Loading...
Searching...
No Matches
netdb.c File Reference
`#include "lwip/netdb.h"`
`#include "lwip/err.h"`
`#include "lwip/errno.h"`
`#include "lwip/mem.h"`
`#include "lwip/memp.h"`
`#include "lwip/ip_addr.h"`
`#include "lwip/api.h"`
`#include "lwip/dns.h"`
`#include <string.h>`
`#include <stdlib.h>`

## Data Structures

struct | gethostbyname_r_helper

## Macros

#define | LWIP_DNS_API_HOSTENT_STORAGE 0

## Functions

struct hostent * | lwip_gethostbyname (const char *name)
int | lwip_gethostbyname_r (const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
void | lwip_freeaddrinfo (struct addrinfo *ai)
int | lwip_getaddrinfo (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)

## Variables

int | h_errno

## Detailed Description

API functions for name resolving

## Macro Definition Documentation

## LWIP_DNS_API_HOSTENT_STORAGE

#define LWIP_DNS_API_HOSTENT_STORAGE 0

LWIP_DNS_API_HOSTENT_STORAGE: if set to 0 (default), lwip_gethostbyname() returns the same global variable for all calls (in all threads). When set to 1, your port should provide a function struct hostent* sys_thread_hostent( struct hostent* h); which have to do a copy of "h" and return a pointer ont the "per-thread" copy.

## Function Documentation

## lwip_freeaddrinfo()

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

  ai | struct addrinfo to free

## lwip_getaddrinfo()

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

  nodename | descriptive name or address string of the host (may be NULL -> local address)
  servname | port number as string of NULL
  hints | structure containing input values that set socktype and protocol
  res | pointer to a pointer where to store the result (set to NULL on failure)

Returns
  0 on success, non-zero on failure

## lwip_gethostbyname()

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

  name | the hostname to resolve

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

## lwip_gethostbyname_r()

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

  name | the hostname to resolve
  ret | pre-allocated struct where to store the result
  buf | pre-allocated buffer where to store additional data
  buflen | the size of buf
  result | pointer to a hostent pointer that is set to ret on success and set to zero on error
  h_errnop | pointer 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

## Variable Documentation

## h_errno

int h_errno

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