net.h revision 7375e38258226d559fb66141cb77c3f272ed7e70
#ifndef NET_H
#define NET_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;
union {
#ifdef HAVE_IPV6
#endif
} u;
};
struct net_unix_cred {
};
/* maxmimum string length of IP address */
#ifdef HAVE_IPV6
# define MAX_IP_LEN INET6_ADDRSTRLEN
#else
# define MAX_IP_LEN 20
#endif
#ifndef HAVE_IPV6
# define EAI_NONAME NO_ADDRESS
# define EAI_FAIL NO_RECOVERY
#endif
enum net_listen_flags {
/* Try to use SO_REUSEPORT if available. If it's not, this flag is
cleared on return. */
NET_LISTEN_FLAG_REUSEPORT = 0x01
};
/* Returns TRUE if IPs are the same */
/* Returns 0 if IPs are the same, -1 or 1 otherwise. */
/* Connect to TCP socket with ip address. The socket and connect() is
non-blocking. */
/* Like net_connect_ip(), but do a blocking connect(). */
/* Like net_connect_ip(), but open a UDP socket. */
/* Returns 0 if we can bind() as given IP, -1 if not. */
/* Connect to named UNIX socket */
int net_connect_unix(const char *path);
/* Try to connect to UNIX socket for give number of seconds when connect()
returns EAGAIN or ECONNREFUSED. */
/* Disconnect socket */
void net_disconnect(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 */
/* Like net_listen_unix(), but if socket already exists, try to connect to it.
If it fails with ECONNREFUSED, unlink the socket and try creating it
again. */
/* Accept a connection on a socket. Returns -1 if the connection got closed,
-2 for other failures. For UNIX sockets addr_r->family=port=0. */
/* 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() */
unsigned int *ips_count);
/* Return host for the IP address. Returns 0 = ok, others = error code for
net_gethosterror(). */
/* get error of net_gethostname() */
/* return TRUE if host lookup failed because it didn't exist (ie. not
some error with name server) */
/* Get UNIX socket name. */
/* Get UNIX socket peer process's credentials. The pid may be (pid_t)-1 if
unavailable. */
/* Returns ip_addr as string, or "" if ip isn't valid IPv4 or IPv6 address. */
/* char* -> struct ip_addr translation. */
/* char* -> net_port_t translation */
/* char* -> net_port_t translation (allows port zero) */
/* Convert IPv6 mapped IPv4 address to an actual IPv4 address. Returns 0 if
successful, -1 if the source address isn't IPv6 mapped IPv4 address. */
/* Get socket error */
int net_geterror(int fd);
/* Get name of TCP service */
unsigned int *bits_r);
in "ip" parameter are converted to plain IPv4 addresses before matching.
No conversion is done to net_ip though, so using IPv4-mapped IPv6 addresses
there will always fail. Invalid IPs (family=0) never match anything. */
#endif