Using getaddrinfo()

Although we've been using getaddrinfo() in previous chapters, we'll discuss it in more detail here.

The declaration for getaddrinfo() is shown in the following code:

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

The preceding code snippet is explained as follows:

  • node specifies a hostname or address as a string. Valid examples could be,, or ::1.
  • service specifies a service or port number as a string. Valid examples could be http or 80. Alternately, the null pointer can be passed in for service, in which case, the resulting address is set to port 0.
  • hints is a pointer to a struct addrinfo, which specifies options for selecting the ...

Get Hands-On Network Programming with C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.