fake-rfc2553.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* Taken for Dropbear from OpenSSH 5.5p1 */
  2. /* $Id: fake-rfc2553.h,v 1.16 2008/07/14 11:37:37 djm Exp $ */
  3. /*
  4. * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
  5. * Copyright (C) 1999 WIDE Project. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the project nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. /*
  32. * Pseudo-implementation of RFC2553 name / address resolution functions
  33. *
  34. * But these functions are not implemented correctly. The minimum subset
  35. * is implemented for ssh use only. For example, this routine assumes
  36. * that ai_family is AF_INET. Don't use it for another purpose.
  37. */
  38. #ifndef DROPBEAR_FAKE_RFC2553_H
  39. #define DROPBEAR_FAKE_RFC2553_H
  40. #include "includes.h"
  41. #include <sys/types.h>
  42. #if defined(HAVE_NETDB_H)
  43. # include <netdb.h>
  44. #endif
  45. /*
  46. * First, socket and INET6 related definitions
  47. */
  48. #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
  49. # define _SS_MAXSIZE 128 /* Implementation specific max size */
  50. # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
  51. struct sockaddr_storage {
  52. struct sockaddr ss_sa;
  53. char __ss_pad2[_SS_PADSIZE];
  54. };
  55. # define ss_family ss_sa.sa_family
  56. #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
  57. #ifndef IN6_IS_ADDR_LOOPBACK
  58. # define IN6_IS_ADDR_LOOPBACK(a) \
  59. (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
  60. ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
  61. #endif /* !IN6_IS_ADDR_LOOPBACK */
  62. #ifndef HAVE_STRUCT_IN6_ADDR
  63. struct in6_addr {
  64. u_int8_t s6_addr[16];
  65. };
  66. #endif /* !HAVE_STRUCT_IN6_ADDR */
  67. #ifndef HAVE_STRUCT_SOCKADDR_IN6
  68. struct sockaddr_in6 {
  69. unsigned short sin6_family;
  70. u_int16_t sin6_port;
  71. u_int32_t sin6_flowinfo;
  72. struct in6_addr sin6_addr;
  73. u_int32_t sin6_scope_id;
  74. };
  75. #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
  76. #ifndef AF_INET6
  77. /* Define it to something that should never appear */
  78. #define AF_INET6 AF_MAX
  79. #endif
  80. /*
  81. * Next, RFC2553 name / address resolution API
  82. */
  83. #ifndef NI_NUMERICHOST
  84. # define NI_NUMERICHOST (1)
  85. #endif
  86. #ifndef NI_NAMEREQD
  87. # define NI_NAMEREQD (1<<1)
  88. #endif
  89. #ifndef NI_NUMERICSERV
  90. # define NI_NUMERICSERV (1<<2)
  91. #endif
  92. #ifndef AI_PASSIVE
  93. # define AI_PASSIVE (1)
  94. #endif
  95. #ifndef AI_CANONNAME
  96. # define AI_CANONNAME (1<<1)
  97. #endif
  98. #ifndef AI_NUMERICHOST
  99. # define AI_NUMERICHOST (1<<2)
  100. #endif
  101. #ifndef NI_MAXSERV
  102. # define NI_MAXSERV 32
  103. #endif /* !NI_MAXSERV */
  104. #ifndef NI_MAXHOST
  105. # define NI_MAXHOST 1025
  106. #endif /* !NI_MAXHOST */
  107. #ifndef EAI_NODATA
  108. # define EAI_NODATA (INT_MAX - 1)
  109. #endif
  110. #ifndef EAI_MEMORY
  111. # define EAI_MEMORY (INT_MAX - 2)
  112. #endif
  113. #ifndef EAI_NONAME
  114. # define EAI_NONAME (INT_MAX - 3)
  115. #endif
  116. #ifndef EAI_SYSTEM
  117. # define EAI_SYSTEM (INT_MAX - 4)
  118. #endif
  119. #ifndef EAI_FAMILY
  120. # define EAI_FAMILY (INT_MAX - 5)
  121. #endif
  122. #ifndef HAVE_STRUCT_ADDRINFO
  123. struct addrinfo {
  124. int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
  125. int ai_family; /* PF_xxx */
  126. int ai_socktype; /* SOCK_xxx */
  127. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  128. size_t ai_addrlen; /* length of ai_addr */
  129. char *ai_canonname; /* canonical name for hostname */
  130. struct sockaddr *ai_addr; /* binary address */
  131. struct addrinfo *ai_next; /* next structure in linked list */
  132. };
  133. #endif /* !HAVE_STRUCT_ADDRINFO */
  134. #ifndef HAVE_GETADDRINFO
  135. #ifdef getaddrinfo
  136. # undef getaddrinfo
  137. #endif
  138. #define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d))
  139. int getaddrinfo(const char *, const char *,
  140. const struct addrinfo *, struct addrinfo **);
  141. #endif /* !HAVE_GETADDRINFO */
  142. #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
  143. #define gai_strerror(a) (_ssh_compat_gai_strerror(a))
  144. char *gai_strerror(int);
  145. #endif /* !HAVE_GAI_STRERROR */
  146. #ifndef HAVE_FREEADDRINFO
  147. #define freeaddrinfo(a) (ssh_freeaddrinfo(a))
  148. void freeaddrinfo(struct addrinfo *);
  149. #endif /* !HAVE_FREEADDRINFO */
  150. #ifndef HAVE_GETNAMEINFO
  151. #define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
  152. int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
  153. char *, size_t, int);
  154. #endif /* !HAVE_GETNAMEINFO */
  155. #endif /* !_FAKE_RFC2553_H */