a2netcompat.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef __CYGWIN__
  38. # ifdef HAVE_WINSOCK2_H
  39. # ifndef _WIN32_WINNT
  40. # define _WIN32_WINNT 0x501
  41. # endif // _WIN32_WINNT
  42. # include <winsock2.h>
  43. # undef ERROR
  44. # endif // HAVE_WINSOCK2_H
  45. # ifdef HAVE_WS2TCPIP_H
  46. # include <ws2tcpip.h>
  47. # endif // HAVE_WS2TCPIP_H
  48. #endif // !__CYGWIN__
  49. #ifdef __MINGW32__
  50. # define a2_sockopt_t char *
  51. # define HAVE_GETADDRINFO
  52. # undef HAVE_GAI_STRERROR
  53. # undef gai_strerror
  54. #else
  55. # define a2_sockopt_t void *
  56. #endif // __MINGW32__
  57. #ifdef HAVE_NETDB_H
  58. # include <netdb.h>
  59. #endif // HAVE_NETDB_H
  60. #ifdef HAVE_SYS_SOCKET_H
  61. # include <sys/socket.h>
  62. #endif // HAVE_SYS_SOCKET_H
  63. #ifdef HAVE_NETINET_IN_H
  64. # include <netinet/in.h>
  65. #endif // HAVE_NETINET_IN_H
  66. #ifdef HAVE_ARPA_INET_H
  67. # include <arpa/inet.h>
  68. #endif // HAVE_ARPA_INET_H
  69. #ifdef HAVE_NETINET_IN_H
  70. # include <netinet/in.h>
  71. #endif // HAVE_NETINET_IN_H
  72. #ifndef HAVE_INET_ATON
  73. # include "inet_aton.h"
  74. #endif // HAVE_INET_ATON
  75. #ifndef HAVE_GETADDRINFO
  76. # include "getaddrinfo.h"
  77. # define HAVE_GAI_STRERROR
  78. #endif // HAVE_GETADDRINFO
  79. #ifndef HAVE_GAI_STRERROR
  80. # include "gai_strerror.h"
  81. #endif // HAVE_GAI_STRERROR
  82. #ifdef HAVE_WINSOCK2_H
  83. # define sock_t SOCKET
  84. #else
  85. # define sock_t int
  86. #endif
  87. #ifdef AI_ADDRCONFIG
  88. # define DEFAULT_AI_FLAGS AI_ADDRCONFIG
  89. #else // !AI_ADDRCONFIG
  90. # define DEFAULT_AI_FLAGS 0
  91. #endif // !AI_ADDRCONFIG
  92. #ifdef __MINGW32__
  93. template<typename T>
  94. class wsaapi_auto_delete {
  95. private:
  96. T _obj;
  97. void (WSAAPI*_deleter)(T);
  98. public:
  99. wsaapi_auto_delete(T obj, void (WSAAPI*deleter)(T)):
  100. _obj(obj), _deleter(deleter) {}
  101. ~wsaapi_auto_delete()
  102. {
  103. _deleter(_obj);
  104. }
  105. };
  106. # define WSAAPI_AUTO_DELETE wsaapi_auto_delete
  107. #else // !__MINGW32__
  108. # define WSAAPI_AUTO_DELETE auto_delete
  109. #endif // !__MINGW32__
  110. #endif // _D_A2NETCOMPAT_H_