a2netcompat.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * aria2 - The high speed download utility
  3. *
  4. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * In addition, as a special exception, the copyright holders give
  21. * permission to link the code of portions of this program with the
  22. * OpenSSL library under certain conditions as described in each
  23. * individual source file, and distribute linked combinations
  24. * including the two.
  25. * You must obey the GNU General Public License in all respects
  26. * for all of the code used other than OpenSSL. If you modify
  27. * file(s) with this exception, you may extend this exception to your
  28. * version of the file(s), but you are not obligated to do so. If you
  29. * do not wish to do so, delete this exception statement from your
  30. * version. If you delete this exception statement from all source
  31. * files in the program, then also delete it here.
  32. */
  33. /* copyright --> */
  34. #ifndef D_A2NETCOMPAT_H
  35. #define D_A2NETCOMPAT_H
  36. #include "a2io.h"
  37. #ifdef __MINGW32__
  38. # ifndef WINVER
  39. # define WINVER 0x501u
  40. # endif // !WINVER
  41. # ifdef HAVE_WINSOCK2_H
  42. # ifndef FD_SETSIZE
  43. # define FD_SETSIZE 1024
  44. # endif // !FD_SETSIZE
  45. # include <winsock2.h>
  46. # undef ERROR
  47. # endif // HAVE_WINSOCK2_H
  48. # ifdef HAVE_WS2TCPIP_H
  49. # include <ws2tcpip.h>
  50. # endif // HAVE_WS2TCPIP_H
  51. #endif // __MINGW32__
  52. #ifdef __MINGW32__
  53. # define a2_sockopt_t char *
  54. # define HAVE_GETADDRINFO
  55. # undef HAVE_GAI_STRERROR
  56. # undef gai_strerror
  57. #else
  58. # define a2_sockopt_t void *
  59. #endif // __MINGW32__
  60. #ifdef HAVE_NETDB_H
  61. # include <netdb.h>
  62. #endif // HAVE_NETDB_H
  63. #ifdef HAVE_SYS_SOCKET_H
  64. # include <sys/socket.h>
  65. #endif // HAVE_SYS_SOCKET_H
  66. #ifdef HAVE_NETINET_IN_H
  67. # include <netinet/in.h>
  68. #endif // HAVE_NETINET_IN_H
  69. #ifdef HAVE_ARPA_INET_H
  70. # include <arpa/inet.h>
  71. #endif // HAVE_ARPA_INET_H
  72. #ifdef HAVE_NETINET_IN_H
  73. # include <netinet/in.h>
  74. #endif // HAVE_NETINET_IN_H
  75. #ifndef HAVE_INET_ATON
  76. # include "inet_aton.h"
  77. #endif // HAVE_INET_ATON
  78. #ifndef HAVE_GETADDRINFO
  79. # include "getaddrinfo.h"
  80. # define HAVE_GAI_STRERROR
  81. #endif // HAVE_GETADDRINFO
  82. #ifndef HAVE_GAI_STRERROR
  83. # include "gai_strerror.h"
  84. #endif // HAVE_GAI_STRERROR
  85. #ifdef HAVE_WINSOCK2_H
  86. # define sock_t SOCKET
  87. #else
  88. # define sock_t int
  89. #endif
  90. #ifndef AI_ADDRCONFIG
  91. # define AI_ADDRCONFIG 0
  92. #endif // !AI_ADDRCONFIG
  93. #define DEFAULT_AI_FLAGS AI_ADDRCONFIG
  94. #ifdef __MINGW32__
  95. # ifndef SHUT_WR
  96. # define SHUT_WR SD_SEND
  97. # endif // !SHUT_WR
  98. #endif // __MINGW32__
  99. #ifdef __MINGW32__
  100. template<typename T>
  101. class wsaapi_auto_delete {
  102. private:
  103. T obj_;
  104. void (WSAAPI*deleter_)(T);
  105. public:
  106. wsaapi_auto_delete(T obj, void (WSAAPI*deleter)(T)):
  107. obj_(obj), deleter_(deleter) {}
  108. ~wsaapi_auto_delete()
  109. {
  110. deleter_(obj_);
  111. }
  112. };
  113. # define WSAAPI_AUTO_DELETE wsaapi_auto_delete
  114. #else // !__MINGW32__
  115. # define WSAAPI_AUTO_DELETE auto_delete
  116. #endif // !__MINGW32__
  117. union sockaddr_union {
  118. sockaddr sa;
  119. sockaddr_storage storage;
  120. sockaddr_in6 in6;
  121. sockaddr_in in;
  122. };
  123. #endif // D_A2NETCOMPAT_H