fake-rfc2553.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
  3. * Copyright (C) 1999 WIDE Project. 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. /*
  30. * Pseudo-implementation of RFC2553 name / address resolution functions
  31. *
  32. * But these functions are not implemented correctly. The minimum subset
  33. * is implemented for ssh use only. For example, this routine assumes
  34. * that ai_family is AF_INET. Don't use it for another purpose.
  35. */
  36. #ifndef _FAKE_RFC2553_H
  37. #define _FAKE_RFC2553_H
  38. #include "includes.h"
  39. #include <sys/types.h>
  40. #if defined(HAVE_NETDB_H)
  41. # include <netdb.h>
  42. #endif
  43. /*
  44. * First, socket and INET6 related definitions
  45. */
  46. #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
  47. # define _SS_MAXSIZE 128 /* Implementation specific max size */
  48. # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
  49. struct sockaddr_storage {
  50. struct sockaddr ss_sa;
  51. char __ss_pad2[_SS_PADSIZE];
  52. };
  53. # define ss_family ss_sa.sa_family
  54. #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
  55. #ifndef IN6_IS_ADDR_LOOPBACK
  56. # define IN6_IS_ADDR_LOOPBACK(a) \
  57. (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
  58. ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
  59. #endif /* !IN6_IS_ADDR_LOOPBACK */
  60. #ifndef HAVE_STRUCT_IN6_ADDR
  61. struct in6_addr {
  62. u_int8_t s6_addr[16];
  63. };
  64. #endif /* !HAVE_STRUCT_IN6_ADDR */
  65. #ifndef HAVE_STRUCT_SOCKADDR_IN6
  66. struct sockaddr_in6 {
  67. unsigned short sin6_family;
  68. u_int16_t sin6_port;
  69. u_int32_t sin6_flowinfo;
  70. struct in6_addr sin6_addr;
  71. u_int32_t sin6_scope_id;
  72. };
  73. #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
  74. #ifndef AF_INET6
  75. /* Define it to something that should never appear */
  76. #define AF_INET6 AF_MAX
  77. #endif
  78. /*
  79. * Next, RFC2553 name / address resolution API
  80. */
  81. #ifndef NI_NUMERICHOST
  82. # define NI_NUMERICHOST (1)
  83. #endif
  84. #ifndef NI_NAMEREQD
  85. # define NI_NAMEREQD (1<<1)
  86. #endif
  87. #ifndef NI_NUMERICSERV
  88. # define NI_NUMERICSERV (1<<2)
  89. #endif
  90. #ifndef AI_PASSIVE
  91. # define AI_PASSIVE (1)
  92. #endif
  93. #ifndef AI_CANONNAME
  94. # define AI_CANONNAME (1<<1)
  95. #endif
  96. #ifndef AI_NUMERICHOST
  97. # define AI_NUMERICHOST (1<<2)
  98. #endif
  99. #ifndef AI_NUMERICSERV
  100. # define AI_NUMERICSERV (1<<3)
  101. #endif
  102. #ifndef NI_MAXSERV
  103. # define NI_MAXSERV 32
  104. #endif /* !NI_MAXSERV */
  105. #ifndef NI_MAXHOST
  106. # define NI_MAXHOST 1025
  107. #endif /* !NI_MAXHOST */
  108. #ifndef EAI_NODATA
  109. # define EAI_NODATA (INT_MAX - 1)
  110. #endif
  111. #ifndef EAI_MEMORY
  112. # define EAI_MEMORY (INT_MAX - 2)
  113. #endif
  114. #ifndef EAI_NONAME
  115. # define EAI_NONAME (INT_MAX - 3)
  116. #endif
  117. #ifndef EAI_SYSTEM
  118. # define EAI_SYSTEM (INT_MAX - 4)
  119. #endif
  120. #ifndef EAI_FAMILY
  121. # define EAI_FAMILY (INT_MAX - 5)
  122. #endif
  123. #ifndef HAVE_STRUCT_ADDRINFO
  124. struct addrinfo {
  125. int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
  126. int ai_family; /* PF_xxx */
  127. int ai_socktype; /* SOCK_xxx */
  128. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  129. size_t ai_addrlen; /* length of ai_addr */
  130. char *ai_canonname; /* canonical name for hostname */
  131. struct sockaddr *ai_addr; /* binary address */
  132. struct addrinfo *ai_next; /* next structure in linked list */
  133. };
  134. #endif /* !HAVE_STRUCT_ADDRINFO */
  135. #ifndef HAVE_GETADDRINFO
  136. #ifdef getaddrinfo
  137. # undef getaddrinfo
  138. #endif
  139. #define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d))
  140. int getaddrinfo(const char *, const char *,
  141. const struct addrinfo *, struct addrinfo **);
  142. #endif /* !HAVE_GETADDRINFO */
  143. #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
  144. #define gai_strerror(a) (_ssh_compat_gai_strerror(a))
  145. char *gai_strerror(int);
  146. #endif /* !HAVE_GAI_STRERROR */
  147. #ifndef HAVE_FREEADDRINFO
  148. #define freeaddrinfo(a) (ssh_freeaddrinfo(a))
  149. void freeaddrinfo(struct addrinfo *);
  150. #endif /* !HAVE_FREEADDRINFO */
  151. #ifndef HAVE_GETNAMEINFO
  152. #define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
  153. int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
  154. char *, size_t, int);
  155. #endif /* !HAVE_GETNAMEINFO */
  156. #endif /* !_FAKE_RFC2553_H */