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