socket_.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Provide a sys/socket header file for systems lacking it (read: MinGW).
  2. Copyright (C) 2005, 2006 Free Software Foundation, Inc.
  3. Written by Simon Josefsson.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. #ifndef _SYS_SOCKET_H
  16. #define _SYS_SOCKET_H
  17. /* This file is supposed to be used on platforms that lack
  18. sys/socket.h. It is intended to provide definitions and prototypes
  19. needed by an application.
  20. Currently only MinGW is supported. See the gnulib manual regarding
  21. Windows sockets. MinGW has the header files winsock2.h and
  22. ws2tcpip.h that declare the sys/socket.h definitions we need. Note
  23. that you can influence which definitions you get by setting the
  24. WINVER symbol before including these two files. For example,
  25. getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
  26. symbol is set indiriectly through WINVER). You can set this by
  27. adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your
  28. code may not run on older Windows releases then. My Windows 2000
  29. box was not able to run the code, for example. The situation is
  30. slightly confusing because:
  31. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
  32. suggests that getaddrinfo should be available on all Windows
  33. releases. */
  34. #if HAVE_WINSOCK2_H
  35. # include <winsock2.h>
  36. #endif
  37. #if HAVE_WS2TCPIP_H
  38. # include <ws2tcpip.h>
  39. #endif
  40. /* For shutdown(). */
  41. #if !defined SHUT_RD && defined SD_RECEIVE
  42. # define SHUT_RD SD_RECEIVE
  43. #endif
  44. #if !defined SHUT_WR && defined SD_SEND
  45. # define SHUT_WR SD_SEND
  46. #endif
  47. #if !defined SHUT_RDWR && defined SD_BOTH
  48. # define SHUT_RDWR SD_BOTH
  49. #endif
  50. #if defined _WIN32 || defined __WIN32__
  51. # define ENOTSOCK WSAENOTSOCK
  52. # define EADDRINUSE WSAEADDRINUSE
  53. # define ENETRESET WSAENETRESET
  54. # define ECONNABORTED WSAECONNABORTED
  55. # define ECONNRESET WSAECONNRESET
  56. # define ENOTCONN WSAENOTCONN
  57. # define ESHUTDOWN WSAESHUTDOWN
  58. #endif
  59. #endif /* _SYS_SOCKET_H */