socket.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc.
  2. This file is part of GNU Emacs.
  3. GNU Emacs is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. GNU Emacs is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
  13. /* Workable version of <sys/socket.h> based on winsock.h */
  14. #ifndef _SOCKET_H_
  15. #define _SOCKET_H_
  16. /* defeat the multiple include protection */
  17. #ifdef _WINSOCKAPI_
  18. #undef _WINSOCKAPI_
  19. #endif
  20. #ifdef _WINSOCK_H
  21. #undef _WINSOCK_H
  22. #endif
  23. /* avoid confusion with our version of select */
  24. #ifdef select
  25. #undef select
  26. #define MUST_REDEF_SELECT
  27. #endif
  28. /* avoid clashing with our version of FD_SET if already defined */
  29. #ifdef FD_SET
  30. #undef FD_SET
  31. #undef FD_CLR
  32. #undef FD_ISSET
  33. #undef FD_ZERO
  34. #endif
  35. /* avoid duplicate definition of timeval */
  36. #ifdef HAVE_TIMEVAL
  37. #define timeval ws_timeval
  38. #endif
  39. #include <winsock2.h>
  40. #include <ws2tcpip.h>
  41. /* process.c uses uint16_t (from C99) for IPv6, but
  42. apparently it is not defined in some versions of mingw and msvc. */
  43. #ifndef UINT16_C
  44. typedef unsigned short uint16_t;
  45. #endif
  46. /* redefine select to reference our version */
  47. #ifdef MUST_REDEF_SELECT
  48. #define select sys_select
  49. #undef MUST_REDEF_SELECT
  50. #endif
  51. /* revert to our version of FD_SET */
  52. #undef FD_SET
  53. #undef FD_CLR
  54. #undef FD_ISSET
  55. #undef FD_ZERO
  56. /* allow us to provide our own version of fd_set */
  57. #define fd_set ws_fd_set
  58. #include "w32.h"
  59. #ifdef HAVE_TIMEVAL
  60. #undef timeval
  61. #endif
  62. /* shadow functions where we provide our own wrapper */
  63. #define socket sys_socket
  64. #define bind sys_bind
  65. #define connect sys_connect
  66. #define htons sys_htons
  67. #define ntohs sys_ntohs
  68. #define inet_addr sys_inet_addr
  69. #define gethostname sys_gethostname
  70. #define gethostbyname sys_gethostbyname
  71. #define getpeername sys_getpeername
  72. #define getservbyname sys_getservbyname
  73. #define shutdown sys_shutdown
  74. #define setsockopt sys_setsockopt
  75. #define listen sys_listen
  76. #define getsockname sys_getsockname
  77. #define accept sys_accept
  78. #define recvfrom sys_recvfrom
  79. #define sendto sys_sendto
  80. int sys_socket(int af, int type, int protocol);
  81. int sys_bind (int s, const struct sockaddr *addr, int namelen);
  82. int sys_connect (int s, const struct sockaddr *addr, int namelen);
  83. u_short sys_htons (u_short hostshort);
  84. u_short sys_ntohs (u_short netshort);
  85. unsigned long sys_inet_addr (const char * cp);
  86. int sys_gethostname (char * name, int namelen);
  87. struct hostent * sys_gethostbyname (const char * name);
  88. struct servent * sys_getservbyname (const char * name, const char * proto);
  89. int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
  90. int sys_shutdown (int socket, int how);
  91. int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
  92. int sys_listen (int s, int backlog);
  93. int sys_getsockname (int s, struct sockaddr * name, int * namelen);
  94. int sys_accept (int s, struct sockaddr *addr, int *addrlen);
  95. int sys_recvfrom (int s, char *buf, int len, int flags,
  96. struct sockaddr *from, int * fromlen);
  97. int sys_sendto (int s, const char * buf, int len, int flags,
  98. const struct sockaddr *to, int tolen);
  99. /* In addition to wrappers for the winsock functions, we also provide
  100. an fcntl function, for setting sockets to non-blocking mode. */
  101. int fcntl (int s, int cmd, int options);
  102. #define F_SETFL 4
  103. #define O_NDELAY 04000
  104. /* we are providing a real h_errno variable */
  105. #undef h_errno
  106. extern int h_errno;
  107. /* map winsock error codes to standard names */
  108. #define EWOULDBLOCK WSAEWOULDBLOCK
  109. #define EINPROGRESS WSAEINPROGRESS
  110. #define EALREADY WSAEALREADY
  111. #define ENOTSOCK WSAENOTSOCK
  112. #define EDESTADDRREQ WSAEDESTADDRREQ
  113. #define EMSGSIZE WSAEMSGSIZE
  114. #define EPROTOTYPE WSAEPROTOTYPE
  115. #define ENOPROTOOPT WSAENOPROTOOPT
  116. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  117. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  118. #define EOPNOTSUPP WSAEOPNOTSUPP
  119. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  120. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  121. #define EADDRINUSE WSAEADDRINUSE
  122. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  123. #define ENETDOWN WSAENETDOWN
  124. #define ENETUNREACH WSAENETUNREACH
  125. #define ENETRESET WSAENETRESET
  126. #define ECONNABORTED WSAECONNABORTED
  127. #define ECONNRESET WSAECONNRESET
  128. #define ENOBUFS WSAENOBUFS
  129. #define EISCONN WSAEISCONN
  130. #define ENOTCONN WSAENOTCONN
  131. #define ESHUTDOWN WSAESHUTDOWN
  132. #define ETOOMANYREFS WSAETOOMANYREFS
  133. #define ETIMEDOUT WSAETIMEDOUT
  134. #define ECONNREFUSED WSAECONNREFUSED
  135. #define ELOOP WSAELOOP
  136. /* #define ENAMETOOLONG WSAENAMETOOLONG */
  137. #define EHOSTDOWN WSAEHOSTDOWN
  138. #define EHOSTUNREACH WSAEHOSTUNREACH
  139. /* #define ENOTEMPTY WSAENOTEMPTY */
  140. #define EPROCLIM WSAEPROCLIM
  141. #define EUSERS WSAEUSERS
  142. #define EDQUOT WSAEDQUOT
  143. #define ESTALE WSAESTALE
  144. #define EREMOTE WSAEREMOTE
  145. #endif /* _SOCKET_H_ */
  146. /* end of socket.h */