/* * File : sal_netdb.h * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Change Logs: * Date Author Notes * 2018-05-24 ChenYong First version */ #ifndef SAL_NETDB_H__ #define SAL_NETDB_H__ #include #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); #endif /* SAL_NETDB_H__ */