1 /* remaining argument check */
2 if ((argc - optind) != 2) {
3 printf("Wrong number of arguments %d\n", argc - optind);
7 ret = getaddrinfo(argv[optind], argv[optind+1], &hint, &res);
9 printf("Resolution error %s\n", gai_strerror(ret));
12 ptr = res; /* init list pointer */
13 printf("Canonical name %s\n", ptr->ai_canonname); /* print cname */
14 while (ptr != NULL) { /* loop on list */
15 if (ptr->ai_family == AF_INET) { /* if IPv4 */
16 printf("IPv4 address: \n");
17 addr = (struct sockaddr_in *) ptr->ai_addr; /* address */
18 port = ntohs(addr->sin_port); /* port */
19 string = inet_ntop(addr->sin_family, &addr->sin_addr,
20 buffer, sizeof(buffer));
21 } else if (ptr->ai_family == AF_INET6) { /* if IPv6 */
22 printf("IPv6 address: \n");
23 addr6 = (struct sockaddr_in6 *) ptr->ai_addr; /* address */
24 port = ntohs(addr6->sin6_port); /* port */
25 string = inet_ntop(addr6->sin6_family, &addr6->sin6_addr,
26 buffer, sizeof(buffer));
27 } else { /* else is an error */
28 printf("Address family error\n");
31 printf("\tIndirizzo %s\n", string);
32 printf("\tProtocollo %i\n", ptr->ai_protocol);
33 printf("\tPorta %i\n", port);