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.
 
 
 
 

153 lines
5.1 KiB

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