#ifndef NETUTIL_H #define NETUTIL_H #include #include #include #ifdef __WIN32__ # include # include # define socklen_t unsigned int # define in_addr_t uint32_t # define in_port_t uint16_t # include # include # define USE_IPHLPAPI 1 #else # include # include # include # include # include # include #ifndef _SIZEOF_ADDR_IFREQ #define _SIZEOF_ADDR_IFREQ(x) sizeof(x) #endif #endif /* Initialize networking */ void net_init(void); /* Set socket blocking/nonblocking */ int soblock(int socket, int blocking); /* Like send(2), recv(2), connect(2), but with timeouts. Socket must be O_NONBLOCK. */ int connect_timeout(int s, const struct sockaddr *serv_addr, socklen_t addrlen, struct timeval *timeout); ssize_t send_timeout(int s, const void *buf, size_t len, int flags, struct timeval *timeout); ssize_t recv_timeout(int s, void *buf, size_t len, int flags, struct timeval *timeout); ssize_t recvfrom_timeout(int s, void *buf, size_t len, int flags, struct sockaddr *address, socklen_t * address_len, struct timeval *timeout); /* Like send_timeout and recv_timeout, but they retry (with the same timeout) in case of partial transfers, in order to try to transfer all data. */ ssize_t send_all_timeout(int s, const void *buf, size_t len, int flags, struct timeval *timeout); ssize_t recv_all_timeout(int s, void *buf, size_t len, int flags, struct timeval *timeout); #endif