Comtrol eCos User Manual

Page 513

Advertising
background image

Chapter 38. TCP/IP Library Reference

SYNOPSIS

#include

<

sys/types.h>

#include

<

sys/socket.h>

#include

<

netdb.h>

int

getaddrinfo(const char *nodename, const char *servname,

const struct addrinfo *hints, struct addrinfo **res);

void

freeaddrinfo(struct addrinfo *ai);

char *

gai_strerror(int ecode);

DESCRIPTION

The getaddrinfo() function is defined for protocol-independent nodename-

to-address translation.

It performs the functionality of

gethostbyname(3) and getservbyname(3), but in a more sophisticated man-

ner.

The addrinfo structure is defined as a result of including the

<

netdb.h>

header:

struct addrinfo {

*

int

ai_flags;

/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */

int

ai_family;

/* PF_xxx */

int

ai_socktype;

/* SOCK_xxx */

int

ai_protocol;

/* 0 or IPPROTO_xxx for IPv4 and IPv6 */

size_t

ai_addrlen;

/* length of ai_addr */

char

*ai_canonname; /* canonical name for nodename */

struct sockaddr

*ai_addr; /* binary address */

struct addrinfo

*ai_next; /* next structure in linked list */

};

The nodename and servname arguments are pointers to NUL-terminated

strings or NULL.

One or both of these two arguments must be a non-null

pointer.

In the normal client scenario, both the nodename and servname

are specified.

In the normal server scenario, only the servname is spec-

ified.

A non-null nodename string can be either a node name or a numeric

host address string (i.e., a dotted-decimal IPv4 address or an IPv6 hex

address).

A non-null servname string can be either a service name or a

decimal port number.

The caller can optionally pass an addrinfo structure, pointed to by the

third argument, to provide hints concerning the type of socket that the

caller supports.

In this hints structure all members other than

ai_flags, ai_family, ai_socktype, and ai_protocol must be zero or a null

pointer.

A value of PF_UNSPEC for ai_family means the caller will accept

any protocol family.

A value of 0 for ai_socktype means the caller will

accept any socket type.

A value of 0 for ai_protocol means the caller

will accept any protocol.

For example, if the caller handles only TCP

and not UDP, then the ai_socktype member of the hints structure should be

set to SOCK_STREAM when getaddrinfo() is called.

If the caller handles

409

Advertising