Simon Zimmermann

2009-12-18

Posix Api

These are my personal notes from Beej’s Guide to Network Programming Using Internet Sockets. I write down what I find important as this makes it easier for me to remember. You should read the guide, not this document. ((http://beej.us/guide/bgnet/))

getaddrinfo()

Given node and service, which identify an Internet host and a service, getaddrinfo() returns one or more addrinfo structures, each of which contains an Internet address that can be specified in a call to bind(2) or connect(2). The getaddrinfo() function combines the functionality provided by the getservbyname(3) and getservbyport(3) functions into a single interface, but unlike the latter functions, getaddrinfo() is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies. ((# man getaddrinfo))

The hints argument points to an addrinfo structure that specifies criteria for selecting the socket address structures returned in the list pointed to by res. If hints is not NULL it points to an addrinfo structure whose ai_family, ai_socktype, and ai_protocol specify criteria that limit the set of socket addresses returned by getaddrinfo(). ((# man getaddrinfo)) synopsis:

include <sys/types.h>

include <sys/socket.h>

include <netdb.h>

int getaddrinfo(const char node, const char service, const struct addrinfo hints, struct addrinfo *res);

void freeaddrinfo(struct addrinfo res); const char gai_strerror(int errcode);

getaddrinfo() returns a pointer to a linked-list which contains the results.

robotics github