Commit e196e273 authored by Gero Hülsbusch's avatar Gero Hülsbusch
Browse files

Update get_addresses.c

parent 76ee48cc
......@@ -57,6 +57,17 @@ getnameinfo https://man7.org/linux/man-pages/man3/getnameinfo.3.html
follows:
getaddrinfo https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
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 gethostbyname(3) and
getservbyname(3) functions into a single interface, but unlike
the latter functions, getaddrinfo() is reentrant and allows
programs to eliminate IPv4-versus-IPv6 dependencies.
*/
#include "Socket.h"
......@@ -71,9 +82,10 @@ int main(int argc, char* argv[]) {
}
int ret;
//The getnameinfo() function is the inverse of getaddrinfo(3): it
//converts a socket address to a corresponding host and service, in
//a protocol-independent manner.
//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).
if ((ret = getaddrinfo(argv[1], NULL, NULL, &result))) {
fprintf(stderr, "Getaddrinfo: %s\n", gai_strerror(ret));
return 2;
......@@ -81,7 +93,9 @@ int main(int argc, char* argv[]) {
for (entry = result; entry != NULL; entry = entry->ai_next) {
char hostname[NI_MAXHOST] = "";
//The getnameinfo() function is the inverse of getaddrinfo(3): it
//converts a socket address to a corresponding host and service, in
//a protocol-independent manner.
getnameinfo(entry->ai_addr, entry->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
printf("%s Protocol: %d, Socktype: %d\n", hostname, entry->ai_protocol, entry->ai_socktype);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment