netdb.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Redistribution and use in source and binary forms, with or without modification,
  3. * are permitted provided that the following conditions are met:
  4. *
  5. * 1. Redistributions of source code must retain the above copyright notice,
  6. * this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation
  9. * and/or other materials provided with the distribution.
  10. * 3. The name of the author may not be used to endorse or promote products
  11. * derived from this software without specific prior written permission.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  16. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  18. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  21. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  22. * OF SUCH DAMAGE.
  23. *
  24. * This file is part of the lwIP TCP/IP stack.
  25. *
  26. * Author: Simon Goldschmidt
  27. *
  28. */
  29. #ifndef __LWIP_NETDB_H__
  30. #define __LWIP_NETDB_H__
  31. #include "lwip/opt.h"
  32. #if LWIP_DNS && LWIP_SOCKET
  33. #include <stddef.h> /* for size_t */
  34. #include "lwip/inet.h"
  35. #include "lwip/sockets.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* some rarely used options */
  40. #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
  41. #define LWIP_DNS_API_DECLARE_H_ERRNO 1
  42. #endif
  43. #ifndef LWIP_DNS_API_DEFINE_ERRORS
  44. #define LWIP_DNS_API_DEFINE_ERRORS 1
  45. #endif
  46. #ifndef LWIP_DNS_API_DECLARE_STRUCTS
  47. #define LWIP_DNS_API_DECLARE_STRUCTS 1
  48. #endif
  49. #if LWIP_DNS_API_DEFINE_ERRORS
  50. /** Errors used by the DNS API functions, h_errno can be one of them */
  51. #define EAI_NONAME 200
  52. #define EAI_SERVICE 201
  53. #define EAI_FAIL 202
  54. #define EAI_MEMORY 203
  55. #define HOST_NOT_FOUND 210
  56. #define NO_DATA 211
  57. #define NO_RECOVERY 212
  58. #define TRY_AGAIN 213
  59. #endif /* LWIP_DNS_API_DEFINE_ERRORS */
  60. #if LWIP_DNS_API_DECLARE_STRUCTS
  61. struct hostent {
  62. char *h_name; /* Official name of the host. */
  63. char **h_aliases; /* A pointer to an array of pointers to alternative host names,
  64. terminated by a null pointer. */
  65. int h_addrtype; /* Address type. */
  66. int h_length; /* The length, in bytes, of the address. */
  67. char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
  68. network byte order) for the host, terminated by a null pointer. */
  69. #define h_addr h_addr_list[0] /* for backward compatibility */
  70. };
  71. struct addrinfo {
  72. int ai_flags; /* Input flags. */
  73. int ai_family; /* Address family of socket. */
  74. int ai_socktype; /* Socket type. */
  75. int ai_protocol; /* Protocol of socket. */
  76. socklen_t ai_addrlen; /* Length of socket address. */
  77. struct sockaddr *ai_addr; /* Socket address of socket. */
  78. char *ai_canonname; /* Canonical name of service location. */
  79. struct addrinfo *ai_next; /* Pointer to next in list. */
  80. };
  81. #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
  82. #if LWIP_DNS_API_DECLARE_H_ERRNO
  83. /* application accessable error code set by the DNS API functions */
  84. extern int h_errno;
  85. #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
  86. struct hostent *lwip_gethostbyname(const char *name);
  87. int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
  88. size_t buflen, struct hostent **result, int *h_errnop);
  89. void lwip_freeaddrinfo(struct addrinfo *ai);
  90. int lwip_getaddrinfo(const char *nodename,
  91. const char *servname,
  92. const struct addrinfo *hints,
  93. struct addrinfo **res);
  94. #if LWIP_COMPAT_SOCKETS
  95. #define gethostbyname(name) lwip_gethostbyname(name)
  96. #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
  97. lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
  98. #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo)
  99. #define getaddrinfo(nodname, servname, hints, res) \
  100. lwip_getaddrinfo(nodname, servname, hints, res)
  101. #endif /* LWIP_COMPAT_SOCKETS */
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* LWIP_DNS && LWIP_SOCKET */
  106. #endif /* __LWIP_NETDB_H__ */