2 #include "getaddrinfo.h"
7 int simple (char *host, char *service)
10 struct addrinfo hints;
11 struct addrinfo *ai0, *ai;
14 printf ("Finding %s service %s...\n", host, service);
16 memset (&hints, 0, sizeof (hints));
17 hints.ai_flags = AI_CANONNAME;
18 hints.ai_family = AF_INET;
19 hints.ai_socktype = SOCK_STREAM;
20 res = getaddrinfo (host, 0, 0, &ai0);
22 printf ("res %d: %s\n", res, gai_strerror (res));
27 for (ai = ai0; ai; ai = ai->ai_next)
29 printf ("\tflags %x\n", ai->ai_flags);
30 printf ("\tfamily %x\n", ai->ai_family);
31 printf ("\tsocktype %x\n", ai->ai_socktype);
32 printf ("\tprotocol %x\n", ai->ai_protocol);
33 printf ("\taddrlen %d: ", ai->ai_addrlen);
34 printf ("\tFound %s\n",
35 inet_ntop (ai->ai_family,
36 &((struct sockaddr_in *)
37 ai->ai_addr)->sin_addr,
38 buf, sizeof (buf) - 1));
40 printf ("\tFound %s...\n", ai->ai_canonname);
48 #define HOST1 "www.gnu.org"
50 #define HOST2 "www.ibm.com"
52 #define HOST3 "ibm.org"
54 #define HOST4 "google.org"
59 return simple (HOST1, SERV1)
60 + simple (HOST2, SERV2)
61 + simple (HOST3, SERV3)
62 + simple (HOST4, SERV4);