You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netutil.h 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef NETUTIL_H
  2. #define NETUTIL_H
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5. #include <fcntl.h>
  6. #ifdef __WIN32__
  7. # include <winsock2.h>
  8. # include <ws2tcpip.h>
  9. # define socklen_t int
  10. # define in_addr_t uint32_t
  11. # define in_port_t uint16_t
  12. # include <windows.h>
  13. # include <iphlpapi.h>
  14. # define USE_IPHLPAPI 1
  15. #else
  16. # include <sys/socket.h>
  17. # include <netinet/in.h>
  18. # include <arpa/inet.h>
  19. # include <netdb.h>
  20. # include <net/if.h>
  21. # include <sys/ioctl.h>
  22. #ifndef _SIZEOF_ADDR_IFREQ
  23. #define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
  24. #endif
  25. #endif
  26. /* Initialize networking */
  27. void net_init(void);
  28. /* Set socket blocking/nonblocking */
  29. int soblock(int socket, int blocking);
  30. /* Like send(2), recv(2), connect(2), but with timeouts.
  31. Socket must be O_NONBLOCK. */
  32. int connect_timeout(int s, const struct sockaddr *serv_addr,
  33. socklen_t addrlen, struct timeval *timeout);
  34. ssize_t send_timeout(int s, const void *buf, size_t len, int flags,
  35. struct timeval *timeout);
  36. ssize_t recv_timeout(int s, void *buf, size_t len, int flags,
  37. struct timeval *timeout);
  38. ssize_t recvfrom_timeout(int s, void *buf, size_t len, int flags,
  39. struct sockaddr *address, socklen_t * address_len,
  40. struct timeval *timeout);
  41. /* Like send_timeout and recv_timeout, but they retry (with the same timeout)
  42. in case of partial transfers, in order to try to transfer all data. */
  43. ssize_t send_all_timeout(int s, const void *buf, size_t len, int flags,
  44. struct timeval *timeout);
  45. ssize_t recv_all_timeout(int s, void *buf, size_t len, int flags,
  46. struct timeval *timeout);
  47. #endif