network.h revision e95baea87aa5d7a10749c39c8ff81a2632ceadf3
#ifndef __NETWORK_H
#define __NETWORK_H
#ifndef WIN32
# include <netdb.h>
#endif
#ifdef HAVE_SOCKS_H
#include <socks.h>
#endif
#ifndef AF_INET6
# ifdef PF_INET6
# else
# define AF_INET6 10
# endif
#endif
struct ip_addr {
unsigned short family;
#ifdef HAVE_IPV6
#else
#endif
};
/* maxmimum string length of IP address */
#ifdef HAVE_IPV6
# define MAX_IP_LEN INET6_ADDRSTRLEN
#else
# define MAX_IP_LEN 20
#endif
/* returns 1 if IPADDRs are the same */
/* Connect to socket with ip address */
/* Connect to named UNIX socket */
int net_connect_unix(const char *path);
/* Disconnect socket */
void net_disconnect(int fd);
/* Try to let the other side close the connection, if it still isn't
disconnected after certain amount of time, close it ourself */
void net_disconnect_later(int fd);
/* Set socket blocking/nonblocking */
/* Set TCP_CORK if supported, ie. don't send out partial frames.
Returns 0 if ok, -1 if failed. */
/* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
include IPv4 depending on the system (Linux yes, BSD no). */
/* Listen for connections on a socket */
/* Listen for connections on an UNIX socket */
int net_listen_unix(const char *path);
/* Accept a connection on a socket. Returns -1 for temporary failure,
-2 for fatal failure */
/* Read data from socket, return number of bytes read,
-1 = error, -2 = disconnected */
/* Transmit data, return number of bytes sent, -1 = error, -2 = disconnected */
/* Get IP addresses for host. ips contains ips_count of IPs, they don't need
to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
/* get error of net_gethostname() */
const char *net_gethosterror(int error);
/* return TRUE if host lookup failed because it didn't exist (ie. not
some error with name server) */
int net_hosterror_notfound(int error);
/* Returns ip_addr as string, or NULL if ip is invalid. */
/* char* -> struct ip_addr translation. */
/* Get socket error */
int net_geterror(int fd);
/* Get name of TCP service */
char *net_getservbyport(unsigned short port);
int is_ipv4_address(const char *addr);
int is_ipv6_address(const char *addr);
#endif