2 * trygetif.c - test program for getif.c
8 #include <sys/socket.h>
10 #if defined(SUNOS) || defined(SVR4)
11 #include <sys/sockio.h>
15 #include <sys/time.h> /* for struct timeval in net/if.h */
17 #include <net/if.h> /* for struct ifreq */
18 #include <netinet/in.h>
19 #include <arpa/inet.h> /* inet_ntoa */
37 struct sockaddr_in *sip; /* Interface address */
39 struct in_addr dst_addr;
43 progname = argv[0]; /* for report */
48 if (isdigit(argv[1][0]))
49 dst_addr.s_addr = inet_addr(argv[1]);
51 hep = gethostbyname(argv[1]);
53 printf("gethostbyname(%s)\n", argv[1]);
56 memcpy(&dst_addr, hep->h_addr, sizeof(dst_addr));
59 s = socket(AF_INET, SOCK_DGRAM, 0);
61 perror("socket open");
66 printf("no interface for address\n");
69 printf("Intf-name:%s\n", ifr->ifr_name);
70 sip = (struct sockaddr_in *) &(ifr->ifr_addr);
71 printf("Intf-addr:%s\n", inet_ntoa(sip->sin_addr));