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 example.com, 192.168.1.1, 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.