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