/*
 * Copyright (C) 2015 by the University of Southern California
 * $Id: socket_util.h 23727 2015-04-30 16:42:20Z liangzhu $
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU General Public License for more details.                                      
 *
 * You should have received a copy of the GNU General Public License along           
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
 * 
 */

#ifndef SOCKET_UTIL_H
#define SOCKET_UTIL_H

#include <stdint.h>
#include <netinet/in.h>
#include "global_var.h"

#ifdef USE_GNUTLS
#include <gnutls/gnutls.h>
#elseif USE_OPENSSL
#include <openssl/ssl.h>
#endif

struct pseudo_hdr
{
  struct in_addr ip_src;
  struct in_addr ip_dst;
  uint8_t reserved;
  uint8_t protocol;
  uint16_t length;
};

int mk_conn (const char *, int, bool);
int create_raw_socket(int);

uint16_t cksum (uint16_t *, int);
uint16_t udp_tcp_cksum (uint8_t *, uint16_t, struct in_addr, struct in_addr, uint8_t);

bool ipv4_addr(const char *);
bool ipv6_addr(const char *);

void clean_fd(int);

int ip_s2b(const char *, const char *, const struct sockaddr *);
char *ip_b2s(const struct sockaddr *, char *, size_t);

int udp_dns_pkt(int, uint8_t *, int, struct sockaddr*, size_t*);
int pull_dns_pkt(void *, uint8_t *, int, const char *);
#endif //SOCKET_UTIL_H
