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

/ext/socket/addrinfo.h

http://github.com/MacRuby/MacRuby
C Header | 172 lines | 106 code | 20 blank | 46 comment | 0 complexity | 241e525e1aacd4f65b6564e5a2cf140b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1
  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 ADDR_INFO_H
  30. #define ADDR_INFO_H
  31. #ifndef HAVE_GETADDRINFO
  32. /* special compatibility hack */
  33. #undef EAI_ADDRFAMILY
  34. #undef EAI_AGAIN
  35. #undef EAI_BADFLAGS
  36. #undef EAI_FAIL
  37. #undef EAI_FAMILY
  38. #undef EAI_MEMORY
  39. #undef EAI_NODATA
  40. #undef EAI_NONAME
  41. #undef EAI_SERVICE
  42. #undef EAI_SOCKTYPE
  43. #undef EAI_SYSTEM
  44. #undef EAI_BADHINTS
  45. #undef EAI_PROTOCOL
  46. #undef EAI_MAX
  47. #undef AI_PASSIVE
  48. #undef AI_CANONNAME
  49. #undef AI_NUMERICHOST
  50. #undef AI_ALL
  51. #undef AI_ADDRCONFIG
  52. #undef AI_V4MAPPED
  53. #undef AI_DEFAULT
  54. #undef NI_NOFQDN
  55. #undef NI_NUMERICHOST
  56. #undef NI_NAMEREQD
  57. #undef NI_NUMERICSERV
  58. #undef NI_DGRAM
  59. #define addrinfo addrinfo__compat
  60. #define getaddrinfo getaddrinfo__compat
  61. #define getnameinfo getnameinfo__compat
  62. #define freehostent freehostent__compat
  63. #define freeaddrinfo freeaddrinfo__compat
  64. #ifndef __P
  65. # ifdef HAVE_PROTOTYPES
  66. # define __P(args) args
  67. # else
  68. # define __P(args) ()
  69. # endif
  70. #endif
  71. /* special compatibility hack -- end*/
  72. /*
  73. * Error return codes from getaddrinfo()
  74. */
  75. #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
  76. #define EAI_AGAIN 2 /* temporary failure in name resolution */
  77. #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
  78. #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
  79. #define EAI_FAMILY 5 /* ai_family not supported */
  80. #define EAI_MEMORY 6 /* memory allocation failure */
  81. #define EAI_NODATA 7 /* no address associated with hostname */
  82. #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
  83. #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
  84. #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
  85. #define EAI_SYSTEM 11 /* system error returned in errno */
  86. #define EAI_BADHINTS 12
  87. #define EAI_PROTOCOL 13
  88. #define EAI_MAX 14
  89. /*
  90. * Flag values for getaddrinfo()
  91. */
  92. #define AI_PASSIVE 0x00000001 /* get address to use bind() */
  93. #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
  94. #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
  95. /* valid flags for addrinfo */
  96. #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
  97. #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
  98. #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
  99. #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
  100. #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
  101. /* special recommended flags for getipnodebyname */
  102. #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
  103. /*
  104. * Constants for getnameinfo()
  105. */
  106. #ifndef NI_MAXHOST
  107. #define NI_MAXHOST 1025
  108. #define NI_MAXSERV 32
  109. #endif
  110. /*
  111. * Flag values for getnameinfo()
  112. */
  113. #define NI_NOFQDN 0x00000001
  114. #define NI_NUMERICHOST 0x00000002
  115. #define NI_NAMEREQD 0x00000004
  116. #define NI_NUMERICSERV 0x00000008
  117. #define NI_DGRAM 0x00000010
  118. struct addrinfo {
  119. int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
  120. int ai_family; /* PF_xxx */
  121. int ai_socktype; /* SOCK_xxx */
  122. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  123. size_t ai_addrlen; /* length of ai_addr */
  124. char *ai_canonname; /* canonical name for hostname */
  125. struct sockaddr *ai_addr; /* binary address */
  126. struct addrinfo *ai_next; /* next structure in linked list */
  127. };
  128. extern int getaddrinfo __P((
  129. const char *hostname, const char *servname,
  130. const struct addrinfo *hints,
  131. struct addrinfo **res));
  132. extern int getnameinfo __P((
  133. const struct sockaddr *sa,
  134. size_t salen,
  135. char *host,
  136. size_t hostlen,
  137. char *serv,
  138. size_t servlen,
  139. int flags));
  140. extern void freehostent __P((struct hostent *));
  141. extern void freeaddrinfo __P((struct addrinfo *));
  142. #if defined __UCLIBC__
  143. const
  144. #endif
  145. extern char *gai_strerror __P((int));
  146. /* In case there is no definition of offsetof() provided - though any proper
  147. Standard C system should have one. */
  148. #ifndef offsetof
  149. #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
  150. #endif
  151. #endif
  152. #endif