addrinfo.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. PostgreSQL Database Management System
  3. (formerly known as Postgres, then as Postgres95)
  4. Portions Copyright (c) 1996-2005, The PostgreSQL Global Development Group
  5. Portions Copyright (c) 1994, The Regents of the University of California
  6. Permission to use, copy, modify, and distribute this software and its
  7. documentation for any purpose, without fee, and without a written agreement
  8. is hereby granted, provided that the above copyright notice and this paragraph
  9. and the following two paragraphs appear in all copies.
  10. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11. DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
  12. LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
  13. EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
  14. SUCH DAMAGE.
  15. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  18. ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS
  19. TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. */
  21. /*-------------------------------------------------------------------------
  22. *
  23. * getaddrinfo.h
  24. * Support getaddrinfo() on platforms that don't have it.
  25. *
  26. * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
  27. * whether or not the library routine getaddrinfo() can be found. This
  28. * policy is needed because on some platforms a manually installed libbind.a
  29. * may provide getaddrinfo(), yet the system headers may not provide the
  30. * struct definitions needed to call it. To avoid conflict with the libbind
  31. * definition in such cases, we rename our routines to pg_xxx() via macros.
  32. *
  33. * This code will also work on platforms where struct addrinfo is defined
  34. * in the system headers but no getaddrinfo() can be located.
  35. *
  36. * Copyright (c) 2003-2007, PostgreSQL Global Development Group
  37. *
  38. *-------------------------------------------------------------------------
  39. */
  40. #ifndef ADDRINFO_H
  41. #define ADDRINFO_H
  42. /* Various macros that ought to be in <netdb.h>, but might not be */
  43. #ifndef EAI_FAIL
  44. #define EAI_BADFLAGS (-1)
  45. #define EAI_NONAME (-2)
  46. #define EAI_AGAIN (-3)
  47. #define EAI_FAIL (-4)
  48. #define EAI_FAMILY (-6)
  49. #define EAI_SOCKTYPE (-7)
  50. #define EAI_SERVICE (-8)
  51. #define EAI_MEMORY (-10)
  52. #define EAI_SYSTEM (-11)
  53. #endif /* !EAI_FAIL */
  54. #ifndef AI_PASSIVE
  55. #define AI_PASSIVE 0x0001
  56. #endif
  57. #ifndef AI_NUMERICHOST
  58. /*
  59. * some platforms don't support AI_NUMERICHOST; define as zero if using
  60. * the system version of getaddrinfo...
  61. */
  62. #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
  63. #define AI_NUMERICHOST 0
  64. #else
  65. #define AI_NUMERICHOST 0x0004
  66. #endif
  67. #endif
  68. #ifndef AI_CANONNAME
  69. #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
  70. #define AI_CANONNAME 0
  71. #else
  72. #define AI_CANONNAME 0x0008
  73. #endif
  74. #endif
  75. #ifndef AI_NUMERICSERV
  76. #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
  77. #define AI_NUMERICSERV 0
  78. #else
  79. #define AI_NUMERICSERV 0x0010
  80. #endif
  81. #endif
  82. #ifndef NI_NUMERICHOST
  83. #define NI_NUMERICHOST 1
  84. #endif
  85. #ifndef NI_NUMERICSERV
  86. #define NI_NUMERICSERV 2
  87. #endif
  88. #ifndef NI_NOFQDN
  89. #define NI_NOFQDN 4
  90. #endif
  91. #ifndef NI_NAMEREQD
  92. #define NI_NAMEREQD 8
  93. #endif
  94. #ifndef NI_DGRAM
  95. #define NI_DGRAM 16
  96. #endif
  97. #ifndef NI_MAXHOST
  98. #define NI_MAXHOST 1025
  99. #endif
  100. #ifndef NI_MAXSERV
  101. #define NI_MAXSERV 32
  102. #endif
  103. #ifndef HAVE_STRUCT_ADDRINFO
  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. struct sockaddr *ai_addr;
  112. char *ai_canonname;
  113. struct addrinfo *ai_next;
  114. };
  115. #endif /* !HAVE_STRUCT_ADDRINFO */
  116. #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
  117. struct sockaddr_storage {
  118. unsigned short ss_family;
  119. unsigned long ss_align;
  120. char ss_padding[128 - sizeof (unsigned long)];
  121. };
  122. #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
  123. #ifndef HAVE_GETADDRINFO
  124. /* Rename private copies per comments above */
  125. #ifdef getaddrinfo
  126. #undef getaddrinfo
  127. #endif
  128. #define getaddrinfo pg_getaddrinfo
  129. #ifdef freeaddrinfo
  130. #undef freeaddrinfo
  131. #endif
  132. #define freeaddrinfo pg_freeaddrinfo
  133. #ifdef gai_strerror
  134. #undef gai_strerror
  135. #endif
  136. #define gai_strerror pg_gai_strerror
  137. #ifdef getnameinfo
  138. #undef getnameinfo
  139. #endif
  140. #define getnameinfo pg_getnameinfo
  141. extern int getaddrinfo(const char *node, const char *service,
  142. const struct addrinfo * hints, struct addrinfo ** res);
  143. extern void freeaddrinfo(struct addrinfo * res);
  144. extern const char *gai_strerror(int errcode);
  145. extern int getnameinfo(const struct sockaddr * sa, socklen_t salen,
  146. char *node, size_t nodelen,
  147. char *service, size_t servicelen, int flags);
  148. #endif /* !HAVE_GETADDRINFO */
  149. #endif /* ADDRINFO_H */