Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / bootp / common / trygetif.c
blob56b0bbd61376097e5ba45b613751a67dc164f2f2
1 /* $NetBSD: trygetif.c,v 1.5 2002/07/14 00:26:18 wiz Exp $ */
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: trygetif.c,v 1.5 2002/07/14 00:26:18 wiz Exp $");
6 #endif
8 /*
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>
17 #endif
19 #include <net/if.h> /* for struct ifreq */
20 #include <netinet/in.h>
21 #include <arpa/inet.h> /* inet_ntoa */
23 #include <netdb.h>
24 #include <stdio.h>
25 #include <errno.h>
27 #include "getif.h"
29 int
30 main(int argc, char **argv)
32 struct hostent *hep;
33 struct sockaddr ea; /* Ethernet address */
34 struct sockaddr_in *sip; /* Interface address */
35 struct ifreq *ifr;
36 struct in_addr dst_addr;
37 struct in_addr *dap;
38 int i, s;
40 dap = NULL;
41 if (argc > 1) {
42 dap = &dst_addr;
43 if (inet_aton(argv[1], &dst_addr) == 0) {
44 hep = gethostbyname(argv[1]);
45 if (!hep) {
46 fprintf(stderr, "gethostbyname(%s)\n", argv[1]);
47 exit(1);
49 memcpy(&dst_addr, hep->h_addr, sizeof(dst_addr));
52 s = socket(AF_INET, SOCK_DGRAM, 0);
53 if (s < 0) {
54 perror("socket open");
55 exit(1);
57 ifr = getif(s, dap);
58 if (!ifr) {
59 fprintf(stderr, "no interface for address\n");
60 exit(1);
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));
66 return 0;