2018-07-17 20:29:33 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-07-17 20:29:33 +08:00
|
|
|
*
|
2018-10-15 01:23:33 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-07-17 20:29:33 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-05-24 ChenYong First version
|
|
|
|
*/
|
|
|
|
#ifndef SAL_NETDB_H__
|
|
|
|
#define SAL_NETDB_H__
|
|
|
|
|
2021-09-12 02:43:09 +08:00
|
|
|
#include <stddef.h>
|
2019-04-16 18:24:55 +08:00
|
|
|
#include "sal_socket.h"
|
2018-07-17 20:29:33 +08:00
|
|
|
|
2018-08-25 21:04:11 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 20:29:33 +08:00
|
|
|
#define EAI_NONAME 200
|
|
|
|
#define EAI_SERVICE 201
|
|
|
|
#define EAI_FAIL 202
|
|
|
|
#define EAI_MEMORY 203
|
|
|
|
#define EAI_FAMILY 204
|
|
|
|
|
|
|
|
#define HOST_NOT_FOUND 210
|
|
|
|
#define NO_DATA 211
|
|
|
|
#define NO_RECOVERY 212
|
|
|
|
#define TRY_AGAIN 213
|
|
|
|
|
|
|
|
#define AI_PASSIVE 0x01
|
|
|
|
#define AI_CANONNAME 0x02
|
|
|
|
#define AI_NUMERICHOST 0x04
|
|
|
|
#define AI_NUMERICSERV 0x08
|
|
|
|
#define AI_V4MAPPED 0x10
|
|
|
|
#define AI_ALL 0x20
|
|
|
|
#define AI_ADDRCONFIG 0x40
|
|
|
|
|
|
|
|
/* input flags for structure addrinfo */
|
|
|
|
#define AI_PASSIVE 0x01
|
|
|
|
#define AI_CANONNAME 0x02
|
|
|
|
#define AI_NUMERICHOST 0x04
|
|
|
|
#define AI_NUMERICSERV 0x08
|
|
|
|
#define AI_V4MAPPED 0x10
|
|
|
|
#define AI_ALL 0x20
|
|
|
|
#define AI_ADDRCONFIG 0x40
|
|
|
|
|
|
|
|
#define DNS_MAX_NAME_LENGTH 256
|
|
|
|
|
|
|
|
struct hostent {
|
|
|
|
char *h_name; /* Official name of the host. */
|
|
|
|
char **h_aliases; /* A pointer to an array of pointers to alternative host names,
|
|
|
|
terminated by a null pointer. */
|
|
|
|
int h_addrtype; /* Address type. */
|
|
|
|
int h_length; /* The length, in bytes, of the address. */
|
|
|
|
char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
|
|
|
|
network byte order) for the host, terminated by a null pointer. */
|
|
|
|
#define h_addr h_addr_list[0] /* for backward compatibility */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addrinfo {
|
|
|
|
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. */
|
|
|
|
struct sockaddr *ai_addr; /* Socket address of socket. */
|
|
|
|
char *ai_canonname; /* Canonical name of service location. */
|
|
|
|
struct addrinfo *ai_next; /* Pointer to next in list. */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hostent *sal_gethostbyname(const char *name);
|
|
|
|
|
|
|
|
int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
|
|
|
size_t buflen, struct hostent **result, int *h_errnop);
|
|
|
|
void sal_freeaddrinfo(struct addrinfo *ai);
|
|
|
|
int sal_getaddrinfo(const char *nodename,
|
|
|
|
const char *servname,
|
|
|
|
const struct addrinfo *hints,
|
|
|
|
struct addrinfo **res);
|
|
|
|
|
2018-08-25 21:04:11 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 20:29:33 +08:00
|
|
|
#endif /* SAL_NETDB_H__ */
|