1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2018-05-24     ChenYong     First version
9  */
10 #ifndef SAL_NETDB_H__
11 #define SAL_NETDB_H__
12 
13 #include <stddef.h>
14 #include "sal_socket.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #define EAI_NONAME      200
21 #define EAI_SERVICE     201
22 #define EAI_FAIL        202
23 #define EAI_MEMORY      203
24 #define EAI_FAMILY      204
25 
26 #define HOST_NOT_FOUND  210
27 #define NO_DATA         211
28 #define NO_RECOVERY     212
29 #define TRY_AGAIN       213
30 
31 #define AI_PASSIVE      0x01
32 #define AI_CANONNAME    0x02
33 #define AI_NUMERICHOST  0x04
34 #define AI_NUMERICSERV  0x08
35 #define AI_V4MAPPED     0x10
36 #define AI_ALL          0x20
37 #define AI_ADDRCONFIG   0x40
38 
39 /* input flags for structure addrinfo */
40 #define AI_PASSIVE      0x01
41 #define AI_CANONNAME    0x02
42 #define AI_NUMERICHOST  0x04
43 #define AI_NUMERICSERV  0x08
44 #define AI_V4MAPPED     0x10
45 #define AI_ALL          0x20
46 #define AI_ADDRCONFIG   0x40
47 
48 #define DNS_MAX_NAME_LENGTH 256
49 
50 struct hostent {
51     char  *h_name;      /* Official name of the host. */
52     char **h_aliases;   /* A pointer to an array of pointers to alternative host names,
53                            terminated by a null pointer. */
54     int    h_addrtype;  /* Address type. */
55     int    h_length;    /* The length, in bytes, of the address. */
56     char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
57                            network byte order) for the host, terminated by a null pointer. */
58 #define h_addr h_addr_list[0] /* for backward compatibility */
59 };
60 
61 struct addrinfo {
62     int               ai_flags;      /* Input flags. */
63     int               ai_family;     /* Address family of socket. */
64     int               ai_socktype;   /* Socket type. */
65     int               ai_protocol;   /* Protocol of socket. */
66     socklen_t         ai_addrlen;    /* Length of socket address. */
67     struct sockaddr  *ai_addr;       /* Socket address of socket. */
68     char             *ai_canonname;  /* Canonical name of service location. */
69     struct addrinfo  *ai_next;       /* Pointer to next in list. */
70 };
71 
72 struct hostent *sal_gethostbyname(const char *name);
73 
74 int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
75                 size_t buflen, struct hostent **result, int *h_errnop);
76 void sal_freeaddrinfo(struct addrinfo *ai);
77 int sal_getaddrinfo(const char *nodename,
78        const char *servname,
79        const struct addrinfo *hints,
80        struct addrinfo **res);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif /* SAL_NETDB_H__ */
87