STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
netdb.h
Go to the documentation of this file.
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_HDR_NETDB_H
30 #define LWIP_HDR_NETDB_H
31 
32 #include "lwip/opt.h"
33 
34 #if LWIP_DNS && LWIP_SOCKET
35 
36 #include <stddef.h> /* for size_t */
37 
38 #include "lwip/inet.h"
39 #include "lwip/sockets.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /* some rarely used options */
46 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
47 #define LWIP_DNS_API_DECLARE_H_ERRNO 1
48 #endif
49 
50 #ifndef LWIP_DNS_API_DEFINE_ERRORS
51 #define LWIP_DNS_API_DEFINE_ERRORS 1
52 #endif
53 
54 #ifndef LWIP_DNS_API_DEFINE_FLAGS
55 #define LWIP_DNS_API_DEFINE_FLAGS 1
56 #endif
57 
58 #ifndef LWIP_DNS_API_DECLARE_STRUCTS
59 #define LWIP_DNS_API_DECLARE_STRUCTS 1
60 #endif
61 
62 #if LWIP_DNS_API_DEFINE_ERRORS
63 
64 #define EAI_NONAME 200
65 #define EAI_SERVICE 201
66 #define EAI_FAIL 202
67 #define EAI_MEMORY 203
68 #define EAI_FAMILY 204
69 
70 #define HOST_NOT_FOUND 210
71 #define NO_DATA 211
72 #define NO_RECOVERY 212
73 #define TRY_AGAIN 213
74 #endif /* LWIP_DNS_API_DEFINE_ERRORS */
75 
76 #if LWIP_DNS_API_DEFINE_FLAGS
77 /* input flags for struct addrinfo */
78 #define AI_PASSIVE 0x01
79 #define AI_CANONNAME 0x02
80 #define AI_NUMERICHOST 0x04
81 #define AI_NUMERICSERV 0x08
82 #define AI_V4MAPPED 0x10
83 #define AI_ALL 0x20
84 #define AI_ADDRCONFIG 0x40
85 #endif /* LWIP_DNS_API_DEFINE_FLAGS */
86 
87 #if LWIP_DNS_API_DECLARE_STRUCTS
88 struct hostent {
89  char *h_name; /* Official name of the host. */
90  char **h_aliases; /* A pointer to an array of pointers to alternative host names,
91  terminated by a null pointer. */
92  int h_addrtype; /* Address type. */
93  int h_length; /* The length, in bytes, of the address. */
94  char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
95  network byte order) for the host, terminated by a null pointer. */
96 #define h_addr h_addr_list[0] /* for backward compatibility */
97 };
98 
99 struct addrinfo {
100  int ai_flags; /* Input flags. */
101  int ai_family; /* Address family of socket. */
102  int ai_socktype; /* Socket type. */
103  int ai_protocol; /* Protocol of socket. */
104  socklen_t ai_addrlen; /* Length of socket address. */
105  struct sockaddr *ai_addr; /* Socket address of socket. */
106  char *ai_canonname; /* Canonical name of service location. */
107  struct addrinfo *ai_next; /* Pointer to next in list. */
108 };
109 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
110 
111 #define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
112 
113 #if LWIP_DNS_API_DECLARE_H_ERRNO
114 /* application accessible error code set by the DNS API functions */
115 extern int h_errno;
116 #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
117 
118 struct hostent *lwip_gethostbyname(const char *name);
119 int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
120  size_t buflen, struct hostent **result, int *h_errnop);
121 void lwip_freeaddrinfo(struct addrinfo *ai);
122 int lwip_getaddrinfo(const char *nodename,
123  const char *servname,
124  const struct addrinfo *hints,
125  struct addrinfo **res);
126 
127 #if LWIP_COMPAT_SOCKETS
128 #define gethostbyname(name) lwip_gethostbyname(name)
129 #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
130  lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
131 #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo)
132 #define getaddrinfo(nodname, servname, hints, res) \
133  lwip_getaddrinfo(nodname, servname, hints, res)
134 #endif /* LWIP_COMPAT_SOCKETS */
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* LWIP_DNS && LWIP_SOCKET */
141 
142 #endif /* LWIP_HDR_NETDB_H */
143