Microchip® Advanced Software Framework

lwip/netdb.h File Reference
#include "lwip/opt.h"
#include <stddef.h>
#include "lwip/inet.h"
#include "lwip/sockets.h"

Data Structures

struct  addrinfo
 
struct  hostent
 

Macros

#define EAI_FAIL   202
 
#define EAI_FAMILY   204
 
#define EAI_MEMORY   203
 
#define EAI_NONAME   200
 Errors used by the DNS API functions, h_errno can be one of them. More...
 
#define EAI_SERVICE   201
 
#define freeaddrinfo(addrinfo)   lwip_freeaddrinfo(addrinfo)
 
#define getaddrinfo(nodname, servname, hints, res)   lwip_getaddrinfo(nodname, servname, hints, res)
 
#define gethostbyname(name)   lwip_gethostbyname(name)
 
#define gethostbyname_r(name, ret, buf, buflen, result, h_errnop)   lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
 
#define h_addr   h_addr_list[0] /* for backward compatibility */
 
#define HOST_NOT_FOUND   210
 
#define LWIP_DNS_API_DECLARE_H_ERRNO   1
 
#define LWIP_DNS_API_DECLARE_STRUCTS   1
 
#define LWIP_DNS_API_DEFINE_ERRORS   1
 
#define NETDB_ELEM_SIZE   (sizeof(struct addrinfo) + sizeof(struct sockaddr_in) + DNS_MAX_NAME_LENGTH + 1)
 
#define NO_DATA   211
 
#define NO_RECOVERY   212
 
#define TRY_AGAIN   213
 

Functions

void lwip_freeaddrinfo (struct addrinfo *ai)
 Frees one or more addrinfo structures returned by getaddrinfo(), along with any additional storage associated with those structures. More...
 
int lwip_getaddrinfo (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
 Translates the name of a service location (for example, a host name) and/or a service name and returns a set of socket addresses and associated information to be used in creating a socket with which to address the specified service. More...
 
struct hostentlwip_gethostbyname (const char *name)
 Returns an entry containing addresses of address family AF_INET for the host with name name. More...
 
int lwip_gethostbyname_r (const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
 Thread-safe variant of lwip_gethostbyname: instead of using a static buffer, this function takes buffer and errno pointers as arguments and uses these for the result. More...
 

Variables

int h_errno
 h_errno is exported in netdb.h for access by applications. More...
 

#define EAI_FAIL   202

Referenced by lwip_getaddrinfo().

#define EAI_FAMILY   204

Referenced by lwip_getaddrinfo().

#define EAI_MEMORY   203

Referenced by lwip_getaddrinfo().

#define EAI_NONAME   200

Errors used by the DNS API functions, h_errno can be one of them.

Referenced by lwip_getaddrinfo().

#define EAI_SERVICE   201

Referenced by lwip_getaddrinfo().

#define freeaddrinfo (   addrinfo)    lwip_freeaddrinfo(addrinfo)
#define getaddrinfo (   nodname,
  servname,
  hints,
  res 
)    lwip_getaddrinfo(nodname, servname, hints, res)
#define gethostbyname (   name)    lwip_gethostbyname(name)
#define gethostbyname_r (   name,
  ret,
  buf,
  buflen,
  result,
  h_errnop 
)    lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
#define h_addr   h_addr_list[0] /* for backward compatibility */
#define HOST_NOT_FOUND   210
#define LWIP_DNS_API_DECLARE_H_ERRNO   1
#define LWIP_DNS_API_DECLARE_STRUCTS   1
#define LWIP_DNS_API_DEFINE_ERRORS   1
#define NETDB_ELEM_SIZE   (sizeof(struct addrinfo) + sizeof(struct sockaddr_in) + DNS_MAX_NAME_LENGTH + 1)

Referenced by lwip_getaddrinfo().

#define NO_DATA   211
#define NO_RECOVERY   212
#define TRY_AGAIN   213

void lwip_freeaddrinfo ( struct addrinfo ai)

Frees one or more addrinfo structures returned by getaddrinfo(), along with any additional storage associated with those structures.

If the ai_next field of the structure is not null, the entire list of structures is freed.

Parameters
aistruct addrinfo to free

References addrinfo::ai_next, memp_free(), next, and NULL.

int lwip_getaddrinfo ( const char *  nodename,
const char *  servname,
const struct addrinfo hints,
struct addrinfo **  res 
)

Translates the name of a service location (for example, a host name) and/or a service name and returns a set of socket addresses and associated information to be used in creating a socket with which to address the specified service.

Memory for the result is allocated internally and must be freed by calling lwip_freeaddrinfo()!

Due to a limitation in dns_gethostbyname, only the first address of a host is returned. Also, service names are not supported (only port numbers)!

Parameters
nodenamedescriptive name or address string of the host (may be NULL -> local address)
servnameport number as string of NULL
hintsstructure containing input values that set socktype and protocol
respointer to a pointer where to store the result (set to NULL on failure)
Returns
0 on success, non-zero on failure

References AF_INET, AF_UNSPEC, addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_canonname, addrinfo::ai_family, addrinfo::ai_protocol, addrinfo::ai_socktype, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NONAME, EAI_SERVICE, ERR_OK, htons, inet_addr_from_ipaddr, ip_addr_set_loopback, LWIP_ASSERT, memp_malloc(), netconn_gethostbyname(), NETDB_ELEM_SIZE, NULL, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_len, and sockaddr_in::sin_port.

struct hostent* lwip_gethostbyname ( const char *  name)

Returns an entry containing addresses of address family AF_INET for the host with name name.

Due to dns_gethostbyname limitations, only one address is returned.

Parameters
namethe hostname to resolve
Returns
an entry containing addresses of address family AF_INET for the host with name name

References AF_INET, DNS_DEBUG, ERR_OK, hostent::h_addr_list, hostent::h_addrtype, hostent::h_aliases, h_errno, hostent::h_length, hostent::h_name, HOST_NOT_FOUND, HOSTENT_STORAGE, ip_ntoa, LWIP_DEBUGF, netconn_gethostbyname(), and NULL.

int lwip_gethostbyname_r ( const char *  name,
struct hostent ret,
char *  buf,
size_t  buflen,
struct hostent **  result,
int *  h_errnop 
)

Thread-safe variant of lwip_gethostbyname: instead of using a static buffer, this function takes buffer and errno pointers as arguments and uses these for the result.

Parameters
namethe hostname to resolve
retpre-allocated struct where to store the result
bufpre-allocated buffer where to store additional data
buflenthe size of buf
resultpointer to a hostent pointer that is set to ret on success and set to zero on error
h_errnoppointer to an int where to store errors (instead of modifying the global h_errno)
Returns
0 on success, non-zero on error, additional error information is stored in *h_errnop instead of h_errno to be thread-safe

References gethostbyname_r_helper::addr, gethostbyname_r_helper::addr_list, AF_INET, gethostbyname_r_helper::aliases, DNS_DEBUG, EINVAL, ERANGE, ERR_OK, h, hostent::h_addr_list, hostent::h_addrtype, hostent::h_aliases, hostent::h_length, hostent::h_name, HOST_NOT_FOUND, LWIP_DEBUGF, LWIP_MEM_ALIGN, MEM_ALIGNMENT, netconn_gethostbyname(), and NULL.

int h_errno

h_errno is exported in netdb.h for access by applications.

Referenced by lwip_gethostbyname().