Simon Cooksey / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netdb.h Source File

netdb.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * NETDB API (sockets)
00004  */
00005 
00006 /*
00007  * Redistribution and use in source and binary forms, with or without modification,
00008  * are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice,
00011  *    this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright notice,
00013  *    this list of conditions and the following disclaimer in the documentation
00014  *    and/or other materials provided with the distribution.
00015  * 3. The name of the author may not be used to endorse or promote products
00016  *    derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00019  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00020  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00021  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00023  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00026  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00027  * OF SUCH DAMAGE.
00028  *
00029  * This file is part of the lwIP TCP/IP stack.
00030  *
00031  * Author: Simon Goldschmidt
00032  *
00033  */
00034 #ifndef LWIP_HDR_NETDB_H
00035 #define LWIP_HDR_NETDB_H
00036 
00037 #include "lwip/opt.h"
00038 
00039 #if LWIP_DNS && LWIP_SOCKET
00040 
00041 #include <stddef.h> /* for size_t */
00042 
00043 #include "lwip/inet.h"
00044 #include "lwip/sockets.h"
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /* some rarely used options */
00051 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
00052 #define LWIP_DNS_API_DECLARE_H_ERRNO  1
00053 #endif
00054 
00055 #ifndef LWIP_DNS_API_DEFINE_ERRORS
00056 #define LWIP_DNS_API_DEFINE_ERRORS    1
00057 #endif
00058 
00059 #ifndef LWIP_DNS_API_DEFINE_FLAGS
00060 #define LWIP_DNS_API_DEFINE_FLAGS     1
00061 #endif
00062 
00063 #ifndef LWIP_DNS_API_DECLARE_STRUCTS
00064 #define LWIP_DNS_API_DECLARE_STRUCTS  1
00065 #endif
00066 
00067 #if LWIP_DNS_API_DEFINE_ERRORS
00068 /** Errors used by the DNS API functions, h_errno can be one of them */
00069 #define EAI_NONAME      200
00070 #define EAI_SERVICE     201
00071 #define EAI_FAIL        202
00072 #define EAI_MEMORY      203
00073 #define EAI_FAMILY      204
00074 
00075 #define HOST_NOT_FOUND  210
00076 #define NO_DATA         211
00077 #define NO_RECOVERY     212
00078 #define TRY_AGAIN       213
00079 #endif /* LWIP_DNS_API_DEFINE_ERRORS */
00080 
00081 #if LWIP_DNS_API_DEFINE_FLAGS
00082 /* input flags for struct addrinfo */
00083 #define AI_PASSIVE      0x01
00084 #define AI_CANONNAME    0x02
00085 #define AI_NUMERICHOST  0x04
00086 #define AI_NUMERICSERV  0x08
00087 #define AI_V4MAPPED     0x10
00088 #define AI_ALL          0x20
00089 #define AI_ADDRCONFIG   0x40
00090 #endif /* LWIP_DNS_API_DEFINE_FLAGS */
00091 
00092 #if LWIP_DNS_API_DECLARE_STRUCTS
00093 struct hostent {
00094     char  *h_name;      /* Official name of the host. */
00095     char **h_aliases;   /* A pointer to an array of pointers to alternative host names,
00096                            terminated by a null pointer. */
00097     int    h_addrtype;  /* Address type. */
00098     int    h_length;    /* The length, in bytes, of the address. */
00099     char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
00100                            network byte order) for the host, terminated by a null pointer. */
00101 #define h_addr h_addr_list[0] /* for backward compatibility */
00102 };
00103 
00104 struct addrinfo {
00105     int               ai_flags;      /* Input flags. */
00106     int               ai_family;     /* Address family of socket. */
00107     int               ai_socktype;   /* Socket type. */
00108     int               ai_protocol;   /* Protocol of socket. */
00109     socklen_t         ai_addrlen;    /* Length of socket address. */
00110     struct sockaddr  *ai_addr;       /* Socket address of socket. */
00111     char             *ai_canonname;  /* Canonical name of service location. */
00112     struct addrinfo  *ai_next;       /* Pointer to next in list. */
00113 };
00114 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
00115 
00116 #define NETDB_ELEM_SIZE           (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
00117 
00118 #if LWIP_DNS_API_DECLARE_H_ERRNO
00119 /* application accessible error code set by the DNS API functions */
00120 extern int h_errno;
00121 #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
00122 
00123 struct hostent *lwip_gethostbyname(const char *name);
00124 int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
00125                 size_t buflen, struct hostent **result, int *h_errnop);
00126 void lwip_freeaddrinfo(struct addrinfo *ai);
00127 int lwip_getaddrinfo(const char *nodename,
00128        const char *servname,
00129        const struct addrinfo *hints,
00130        struct addrinfo **res);
00131 
00132 #if LWIP_COMPAT_SOCKETS
00133 /** @ingroup netdbapi */
00134 #define gethostbyname(name) lwip_gethostbyname(name)
00135 /** @ingroup netdbapi */
00136 #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
00137        lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
00138 /** @ingroup netdbapi */
00139 #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo)
00140 /** @ingroup netdbapi */
00141 #define getaddrinfo(nodname, servname, hints, res) \
00142        lwip_getaddrinfo(nodname, servname, hints, res)
00143 #endif /* LWIP_COMPAT_SOCKETS */
00144 
00145 #ifdef __cplusplus
00146 }
00147 #endif
00148 
00149 #endif /* LWIP_DNS && LWIP_SOCKET */
00150 
00151 #endif /* LWIP_HDR_NETDB_H */