PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/include/netdb.h

https://bitbucket.org/benchmark-electronics/nuttx
C Header | 325 lines | 134 code | 41 blank | 150 comment | 0 complexity | e8e5f5ed86941da27fbf8776d6f981b6 MD5 | raw file
Possible License(s): 0BSD
  1. /****************************************************************************
  2. * include/netdb.h
  3. *
  4. * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * 3. Neither the name NuttX nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ****************************************************************************/
  37. #ifndef __INCLUDE_NETDB_H
  38. #define __INCLUDE_NETDB_H
  39. /****************************************************************************
  40. * Included Files
  41. ****************************************************************************/
  42. #include <nuttx/config.h>
  43. #include <nuttx/compiler.h>
  44. /* Inclusion of the <netdb.h> header may also make visible all symbols from
  45. * <netinet/in.h>, <sys/socket.h>, and <inttypes.h>.
  46. */
  47. #include <inttypes.h>
  48. #include <netinet/in.h>
  49. #include <sys/socket.h>
  50. /****************************************************************************
  51. * Pre-processor Definitions
  52. ****************************************************************************/
  53. /* The <netdb.h> header shall define the IPPORT_RESERVED macro with the
  54. * value of the highest reserved Internet port number.
  55. */
  56. #define IPPORT_RESERVED 0xffff /* No reserved port numbers */
  57. /* The <netdb.h> header shall define the following macros that evaluate to
  58. * bitwise-distinct integer constants for use in the flags field of the
  59. * addrinfo structure:
  60. *
  61. * AI_PASSIVE - Socket address is intended for bind().
  62. * AI_CANONNAME - Request for canonical name.
  63. * AI_NUMERICHOST - Return numeric host address as name.
  64. * AI_NUMERICSERV - Inhibit service name resolution.
  65. * AI_V4MAPPED - If no IPv6 addresses are found, query for IPv4
  66. * addresses and return them to the caller as IPv4-mapped
  67. * IPv6 addresses.
  68. * AI_ALL - Query for both IPv4 and IPv6 addresses.
  69. * AI_ADDRCONFIG - Query for IPv4 addresses only when an IPv4 address is
  70. * configured; query for IPv6 addresses only when an IPv6
  71. * address is configured.
  72. */
  73. #define AI_PASSIVE (1 << 0)
  74. #define AI_CANONNAME (1 << 1)
  75. #define AI_NUMERICHOST (1 << 2)
  76. #define AI_NUMERICSERV (1 << 3)
  77. #define AI_V4MAPPED (1 << 4)
  78. #define AI_ALL (1 << 5)
  79. #define AI_ADDRCONFIG (1 << 6)
  80. /* The <netdb.h> header shall define the following macros that evaluate to
  81. * bitwise-distinct integer constants for use in the flags argument to
  82. * getnameinfo():
  83. *
  84. * NI_NOFQDN - Only the nodename portion of the FQDN is returned for
  85. * local hosts.
  86. * NI_NUMERICHOST - The numeric form of the node's address is returned
  87. * instead of its name.
  88. * NI_NAMEREQD - Return an error if the node's name cannot be located
  89. * in the database.
  90. * NI_NUMERICSERV - The numeric form of the service address is returned
  91. * instead of its name.
  92. * NI_NUMERICSCOPE - For IPv6 addresses, the numeric form of the scope
  93. * identifier is returned instead of its name.
  94. * NI_DGRAM - Indicates that the service is a datagram service
  95. * (SOCK_DGRAM).
  96. */
  97. #define NI_NOFQDN (1 << 0)
  98. #define NI_NUMERICHOST (1 << 1)
  99. #define NI_NAMEREQD (1 << 2)
  100. #define NI_NUMERICSERV (1 << 3)
  101. #define NI_NUMERICSCOPE (1 << 4)
  102. #define NI_DGRAM (1 << 5)
  103. /* Address Information Errors. The <netdb.h> header shall define the
  104. * following macros for use as error values for getaddrinfo() and
  105. * getnameinfo():
  106. *
  107. * EAI_AGAIN - The name could not be resolved at this time. Future
  108. * attempts may succeed.
  109. * EAI_BADFLAGS - The flags had an invalid value.
  110. * EAI_FAIL - A non-recoverable error occurred.
  111. * EAI_FAMILY - The address family was not recognized or the address
  112. * length was invalid for the specified family.
  113. * EAI_MEMORY - There was a memory allocation failure.
  114. * EAI_NONAME - The name does not resolve for the supplied
  115. * parameters. NI_NAMEREQD is set and the host's name
  116. * cannot be located, or both nodename and servname were
  117. * null.
  118. * EAI_SERVICE - The service passed was not recognized for the
  119. * specified socket type.
  120. * EAI_SOCKTYPE - The intended socket type was not recognized.
  121. * EAI_SYSTEM - A system error occurred. The error code can be found
  122. * in errno.
  123. * EAI_OVERFLOW - An argument buffer overflowed.
  124. */
  125. #define EAI_AGAIN 1
  126. #define EAI_BADFLAGS 2
  127. #define EAI_FAIL 3
  128. #define EAI_FAMILY 4
  129. #define EAI_MEMORY 5
  130. #define EAI_NONAME 6
  131. #define EAI_SERVICE 7
  132. #define EAI_SOCKTYPE 8
  133. #define EAI_SYSTEM 9
  134. #define EAI_OVERFLOW 10
  135. /* h_errno values that may be returned by gethosbyname(), gethostbyname_r(),
  136. * gethostbyaddr(), or gethostbyaddr_r()
  137. *
  138. * HOST_NOT_FOUND - No such host is known.
  139. *
  140. * NO_DATA - The server recognized the request and the name, but no
  141. * address is available. Another type of request to the name server
  142. * for the domain might return an answer.
  143. *
  144. * NO_RECOVERY - An unexpected server failure occurred which cannot be
  145. * recovered.
  146. *
  147. * TRY_AGAIN - A temporary and possibly transient error occurred, such as
  148. * a failure of a server to respond.
  149. *
  150. * These are obsolete and were removed in the Open Group Base Specifications
  151. * Issue 7, 2018 edition.
  152. */
  153. #define HOST_NOT_FOUND 1
  154. #define NO_DATA 2
  155. #define NO_RECOVERY 3
  156. #define TRY_AGAIN 4
  157. /****************************************************************************
  158. * Public Types
  159. ****************************************************************************/
  160. struct hostent
  161. {
  162. FAR char *h_name; /* Official name of the host. */
  163. FAR char **h_aliases; /* A pointer to an array of pointers to alternative
  164. * host names, terminated by a null pointer. */
  165. int h_addrtype; /* Address type. */
  166. int h_length; /* The length, in bytes, of the address. */
  167. FAR char **h_addr_list; /* A pointer to an array of pointers to network
  168. * addresses (in network byte order) for the host,
  169. * terminated by a null pointer. */
  170. };
  171. #define h_addr h_addr_list[0] /* For backward compatibility */
  172. struct netent
  173. {
  174. FAR char *n_name; /* Official, fully-qualified (including the domain)
  175. * name of the host. */
  176. FAR char **n_aliases; /* A pointer to an array of pointers to alternative
  177. * network names, terminated by a null pointer. */
  178. int n_addrtype; /* The address type of the network. */
  179. uint32_t n_net; /* The network number, in host byte order. */
  180. };
  181. struct protoent
  182. {
  183. FAR char *p_name; /* Official name of the protocol. */
  184. FAR char **p_aliases; /* A pointer to an array of pointers to
  185. * alternative protocol names, terminated by a
  186. * null pointer. */
  187. int p_proto; /* The protocol number. */
  188. };
  189. struct servent
  190. {
  191. FAR char *s_name; /* Official name of the service. */
  192. FAR char **s_aliases; /* A pointer to an array of pointers to
  193. * alternative service names, terminated by a
  194. * null pointer. */
  195. int s_port; /* The port number at which the service resides,
  196. * in network byte order. */
  197. FAR char *s_proto; /* The name of the protocol to use when
  198. * contacting the service. */
  199. };
  200. struct addrinfo
  201. {
  202. int ai_flags; /* Input flags. */
  203. int ai_family; /* Address family of socket. */
  204. int ai_socktype; /* Socket type. */
  205. int ai_protocol; /* Protocol of socket. */
  206. socklen_t ai_addrlen; /* Length of socket address. */
  207. FAR struct sockaddr *ai_addr; /* Socket address of socket. */
  208. FAR char *ai_canonname; /* Canonical name of service location. */
  209. FAR struct addrinfo *ai_next; /* Pointer to next in list. */
  210. };
  211. /****************************************************************************
  212. * Public Data
  213. ****************************************************************************/
  214. #ifdef __cplusplus
  215. #define EXTERN extern "C"
  216. extern "C"
  217. {
  218. #else
  219. #define EXTERN extern
  220. #endif
  221. /* When the <netdb.h> header is included, h_errno shall be available as a
  222. * modifiable lvalue of type int. It is unspecified whether h_errno is a
  223. * macro or an identifier declared with external linkage.
  224. *
  225. * h_errno is obsolete and was removed in the Open Group Base Specifications
  226. * Issue 7, 2018 edition.
  227. */
  228. /* REVISIT: This should at least be per-task? */
  229. EXTERN int h_errno;
  230. /****************************************************************************
  231. * Public Function Prototypes
  232. ****************************************************************************/
  233. #ifdef CONFIG_LIBC_NETDB
  234. #if 0 /* None of these are yet supported */
  235. void endhostent(void);
  236. void endnetent(void);
  237. void endprotoent(void);
  238. void endservent(void);
  239. #endif
  240. void freeaddrinfo(FAR struct addrinfo *ai);
  241. FAR const char *gai_strerror(int);
  242. int getaddrinfo(FAR const char *nodename,
  243. FAR const char *servname,
  244. FAR const struct addrinfo *hints,
  245. FAR struct addrinfo **res);
  246. FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len,
  247. int type);
  248. FAR struct hostent *gethostbyname(FAR const char *name);
  249. FAR struct servent *getservbyname(FAR const char *name,
  250. FAR const char *proto);
  251. #if 0 /* None of these are yet supported */
  252. FAR struct hostent *gethostent(void);
  253. int getnameinfo(FAR const struct sockaddr *sa,
  254. socklen_t salen, FAR char *node,
  255. socklen_t nodelen, FAR char *service,
  256. socklen_t servicelen, int flags);
  257. FAR struct netent *getnetbyaddr(uint32_t net, int type);
  258. FAR struct netent *getnetbyname(FAR const char *name);
  259. FAR struct netent *getnetent(void);
  260. FAR struct protoent *getprotobyname(FAR const char *name);
  261. FAR struct protoent *getprotobynumber(int proto);
  262. FAR struct protoent *getprotoent(void);
  263. FAR struct servent *getservbyport(int port, FAR const char *proto);
  264. FAR struct servent *getservent(void);
  265. void sethostent(int);
  266. void setnetent(int stayopen);
  267. void setprotoent(int stayopen);
  268. void setservent(int);
  269. #endif /* None of these are yet supported */
  270. /* Non-standard interfaces similar to Glibc 2 interfaces */
  271. int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
  272. FAR struct hostent *host, FAR char *buf,
  273. size_t buflen, int *h_errnop);
  274. int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
  275. FAR char *buf, size_t buflen, int *h_errnop);
  276. int getservbyname_r(FAR const char *name, FAR const char *proto,
  277. FAR struct servent *result_buf, FAR char *buf,
  278. size_t buflen, FAR struct servent **result);
  279. #endif /* CONFIG_LIBC_NETDB */
  280. #undef EXTERN
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284. #endif /* __INCLUDE_NETDB_H */