addrinfo.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the project nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef HAVE_GETADDRINFO
  30. /*
  31. * Error return codes from getaddrinfo()
  32. */
  33. #ifdef EAI_ADDRFAMILY
  34. /* If this is defined, there is a conflicting implementation
  35. in the C library, which can't be used for some reason.
  36. Make sure it won't interfere with this emulation. */
  37. #undef EAI_ADDRFAMILY
  38. #undef EAI_AGAIN
  39. #undef EAI_BADFLAGS
  40. #undef EAI_FAIL
  41. #undef EAI_FAMILY
  42. #undef EAI_MEMORY
  43. #undef EAI_NODATA
  44. #undef EAI_NONAME
  45. #undef EAI_SERVICE
  46. #undef EAI_SOCKTYPE
  47. #undef EAI_SYSTEM
  48. #undef EAI_BADHINTS
  49. #undef EAI_PROTOCOL
  50. #undef EAI_MAX
  51. #undef getaddrinfo
  52. #define getaddrinfo fake_getaddrinfo
  53. #endif /* EAI_ADDRFAMILY */
  54. #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
  55. #define EAI_AGAIN 2 /* temporary failure in name resolution */
  56. #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
  57. #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
  58. #define EAI_FAMILY 5 /* ai_family not supported */
  59. #define EAI_MEMORY 6 /* memory allocation failure */
  60. #define EAI_NODATA 7 /* no address associated with hostname */
  61. #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
  62. #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
  63. #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
  64. #define EAI_SYSTEM 11 /* system error returned in errno */
  65. #define EAI_BADHINTS 12
  66. #define EAI_PROTOCOL 13
  67. #define EAI_MAX 14
  68. /*
  69. * Flag values for getaddrinfo()
  70. */
  71. #ifdef AI_PASSIVE
  72. #undef AI_PASSIVE
  73. #undef AI_CANONNAME
  74. #undef AI_NUMERICHOST
  75. #undef AI_MASK
  76. #undef AI_ALL
  77. #undef AI_V4MAPPED_CFG
  78. #undef AI_ADDRCONFIG
  79. #undef AI_V4MAPPED
  80. #undef AI_DEFAULT
  81. #endif /* AI_PASSIVE */
  82. #define AI_PASSIVE 0x00000001 /* get address to use bind() */
  83. #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
  84. #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
  85. /* valid flags for addrinfo */
  86. #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
  87. #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
  88. #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
  89. #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
  90. #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
  91. /* special recommended flags for getipnodebyname */
  92. #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
  93. #endif /* !HAVE_GETADDRINFO */
  94. #ifndef HAVE_GETNAMEINFO
  95. /*
  96. * Constants for getnameinfo()
  97. */
  98. #ifndef NI_MAXHOST
  99. #define NI_MAXHOST 1025
  100. #define NI_MAXSERV 32
  101. #endif /* !NI_MAXHOST */
  102. /*
  103. * Flag values for getnameinfo()
  104. */
  105. #ifndef NI_NOFQDN
  106. #define NI_NOFQDN 0x00000001
  107. #define NI_NUMERICHOST 0x00000002
  108. #define NI_NAMEREQD 0x00000004
  109. #define NI_NUMERICSERV 0x00000008
  110. #define NI_DGRAM 0x00000010
  111. #endif /* !NI_NOFQDN */
  112. #endif /* !HAVE_GETNAMEINFO */
  113. #ifndef HAVE_ADDRINFO
  114. struct addrinfo {
  115. int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
  116. int ai_family; /* PF_xxx */
  117. int ai_socktype; /* SOCK_xxx */
  118. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  119. size_t ai_addrlen; /* length of ai_addr */
  120. char *ai_canonname; /* canonical name for hostname */
  121. struct sockaddr *ai_addr; /* binary address */
  122. struct addrinfo *ai_next; /* next structure in linked list */
  123. };
  124. #endif /* !HAVE_ADDRINFO */
  125. #ifndef HAVE_SOCKADDR_STORAGE
  126. /*
  127. * RFC 2553: protocol-independent placeholder for socket addresses
  128. */
  129. #define _SS_MAXSIZE 128
  130. #define _SS_ALIGNSIZE (sizeof(long long))
  131. #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) * 2)
  132. #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) * 2 - \
  133. _SS_PAD1SIZE - _SS_ALIGNSIZE)
  134. struct sockaddr_storage {
  135. #ifdef HAVE_SOCKADDR_SA_LEN
  136. unsigned char ss_len; /* address length */
  137. unsigned char ss_family; /* address family */
  138. #else
  139. unsigned short ss_family; /* address family */
  140. #endif /* HAVE_SOCKADDR_SA_LEN */
  141. char __ss_pad1[_SS_PAD1SIZE];
  142. long long __ss_align; /* force desired structure storage alignment */
  143. char __ss_pad2[_SS_PAD2SIZE];
  144. };
  145. #endif /* !HAVE_SOCKADDR_STORAGE */
  146. #ifdef __cplusplus
  147. extern "C" {
  148. #endif
  149. #ifdef ENABLE_IPV6
  150. extern void freehostent(struct hostent *);
  151. #endif
  152. #ifdef __cplusplus
  153. }
  154. #endif