2015-02-17 15:27:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* include/netdb.h
|
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-02-17 15:27:12 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-02-17 15:27:12 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-02-17 15:27:12 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __INCLUDE_NETDB_H
|
|
|
|
#define __INCLUDE_NETDB_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
/* Inclusion of the <netdb.h> header may also make visible all symbols from
|
|
|
|
* <netinet/in.h>, <sys/socket.h>, and <inttypes.h>.
|
|
|
|
*/
|
|
|
|
|
2015-02-17 19:47:48 +01:00
|
|
|
#include <inttypes.h>
|
2015-02-17 15:27:12 +01:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* The <netdb.h> header shall define the IPPORT_RESERVED macro with the
|
|
|
|
* value of the highest reserved Internet port number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IPPORT_RESERVED 0xffff /* No reserved port numbers */
|
|
|
|
|
|
|
|
/* The <netdb.h> header shall define the following macros that evaluate to
|
|
|
|
* bitwise-distinct integer constants for use in the flags field of the
|
|
|
|
* addrinfo structure:
|
|
|
|
*
|
|
|
|
* AI_PASSIVE - Socket address is intended for bind().
|
|
|
|
* AI_CANONNAME - Request for canonical name.
|
|
|
|
* AI_NUMERICHOST - Return numeric host address as name.
|
|
|
|
* AI_NUMERICSERV - Inhibit service name resolution.
|
|
|
|
* AI_V4MAPPED - If no IPv6 addresses are found, query for IPv4
|
|
|
|
* addresses and return them to the caller as IPv4-mapped
|
|
|
|
* IPv6 addresses.
|
|
|
|
* AI_ALL - Query for both IPv4 and IPv6 addresses.
|
|
|
|
* AI_ADDRCONFIG - Query for IPv4 addresses only when an IPv4 address is
|
|
|
|
* configured; query for IPv6 addresses only when an IPv6
|
|
|
|
* address is configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AI_PASSIVE (1 << 0)
|
|
|
|
#define AI_CANONNAME (1 << 1)
|
|
|
|
#define AI_NUMERICHOST (1 << 2)
|
|
|
|
#define AI_NUMERICSERV (1 << 3)
|
|
|
|
#define AI_V4MAPPED (1 << 4)
|
|
|
|
#define AI_ALL (1 << 5)
|
|
|
|
#define AI_ADDRCONFIG (1 << 6)
|
|
|
|
|
|
|
|
/* The <netdb.h> header shall define the following macros that evaluate to
|
|
|
|
* bitwise-distinct integer constants for use in the flags argument to
|
|
|
|
* getnameinfo():
|
|
|
|
*
|
|
|
|
* NI_NOFQDN - Only the nodename portion of the FQDN is returned for
|
|
|
|
* local hosts.
|
|
|
|
* NI_NUMERICHOST - The numeric form of the node's address is returned
|
|
|
|
* instead of its name.
|
|
|
|
* NI_NAMEREQD - Return an error if the node's name cannot be located
|
|
|
|
* in the database.
|
|
|
|
* NI_NUMERICSERV - The numeric form of the service address is returned
|
|
|
|
* instead of its name.
|
|
|
|
* NI_NUMERICSCOPE - For IPv6 addresses, the numeric form of the scope
|
|
|
|
* identifier is returned instead of its name.
|
|
|
|
* NI_DGRAM - Indicates that the service is a datagram service
|
|
|
|
* (SOCK_DGRAM).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NI_NOFQDN (1 << 0)
|
|
|
|
#define NI_NUMERICHOST (1 << 1)
|
|
|
|
#define NI_NAMEREQD (1 << 2)
|
|
|
|
#define NI_NUMERICSERV (1 << 3)
|
|
|
|
#define NI_NUMERICSCOPE (1 << 4)
|
|
|
|
#define NI_DGRAM (1 << 5)
|
|
|
|
|
|
|
|
/* Address Information Errors. The <netdb.h> header shall define the
|
|
|
|
* following macros for use as error values for getaddrinfo() and
|
|
|
|
* getnameinfo():
|
|
|
|
*
|
|
|
|
* EAI_AGAIN - The name could not be resolved at this time. Future
|
|
|
|
* attempts may succeed.
|
2018-06-08 15:07:21 +02:00
|
|
|
* EAI_BADFLAGS - The flags had an invalid value.
|
|
|
|
* EAI_FAIL - A non-recoverable error occurred.
|
2015-02-17 15:27:12 +01:00
|
|
|
* EAI_FAMILY - The address family was not recognized or the address
|
|
|
|
* length was invalid for the specified family.
|
|
|
|
* EAI_MEMORY - There was a memory allocation failure.
|
|
|
|
* EAI_NONAME - The name does not resolve for the supplied
|
|
|
|
* parameters. NI_NAMEREQD is set and the host's name
|
|
|
|
* cannot be located, or both nodename and servname were
|
|
|
|
* null.
|
|
|
|
* EAI_SERVICE - The service passed was not recognized for the
|
|
|
|
* specified socket type.
|
|
|
|
* EAI_SOCKTYPE - The intended socket type was not recognized.
|
|
|
|
* EAI_SYSTEM - A system error occurred. The error code can be found
|
|
|
|
* in errno.
|
|
|
|
* EAI_OVERFLOW - An argument buffer overflowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EAI_AGAIN 1
|
|
|
|
#define EAI_BADFLAGS 2
|
2018-06-08 15:07:21 +02:00
|
|
|
#define EAI_FAIL 3
|
|
|
|
#define EAI_FAMILY 4
|
|
|
|
#define EAI_MEMORY 5
|
|
|
|
#define EAI_NONAME 6
|
|
|
|
#define EAI_SERVICE 7
|
|
|
|
#define EAI_SOCKTYPE 8
|
|
|
|
#define EAI_SYSTEM 9
|
|
|
|
#define EAI_OVERFLOW 10
|
2015-02-17 15:27:12 +01:00
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
/* h_errno values that may be returned by gethosbyname(), gethostbyname_r(),
|
|
|
|
* gethostbyaddr(), or gethostbyaddr_r()
|
|
|
|
*
|
|
|
|
* HOST_NOT_FOUND - No such host is known.
|
|
|
|
*
|
|
|
|
* NO_DATA - The server recognized the request and the name, but no
|
|
|
|
* address is available. Another type of request to the name server
|
|
|
|
* for the domain might return an answer.
|
|
|
|
*
|
|
|
|
* NO_RECOVERY - An unexpected server failure occurred which cannot be
|
|
|
|
* recovered.
|
|
|
|
*
|
|
|
|
* TRY_AGAIN - A temporary and possibly transient error occurred, such as
|
|
|
|
* a failure of a server to respond.
|
2018-06-08 15:07:21 +02:00
|
|
|
*
|
|
|
|
* These are obsolete and were removed in the Open Group Base Specifications
|
|
|
|
* Issue 7, 2018 edition.
|
2015-07-08 21:40:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define HOST_NOT_FOUND 1
|
|
|
|
#define NO_DATA 2
|
2018-11-09 16:04:21 +01:00
|
|
|
#define NO_ADDRESS NO_DATA
|
2015-07-08 21:40:52 +02:00
|
|
|
#define NO_RECOVERY 3
|
|
|
|
#define TRY_AGAIN 4
|
|
|
|
|
2021-02-19 04:44:20 +01:00
|
|
|
/* NI_MAXHOST is the max of
|
|
|
|
*
|
|
|
|
* CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1
|
|
|
|
* INET6_ADDRSTRLEN
|
|
|
|
* INET_ADDRSTRLEN
|
|
|
|
*
|
|
|
|
* Note: INETxxx_ADDRSTRLEN already includes the terminating NUL.
|
|
|
|
* Note: INET6_ADDRSTRLEN > INET_ADDRSTRLEN is assumed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IPv6)
|
2021-03-26 15:10:37 +01:00
|
|
|
#define _INET_ADDRSTRLEN INET6_ADDRSTRLEN
|
2021-02-19 04:44:20 +01:00
|
|
|
#else
|
2021-03-26 15:10:37 +01:00
|
|
|
#define _INET_ADDRSTRLEN INET_ADDRSTRLEN
|
2021-02-19 04:44:20 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETDB_DNSCLIENT) && \
|
|
|
|
(CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1) > _INET_ADDRSTRLEN
|
2021-03-26 15:10:37 +01:00
|
|
|
#define NI_MAXHOST (CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1)
|
2021-02-19 04:44:20 +01:00
|
|
|
#else
|
2021-03-26 15:10:37 +01:00
|
|
|
#define NI_MAXHOST _INET_ADDRSTRLEN
|
2021-02-19 04:44:20 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Right now, g_services_db[] only has "ntp".
|
|
|
|
* 16 should be large enough.
|
|
|
|
*/
|
|
|
|
|
2021-03-26 15:10:37 +01:00
|
|
|
#define NI_MAXSERV 16
|
2021-02-19 04:44:20 +01:00
|
|
|
|
2015-02-17 15:27:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct hostent
|
|
|
|
{
|
|
|
|
FAR char *h_name; /* Official name of the host. */
|
2020-03-30 14:49:28 +02:00
|
|
|
FAR char **h_aliases; /* A pointer to an array of pointers to the
|
|
|
|
* alternative host names, terminated by a
|
|
|
|
* null pointer. */
|
2020-03-31 20:21:04 +02:00
|
|
|
int h_addrtype; /* Address type. */
|
|
|
|
int h_length; /* The length, in bytes, of the address. */
|
2017-06-28 21:30:08 +02:00
|
|
|
FAR char **h_addr_list; /* A pointer to an array of pointers to network
|
|
|
|
* addresses (in network byte order) for the host,
|
2015-02-17 15:27:12 +01:00
|
|
|
* terminated by a null pointer. */
|
|
|
|
};
|
|
|
|
|
2015-07-08 19:11:52 +02:00
|
|
|
#define h_addr h_addr_list[0] /* For backward compatibility */
|
|
|
|
|
2015-02-17 15:27:12 +01:00
|
|
|
struct netent
|
|
|
|
{
|
2020-03-30 14:49:28 +02:00
|
|
|
FAR char *n_name; /* Official, fully-qualified(including the domain)
|
2015-02-17 15:27:12 +01:00
|
|
|
* name of the host. */
|
2020-03-30 14:49:28 +02:00
|
|
|
FAR char **n_aliases; /* A pointer to an array of pointers to the
|
|
|
|
* alternative network names, terminated by a
|
|
|
|
* null pointer. */
|
2015-02-17 15:27:12 +01:00
|
|
|
int n_addrtype; /* The address type of the network. */
|
|
|
|
uint32_t n_net; /* The network number, in host byte order. */
|
|
|
|
};
|
|
|
|
|
2017-06-28 21:30:08 +02:00
|
|
|
struct protoent
|
2015-02-17 15:27:12 +01:00
|
|
|
{
|
|
|
|
FAR char *p_name; /* Official name of the protocol. */
|
|
|
|
FAR char **p_aliases; /* A pointer to an array of pointers to
|
|
|
|
* alternative protocol names, terminated by a
|
|
|
|
* null pointer. */
|
2022-12-02 13:03:15 +01:00
|
|
|
uint8_t p_proto; /* The protocol number. */
|
|
|
|
uint8_t idx; /* Index used by the local database, required
|
|
|
|
* by _r version APIs */
|
2015-02-17 15:27:12 +01:00
|
|
|
};
|
|
|
|
|
2017-06-28 21:30:08 +02:00
|
|
|
struct servent
|
2015-02-17 15:27:12 +01:00
|
|
|
{
|
|
|
|
FAR char *s_name; /* Official name of the service. */
|
|
|
|
FAR char **s_aliases; /* A pointer to an array of pointers to
|
|
|
|
* alternative service names, terminated by a
|
2018-10-28 19:25:57 +01:00
|
|
|
* null pointer. */
|
2015-02-17 15:27:12 +01:00
|
|
|
int s_port; /* The port number at which the service resides,
|
|
|
|
* in network byte order. */
|
|
|
|
FAR char *s_proto; /* The name of the protocol to use when
|
|
|
|
* contacting the service. */
|
|
|
|
};
|
|
|
|
|
2017-06-28 21:30:08 +02:00
|
|
|
struct addrinfo
|
2015-02-17 15:27:12 +01:00
|
|
|
{
|
2018-10-28 19:25:57 +01:00
|
|
|
int ai_flags; /* Input flags. */
|
|
|
|
int ai_family; /* Address family of socket. */
|
|
|
|
int ai_socktype; /* Socket type. */
|
|
|
|
int ai_protocol; /* Protocol of socket. */
|
|
|
|
socklen_t ai_addrlen; /* Length of socket address. */
|
|
|
|
|
|
|
|
FAR struct sockaddr *ai_addr; /* Socket address of socket. */
|
|
|
|
FAR char *ai_canonname; /* Canonical name of service location. */
|
|
|
|
FAR struct addrinfo *ai_next; /* Pointer to next in list. */
|
2015-02-17 15:27:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
2015-02-17 19:44:51 +01:00
|
|
|
|
2015-02-17 15:27:12 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* When the <netdb.h> header is included, h_errno shall be available as a
|
|
|
|
* modifiable lvalue of type int. It is unspecified whether h_errno is a
|
|
|
|
* macro or an identifier declared with external linkage.
|
2018-06-08 15:07:21 +02:00
|
|
|
*
|
|
|
|
* h_errno is obsolete and was removed in the Open Group Base Specifications
|
|
|
|
* Issue 7, 2018 edition.
|
2015-02-17 15:27:12 +01:00
|
|
|
*/
|
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
/* REVISIT: This should at least be per-task? */
|
2018-06-08 15:07:21 +02:00
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
EXTERN int h_errno;
|
2015-02-17 15:27:12 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-08-17 11:33:45 +02:00
|
|
|
int rexec(FAR char **ahost, int inport, FAR const char *user,
|
|
|
|
FAR const char *passwd, FAR const char *cmd, FAR int *fd2p);
|
|
|
|
int rexec_af(FAR char **ahost, int inport, FAR const char *user,
|
|
|
|
FAR const char *passwd, FAR const char *cmd, FAR int *fd2p,
|
|
|
|
sa_family_t af);
|
|
|
|
|
2015-07-10 20:11:40 +02:00
|
|
|
#ifdef CONFIG_LIBC_NETDB
|
2015-02-17 15:27:12 +01:00
|
|
|
#if 0 /* None of these are yet supported */
|
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
void endhostent(void);
|
|
|
|
void endnetent(void);
|
|
|
|
void endprotoent(void);
|
|
|
|
void endservent(void);
|
2018-06-08 15:07:21 +02:00
|
|
|
#endif
|
2018-06-13 05:11:48 +02:00
|
|
|
void freeaddrinfo(FAR struct addrinfo *ai);
|
2015-07-08 21:40:52 +02:00
|
|
|
FAR const char *gai_strerror(int);
|
2018-06-13 05:11:48 +02:00
|
|
|
int getaddrinfo(FAR const char *nodename,
|
|
|
|
FAR const char *servname,
|
|
|
|
FAR const struct addrinfo *hints,
|
|
|
|
FAR struct addrinfo **res);
|
2019-06-30 23:12:34 +02:00
|
|
|
int getnameinfo(FAR const struct sockaddr *sa,
|
|
|
|
socklen_t salen, FAR char *node,
|
|
|
|
socklen_t nodelen, FAR char *service,
|
|
|
|
socklen_t servicelen, int flags);
|
2015-07-08 21:40:52 +02:00
|
|
|
|
2015-07-08 22:33:23 +02:00
|
|
|
FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len,
|
|
|
|
int type);
|
|
|
|
FAR struct hostent *gethostbyname(FAR const char *name);
|
2020-03-31 20:21:04 +02:00
|
|
|
FAR struct hostent *gethostbyname2(FAR const char *name, int type);
|
2019-06-30 23:12:34 +02:00
|
|
|
FAR struct servent *getservbyport(int port, FAR const char *proto);
|
2018-06-08 15:07:21 +02:00
|
|
|
FAR struct servent *getservbyname(FAR const char *name,
|
|
|
|
FAR const char *proto);
|
2015-07-08 21:40:52 +02:00
|
|
|
|
2022-12-02 13:03:15 +01:00
|
|
|
void setprotoent(int stayopen);
|
|
|
|
void endprotoent(void);
|
|
|
|
FAR struct protoent *getprotobyname(FAR const char *name);
|
|
|
|
FAR struct protoent *getprotobynumber(int proto);
|
|
|
|
FAR struct protoent *getprotoent(void);
|
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
#if 0 /* None of these are yet supported */
|
|
|
|
FAR struct hostent *gethostent(void);
|
2018-06-13 05:11:48 +02:00
|
|
|
FAR struct netent *getnetbyaddr(uint32_t net, int type);
|
|
|
|
FAR struct netent *getnetbyname(FAR const char *name);
|
2015-07-08 21:40:52 +02:00
|
|
|
FAR struct netent *getnetent(void);
|
|
|
|
FAR struct servent *getservent(void);
|
|
|
|
void sethostent(int);
|
2018-06-13 05:11:48 +02:00
|
|
|
void setnetent(int stayopen);
|
2015-07-08 21:40:52 +02:00
|
|
|
void setservent(int);
|
2015-02-17 19:44:51 +01:00
|
|
|
#endif /* None of these are yet supported */
|
2015-02-17 15:27:12 +01:00
|
|
|
|
2015-07-08 21:40:52 +02:00
|
|
|
/* Non-standard interfaces similar to Glibc 2 interfaces */
|
|
|
|
|
2015-07-08 22:33:23 +02:00
|
|
|
int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
|
|
|
|
FAR struct hostent *host, FAR char *buf,
|
2020-03-31 20:21:04 +02:00
|
|
|
size_t buflen, FAR struct hostent **result,
|
|
|
|
FAR int *h_errnop);
|
|
|
|
int gethostbyname_r(FAR const char *name,
|
|
|
|
FAR struct hostent *host, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct hostent **result,
|
|
|
|
FAR int *h_errnop);
|
|
|
|
int gethostbyname2_r(FAR const char *name, int type,
|
|
|
|
FAR struct hostent *host, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct hostent **result,
|
|
|
|
FAR int *h_errnop);
|
2019-06-30 23:12:34 +02:00
|
|
|
int getservbyport_r(int port, FAR const char *proto,
|
|
|
|
FAR struct servent *result_buf, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct servent **result);
|
2018-06-08 15:07:21 +02:00
|
|
|
int getservbyname_r(FAR const char *name, FAR const char *proto,
|
|
|
|
FAR struct servent *result_buf, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct servent **result);
|
2015-07-08 21:40:52 +02:00
|
|
|
|
2022-12-02 13:03:15 +01:00
|
|
|
void setprotoent_r(int stayopen, FAR struct protoent *result_buf);
|
|
|
|
void endprotoent_r(FAR struct protoent *result_buf);
|
|
|
|
int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct protoent **result);
|
|
|
|
int getprotobyname_r(FAR const char *name,
|
|
|
|
FAR struct protoent *result_buf, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct protoent **result);
|
|
|
|
int getprotobynumber_r(int proto,
|
|
|
|
FAR struct protoent *result_buf, FAR char *buf,
|
|
|
|
size_t buflen, FAR struct protoent **result);
|
|
|
|
|
2015-07-10 20:11:40 +02:00
|
|
|
#endif /* CONFIG_LIBC_NETDB */
|
2015-07-08 21:40:52 +02:00
|
|
|
|
2015-02-17 15:27:12 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __INCLUDE_NETDB_H */
|