1 /* $NetBSD: trygetif.c,v 1.5 2002/07/14 00:26:18 wiz Exp $ */
5 __RCSID("$NetBSD: trygetif.c,v 1.5 2002/07/14 00:26:18 wiz Exp $");
9 * trygetif.c - test program for getif.c
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #if defined(SUNOS) || defined(SVR4)
16 #include <sys/sockio.h>
19 #include <net/if.h> /* for struct ifreq */
20 #include <netinet/in.h>
21 #include <arpa/inet.h> /* inet_ntoa */
30 main(int argc
, char **argv
)
33 struct sockaddr ea
; /* Ethernet address */
34 struct sockaddr_in
*sip
; /* Interface address */
36 struct in_addr dst_addr
;
43 if (inet_aton(argv
[1], &dst_addr
) == 0) {
44 hep
= gethostbyname(argv
[1]);
46 fprintf(stderr
, "gethostbyname(%s)\n", argv
[1]);
49 memcpy(&dst_addr
, hep
->h_addr
, sizeof(dst_addr
));
52 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
54 perror("socket open");
59 fprintf(stderr
, "no interface for address\n");
62 printf("Intf-name:%s\n", ifr
->ifr_name
);
63 sip
= (struct sockaddr_in
*) &(ifr
->ifr_addr
);
64 printf("Intf-addr:%s\n", inet_ntoa(sip
->sin_addr
));