ethstream/netutil.h
jim b0be6473b8 Fix warnings
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@8320 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2010-02-08 21:37:57 +00:00

55 lines
1.6 KiB
C

#ifndef NETUTIL_H
#define NETUTIL_H
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#ifdef __WIN32__
# include <winsock2.h>
# include <ws2tcpip.h>
# define socklen_t int
# define in_addr_t uint32_t
# define in_port_t uint16_t
# include <windows.h>
# include <iphlpapi.h>
# define USE_IPHLPAPI 1
#else
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
# include <net/if.h>
# include <sys/ioctl.h>
#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