posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
netdb.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
20#ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_
21#define ZEPHYR_INCLUDE_POSIX_NETDB_H_
22
23#include <stdint.h>
24
25#include <zephyr/net/socket.h>
26#include <zephyr/net/dns_resolve.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#if !(defined(_HOSTENT_DECLARED) || defined(__hostent_defined)) || defined(__DOXYGEN__)
34struct hostent {
35 char *h_name;
36 char **h_aliases;
39 char **h_addr_list;
40};
41#define _HOSTENT_DECLARED
42#define __hostent_defined
43#endif
44
45#if !(defined(_NETENT_DECLARED) || defined(__netent_defined)) || defined(__DOXYGEN__)
47struct netent {
48 char *n_name;
49 char **n_aliases;
51 uint32_t n_net;
52};
53#define _NETENT_DECLARED
54#define __netent_defined
55#endif
56
57#if !(defined(_PROTOENT_DECLARED) || defined(__protoent_defined)) || defined(__DOXYGEN__)
59struct protoent {
60 char *p_name;
61 char **p_aliases;
62 int p_proto;
63};
64#define _PROTOENT_DECLARED
65#define __protoent_defined
66#endif
67
68#if !(defined(_SERVENT_DECLARED) || defined(__servent_defined)) || defined(__DOXYGEN__)
70struct servent {
71 char *s_name;
72 char **s_aliases;
73 int s_port;
74 char *s_proto;
75};
76#define _SERVENT_DECLARED
77#define __servent_defined
78#endif
79
81#define IPPORT_RESERVED 1024
82
83/*
84 * required by addrinfo and several functions but absent in the spec
85 * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html
86 */
87#if !defined(_SOCKLEN_T_DECLARED) && !defined(__socklen_t_defined)
88typedef net_socklen_t socklen_t;
89#define _SOCKLEN_T_DECLARED
90#define __socklen_t_defined
91#endif
92
93#if !defined(_SA_FAMILY_T_DECLARED) && !defined(__sa_family_t_defined)
94typedef net_sa_family_t sa_family_t;
95#define _SA_FAMILY_T_DECLARED
96#define __sa_family_t_defined
97#endif
98
99#if !defined(_SOCKADDR_DECLARED) && !defined(__sockaddr_defined)
104#define _SOCKADDR_DECLARED
105#define __sockaddr_defined
106#endif
107
108#if !(defined(_ADDRINFO_DECLARED) || defined(__addrinfo_defined)) || defined(__DOXYGEN__)
110struct addrinfo {
117 int ai_eflags; /* for zephyr compatibility */
119 socklen_t ai_addrlen;
123 struct net_sockaddr_storage _ai_addr; /* for zephyr compatibility */
124 char _ai_canonname[DNS_MAX_NAME_SIZE + 1]; /* for zephyr compatibility */
126};
127#define _ADDRINFO_DECLARED
128#define __addrinfo_defined
129#endif
130
131/* getaddrinfo() flags for @c addrinfo.ai_flags. */
133#define AI_PASSIVE ZSOCK_AI_PASSIVE
135#define AI_CANONNAME ZSOCK_AI_CANONNAME
137#define AI_NUMERICHOST ZSOCK_AI_NUMERICHOST
139#define AI_NUMERICSERV ZSOCK_AI_NUMERICSERV
141#define AI_V4MAPPED ZSOCK_AI_V4MAPPED
143#define AI_ALL ZSOCK_AI_ALL
145#define AI_ADDRCONFIG ZSOCK_AI_ADDRCONFIG
146
147/* getnameinfo() flags for the @p flags argument. */
149#define NI_NOFQDN ZSOCK_NI_NOFQDN
151#define NI_NUMERICHOST ZSOCK_NI_NUMERICHOST
153#define NI_NAMEREQD ZSOCK_NI_NAMEREQD
155#define NI_NUMERICSERV ZSOCK_NI_NUMERICSERV
157#define NI_NUMERICSCOPE 32
159#define NI_DGRAM ZSOCK_NI_DGRAM
160
161/* Error values for @ref getaddrinfo and @ref getnameinfo. */
163#define EAI_AGAIN DNS_EAI_AGAIN
165#define EAI_BADFLAGS DNS_EAI_BADFLAGS
167#define EAI_FAIL DNS_EAI_FAIL
169#define EAI_FAMILY DNS_EAI_FAMILY
171#define EAI_MEMORY DNS_EAI_MEMORY
173#define EAI_NONAME DNS_EAI_NONAME
175#define EAI_SERVICE DNS_EAI_SERVICE
177#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
179#define EAI_SYSTEM DNS_EAI_SYSTEM
181#define EAI_OVERFLOW DNS_EAI_OVERFLOW
182
183/* Non-POSIX extensions. */
184#ifndef NI_MAXHOST
186#define NI_MAXHOST 64
187#endif
188#ifndef NI_MAXSERV
190#define NI_MAXSERV 32
191#endif
193#define EAI_NODATA DNS_EAI_NODATA
194
200void endhostent(void);
201
207void endnetent(void);
208
214void endprotoent(void);
215
221void endservent(void);
222
229void freeaddrinfo(struct addrinfo *ai);
230
238const char *gai_strerror(int errcode);
239
250int getaddrinfo(const char *host, const char *service, const struct addrinfo *hints,
251 struct addrinfo **res);
252
259struct hostent *gethostent(void);
260
274int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
275 char *serv, socklen_t servlen, int flags);
276
285struct netent *getnetbyaddr(uint32_t net, int type);
286
294struct netent *getnetbyname(const char *name);
295
302struct netent *getnetent(void);
303
311struct protoent *getprotobyname(const char *name);
312
320struct protoent *getprotobynumber(int proto);
321
328struct protoent *getprotoent(void);
329
338struct servent *getservbyname(const char *name, const char *proto);
339
348struct servent *getservbyport(int port, const char *proto);
349
356struct servent *getservent(void);
357
364void sethostent(int stayopen);
365
372void setnetent(int stayopen);
373
380void setprotoent(int stayopen);
381
388void setservent(int stayopen);
389
390#ifdef __cplusplus
391}
392#endif
393
394#endif /* ZEPHYR_INCLUDE_POSIX_NETDB_H_ */
struct servent * getservbyport(int port, const char *proto)
Look up a service by port number and protocol.
void setnetent(int stayopen)
Open the networks database.
struct netent * getnetbyaddr(uint32_t net, int type)
Look up a network by address.
struct netent * getnetent(void)
Get the next entry from the networks database.
struct protoent * getprotobyname(const char *name)
Look up a protocol by name.
struct netent * getnetbyname(const char *name)
Look up a network by name.
void endprotoent(void)
Close the protocols database.
int getaddrinfo(const char *host, const char *service, const struct addrinfo *hints, struct addrinfo **res)
Translate a hostname and service to a list of socket addresses.
struct hostent * gethostent(void)
Get the next entry from the hosts database.
void freeaddrinfo(struct addrinfo *ai)
Free addrinfo list returned by getaddrinfo.
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
Translate a socket address to a hostname and service name.
void setprotoent(int stayopen)
Open the protocols database.
const char * gai_strerror(int errcode)
Return a string describing a getaddrinfo error code.
struct protoent * getprotoent(void)
Get the next entry from the protocols database.
void endnetent(void)
Close the networks database.
struct servent * getservbyname(const char *name, const char *proto)
Look up a service by name and protocol.
struct servent * getservent(void)
Get the next entry from the services database.
void setservent(int stayopen)
Open the services database.
struct protoent * getprotobynumber(int proto)
Look up a protocol by number.
void endhostent(void)
Close the hosts database.
void sethostent(int stayopen)
Open the hosts database.
void endservent(void)
Close the services database.
net_sa_family_t sa_family_t
Socket address family type.
Definition socket.h:39
Address info structure returned by getaddrinfo.
Definition netdb.h:110
struct sockaddr * ai_addr
Socket address for this entry.
Definition netdb.h:120
char * ai_canonname
Canonical host name, or NULL.
Definition netdb.h:121
int ai_socktype
Socket type (SOCK_STREAM, SOCK_DGRAM, ...).
Definition netdb.h:114
int ai_protocol
Protocol (IPPROTO_*), or 0 for any.
Definition netdb.h:115
socklen_t ai_addrlen
Length of addrinfo.ai_addr in bytes.
Definition netdb.h:119
struct addrinfo * ai_next
Next entry in the linked list, or NULL.
Definition netdb.h:111
int ai_flags
Input AI_* flags.
Definition netdb.h:112
int ai_family
Address family (AF_INET, AF_INET6, AF_UNSPEC).
Definition netdb.h:113
Host database entry.
Definition netdb.h:34
int h_addrtype
Address type (AF_INET, etc.).
Definition netdb.h:37
char * h_name
Official name of the host.
Definition netdb.h:35
char ** h_addr_list
NULL-terminated list of addresses.
Definition netdb.h:39
int h_length
Length of each address in bytes.
Definition netdb.h:38
char ** h_aliases
NULL-terminated list of alternate names.
Definition netdb.h:36
Network database entry.
Definition netdb.h:47
uint32_t n_net
Network number (host byte order).
Definition netdb.h:51
char ** n_aliases
NULL-terminated list of alternate names.
Definition netdb.h:49
char * n_name
Official network name.
Definition netdb.h:48
int n_addrtype
Address type (AF_INET).
Definition netdb.h:50
Protocol database entry.
Definition netdb.h:59
int p_proto
Protocol number.
Definition netdb.h:62
char ** p_aliases
NULL-terminated list of alternate names.
Definition netdb.h:61
char * p_name
Official protocol name.
Definition netdb.h:60
Service database entry.
Definition netdb.h:70
char * s_name
Official service name.
Definition netdb.h:71
char * s_proto
Protocol to use ("tcp" or "udp").
Definition netdb.h:74
char ** s_aliases
NULL-terminated list of alternate names.
Definition netdb.h:72
int s_port
Port number (network byte order).
Definition netdb.h:73
Generic socket address.
Definition netdb.h:100
char sa_data[14]
Address payload.
Definition netdb.h:102
sa_family_t sa_family
Address family.
Definition netdb.h:101