Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.

179 lines
6.3 KiB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
13 years ago
21 years ago
21 years ago
21 years ago
18 years ago
21 years ago
21 years ago
  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef SOCKET_H
  3. #define SOCKET_H
  4. #include <sys/types.h>
  5. #include <libowfat/compiler.h>
  6. #include <libowfat/uint16.h>
  7. #include <libowfat/uint32.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. int socket_tcp4(void);
  12. int socket_tcp4b(void);
  13. int socket_udp4(void);
  14. int socket_udp4b(void);
  15. int socket_tcp6(void);
  16. int socket_tcp6b(void);
  17. int socket_udp6(void);
  18. int socket_udp6b(void);
  19. int socket_sctp4(void);
  20. int socket_sctp4b(void);
  21. int socket_sctp6(void);
  22. int socket_sctp6b(void);
  23. #define socket_tcp() socket_tcp4()
  24. #define socket_udp() socket_udp4()
  25. int socket_connect4(int s,const char ip[4],uint16 port);
  26. int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id);
  27. int socket_connected(int s);
  28. int socket_bind4(int s,const char ip[4],uint16 port);
  29. int socket_bind4_reuse(int s,const char ip[4],uint16 port);
  30. int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id);
  31. int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id);
  32. int socket_listen(int s,unsigned int backlog);
  33. int socket_accept4(int s,char ip[4],uint16* port);
  34. int socket_accept6(int s,char ip[16],uint16* port,uint32* scope_id);
  35. int socket_accept4_makenonblocking(int s,char ip[4],uint16* port);
  36. int socket_accept6_makenonblocking(int s,char ip[16],uint16* port,uint32* scope_id);
  37. int socket_accept4_setcloseonexec(int s,char ip[4],uint16* port);
  38. int socket_accept6_setcloseonexec(int s,char ip[16],uint16* port,uint32* scope_id);
  39. int socket_accept4_makenonblocking_setcloseonexec(int s,char ip[4],uint16* port);
  40. int socket_accept6_makenonblocking_setcloseonexec(int s,char ip[16],uint16* port,uint32* scope_id);
  41. /* These are internal wrappers around accept4, not meant for external use.
  42. * flags can be SOCKET_NONBLOCK or SOCKET_CLOEXEC or both */
  43. enum {
  44. SOCKET_NONBLOCK=1,
  45. SOCKET_CLOEXEC=2,
  46. };
  47. int socket_accept4_flags(int s,char ip[4],uint16* port, int flags);
  48. int socket_accept6_flags(int s,char ip[16],uint16* port,uint32* scope_id, int flags);
  49. att_writen(2,3) att_nonnull(2)
  50. ssize_t socket_recv4(int s,char* buf,size_t len,char ip[4],uint16* port);
  51. att_writen(2,3) att_nonnull(2)
  52. ssize_t socket_recv6(int s,char* buf,size_t len,char ip[16],uint16* port,uint32* scope_id);
  53. att_readn(2,3) att_nonnull(2)
  54. ssize_t socket_send4(int s,const char* buf,size_t len,const char ip[4],uint16 port);
  55. att_readn(2,3) att_nonnull(2)
  56. ssize_t socket_send4_flag(int s,const char* buf,size_t len,const char ip[4],uint16 port,int flags);
  57. att_readn(2,3) att_nonnull(2)
  58. ssize_t socket_send6(int s,const char* buf,size_t len,const char ip[16],uint16 port,uint32 scope_id);
  59. att_readn(2,3) att_nonnull(2)
  60. ssize_t socket_send6_flag(int s,const char* buf,size_t len,const char ip[16],uint16 port,uint32 scope_id,int flags);
  61. int socket_local4(int s,char ip[4],uint16* port);
  62. int socket_local6(int s,char ip[16],uint16* port,uint32* scope_id);
  63. int socket_remote4(int s,char ip[4],uint16* port);
  64. int socket_remote6(int s,char ip[16],uint16* port,uint32* scope_id);
  65. /* enable sending udp packets to the broadcast address */
  66. int socket_broadcast(int s);
  67. /* join a multicast group on the given interface */
  68. int socket_mcjoin4(int s,const char groupip[4],const char _interface[4]);
  69. int socket_mcjoin6(int s,const char groupip[16],int _interface);
  70. /* leave a multicast group on the given interface */
  71. int socket_mcleave4(int s,const char groupip[4]);
  72. int socket_mcleave6(int s,const char groupip[16]);
  73. /* set multicast TTL/hop count for outgoing packets */
  74. int socket_mcttl4(int s,char hops);
  75. int socket_mchopcount6(int s,char hops);
  76. /* enable multicast loopback, pass 1 for enable, 0 for disable */
  77. int socket_mcloop4(int s,char loop);
  78. int socket_mcloop6(int s,char loop);
  79. /* Please note that these are platform specific. Do not expect them to
  80. * work. You might still get an accept() signalled even though there is
  81. * no data available. So far, DATAIN is supported on FreeBSD and Linux,
  82. * and HTTPIN is supported on FreeBSD. */
  83. enum defermode {
  84. DATAIN, /* only signal accept() if there is data coming in */
  85. HTTPIN, /* only signal accept() if a HTTP header has come in */
  86. };
  87. void socket_deferaccept(int s,enum defermode mode);
  88. void socket_tryreservein(int s,int size);
  89. const char* socket_getifname(uint32 _interface);
  90. uint32 socket_getifidx(const char* ifname);
  91. extern int noipv6;
  92. /* if HAVE_SOCKET_FASTOPEN is #defined, your version of libowfat
  93. * has socket_fastopen, socket_fastopen_connect4,
  94. * socket_fastopen_connect6 and socket_quickack */
  95. #define HAVE_SOCKET_FASTOPEN
  96. /* Turn on server-side TCP fast open support (0 success, -1 error) */
  97. int socket_fastopen(int s);
  98. /* Turn quick ack mode on or off for the socket s. */
  99. int socket_quickack(int s,int value);
  100. /* For client-side TCP fast open, connect and sending the first data is
  101. * just one step, so we need an API to do it in one step */
  102. att_readn(4,5) att_nonnull(4)
  103. ssize_t socket_fastopen_connect4(int s,const char ip[4],uint16 port,const char* buf,size_t len);
  104. att_readn(5,6) att_nonnull(5)
  105. ssize_t socket_fastopen_connect6(int s,const char ip[16],uint16 port,uint32 scope_id,const char* buf,size_t len);
  106. #ifdef __MINGW32__
  107. #include <winsock2.h>
  108. #include <ws2tcpip.h>
  109. #ifndef EWOULDBLOCK
  110. #define EWOULDBLOCK WSAEWOULDBLOCK
  111. #define EINPROGRESS WSAEINPROGRESS
  112. #define EALREADY WSAEALREADY
  113. #define ENOTSOCK WSAENOTSOCK
  114. #define EDESTADDRREQ WSAEDESTADDRREQ
  115. #define EMSGSIZE WSAEMSGSIZE
  116. #define EPROTOTYPE WSAEPROTOTYPE
  117. #define ENOPROTOOPT WSAENOPROTOOPT
  118. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  119. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  120. #define EOPNOTSUPP WSAEOPNOTSUPP
  121. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  122. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  123. #define EADDRINUSE WSAEADDRINUSE
  124. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  125. #define ENETDOWN WSAENETDOWN
  126. #define ENETUNREACH WSAENETUNREACH
  127. #define ENETRESET WSAENETRESET
  128. #define ECONNABORTED WSAECONNABORTED
  129. #define ECONNRESET WSAECONNRESET
  130. #define ENOBUFS WSAENOBUFS
  131. #define EISCONN WSAEISCONN
  132. #define ENOTCONN WSAENOTCONN
  133. #define ESHUTDOWN WSAESHUTDOWN
  134. #define ETOOMANYREFS WSAETOOMANYREFS
  135. #define ETIMEDOUT WSAETIMEDOUT
  136. #define ECONNREFUSED WSAECONNREFUSED
  137. #define ELOOP WSAELOOP
  138. #define EHOSTDOWN WSAEHOSTDOWN
  139. #define EHOSTUNREACH WSAEHOSTUNREACH
  140. #define EPROCLIM WSAEPROCLIM
  141. #define EUSERS WSAEUSERS
  142. #define EDQUOT WSAEDQUOT
  143. #define ESTALE WSAESTALE
  144. #define EREMOTE WSAEREMOTE
  145. #define EDISCON WSAEDISCON
  146. #endif
  147. #endif
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif