PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/include/getaddrinfo.h

http://github.com/postgres/postgres
C Header | 162 lines | 111 code | 19 blank | 32 comment | 1 complexity | 38692627c32c57761665a3c780856174 MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*-------------------------------------------------------------------------
  2. *
  3. * getaddrinfo.h
  4. * Support getaddrinfo() on platforms that don't have it.
  5. *
  6. * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
  7. * whether or not the library routine getaddrinfo() can be found. This
  8. * policy is needed because on some platforms a manually installed libbind.a
  9. * may provide getaddrinfo(), yet the system headers may not provide the
  10. * struct definitions needed to call it. To avoid conflict with the libbind
  11. * definition in such cases, we rename our routines to pg_xxx() via macros.
  12. *
  13. * This code will also work on platforms where struct addrinfo is defined
  14. * in the system headers but no getaddrinfo() can be located.
  15. *
  16. * Copyright (c) 2003-2020, PostgreSQL Global Development Group
  17. *
  18. * src/include/getaddrinfo.h
  19. *
  20. *-------------------------------------------------------------------------
  21. */
  22. #ifndef GETADDRINFO_H
  23. #define GETADDRINFO_H
  24. #include <sys/socket.h>
  25. #include <netdb.h>
  26. /* Various macros that ought to be in <netdb.h>, but might not be */
  27. #ifndef EAI_FAIL
  28. #ifndef WIN32
  29. #define EAI_BADFLAGS (-1)
  30. #define EAI_NONAME (-2)
  31. #define EAI_AGAIN (-3)
  32. #define EAI_FAIL (-4)
  33. #define EAI_FAMILY (-6)
  34. #define EAI_SOCKTYPE (-7)
  35. #define EAI_SERVICE (-8)
  36. #define EAI_MEMORY (-10)
  37. #define EAI_SYSTEM (-11)
  38. #else /* WIN32 */
  39. #ifdef _MSC_VER
  40. #ifndef WSA_NOT_ENOUGH_MEMORY
  41. #define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS)
  42. #endif
  43. #define WSATYPE_NOT_FOUND (WSABASEERR+109)
  44. #endif
  45. #define EAI_AGAIN WSATRY_AGAIN
  46. #define EAI_BADFLAGS WSAEINVAL
  47. #define EAI_FAIL WSANO_RECOVERY
  48. #define EAI_FAMILY WSAEAFNOSUPPORT
  49. #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
  50. #define EAI_NODATA WSANO_DATA
  51. #define EAI_NONAME WSAHOST_NOT_FOUND
  52. #define EAI_SERVICE WSATYPE_NOT_FOUND
  53. #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
  54. #endif /* !WIN32 */
  55. #endif /* !EAI_FAIL */
  56. #ifndef AI_PASSIVE
  57. #define AI_PASSIVE 0x0001
  58. #endif
  59. #ifndef AI_NUMERICHOST
  60. /*
  61. * some platforms don't support AI_NUMERICHOST; define as zero if using
  62. * the system version of getaddrinfo...
  63. */
  64. #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
  65. #define AI_NUMERICHOST 0
  66. #else
  67. #define AI_NUMERICHOST 0x0004
  68. #endif
  69. #endif
  70. #ifndef NI_NUMERICHOST
  71. #define NI_NUMERICHOST 1
  72. #endif
  73. #ifndef NI_NUMERICSERV
  74. #define NI_NUMERICSERV 2
  75. #endif
  76. #ifndef NI_NAMEREQD
  77. #define NI_NAMEREQD 4
  78. #endif
  79. #ifndef NI_MAXHOST
  80. #define NI_MAXHOST 1025
  81. #endif
  82. #ifndef NI_MAXSERV
  83. #define NI_MAXSERV 32
  84. #endif
  85. #ifndef HAVE_STRUCT_ADDRINFO
  86. #ifndef WIN32
  87. struct addrinfo
  88. {
  89. int ai_flags;
  90. int ai_family;
  91. int ai_socktype;
  92. int ai_protocol;
  93. size_t ai_addrlen;
  94. struct sockaddr *ai_addr;
  95. char *ai_canonname;
  96. struct addrinfo *ai_next;
  97. };
  98. #else
  99. /*
  100. * The order of the structure elements on Win32 doesn't match the
  101. * order specified in the standard, but we have to match it for
  102. * IPv6 to work.
  103. */
  104. struct addrinfo
  105. {
  106. int ai_flags;
  107. int ai_family;
  108. int ai_socktype;
  109. int ai_protocol;
  110. size_t ai_addrlen;
  111. char *ai_canonname;
  112. struct sockaddr *ai_addr;
  113. struct addrinfo *ai_next;
  114. };
  115. #endif
  116. #endif /* HAVE_STRUCT_ADDRINFO */
  117. #ifndef HAVE_GETADDRINFO
  118. /* Rename private copies per comments above */
  119. #ifdef getaddrinfo
  120. #undef getaddrinfo
  121. #endif
  122. #define getaddrinfo pg_getaddrinfo
  123. #ifdef freeaddrinfo
  124. #undef freeaddrinfo
  125. #endif
  126. #define freeaddrinfo pg_freeaddrinfo
  127. #ifdef gai_strerror
  128. #undef gai_strerror
  129. #endif
  130. #define gai_strerror pg_gai_strerror
  131. #ifdef getnameinfo
  132. #undef getnameinfo
  133. #endif
  134. #define getnameinfo pg_getnameinfo
  135. extern int getaddrinfo(const char *node, const char *service,
  136. const struct addrinfo *hints, struct addrinfo **res);
  137. extern void freeaddrinfo(struct addrinfo *res);
  138. extern const char *gai_strerror(int errcode);
  139. extern int getnameinfo(const struct sockaddr *sa, int salen,
  140. char *node, int nodelen,
  141. char *service, int servicelen, int flags);
  142. #endif /* HAVE_GETADDRINFO */
  143. #endif /* GETADDRINFO_H */