2 * trygetif.c - test program for getif.c
4 * $FreeBSD: src/libexec/bootpd/trygetif.c,v 1.5 1999/08/28 00:09:20 peter Exp $
5 * $DragonFly: src/libexec/bootpd/trygetif.c,v 1.2 2003/06/17 04:27:07 dillon Exp $
9 #include <sys/socket.h>
11 #if defined(SUNOS) || defined(SVR4)
12 #include <sys/sockio.h>
16 #include <sys/time.h> /* for struct timeval in net/if.h */
18 #include <net/if.h> /* for struct ifreq */
19 #include <netinet/in.h>
20 #include <arpa/inet.h> /* inet_ntoa */
38 struct sockaddr_in
*sip
; /* Interface address */
40 struct in_addr dst_addr
;
44 progname
= argv
[0]; /* for report */
49 if (isdigit(argv
[1][0]))
50 dst_addr
.s_addr
= inet_addr(argv
[1]);
52 hep
= gethostbyname(argv
[1]);
54 printf("gethostbyname(%s)\n", argv
[1]);
57 memcpy(&dst_addr
, hep
->h_addr
, sizeof(dst_addr
));
60 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
62 perror("socket open");
67 printf("no interface for address\n");
70 printf("Intf-name:%s\n", ifr
->ifr_name
);
71 sip
= (struct sockaddr_in
*) &(ifr
->ifr_addr
);
72 printf("Intf-addr:%s\n", inet_ntoa(sip
->sin_addr
));