freebsd-dev/libexec/bootpd/trygetif.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.3 KiB
C
Raw Normal View History

1994-09-30 05:45:07 +00:00
/*
* trygetif.c - test program for getif.c
1996-09-22 21:56:57 +00:00
*
1999-08-28 00:22:10 +00:00
* $FreeBSD$
1994-09-30 05:45:07 +00:00
*/
#include <sys/types.h>
#include <sys/socket.h>
#if defined(SUNOS) || defined(SVR4)
#include <sys/sockio.h>
#endif
1996-01-23 01:35:04 +00:00
#ifdef _AIX32
#include <sys/time.h> /* for struct timeval in net/if.h */
#endif
1994-09-30 05:45:07 +00:00
#include <net/if.h> /* for struct ifreq */
#include <netinet/in.h>
#include <arpa/inet.h> /* inet_ntoa */
#include <netdb.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "getif.h"
int debug = 0;
char *progname;
1996-01-23 01:35:04 +00:00
void
1994-09-30 05:45:07 +00:00
main(argc, argv)
1996-01-23 01:35:04 +00:00
int argc;
1994-09-30 05:45:07 +00:00
char **argv;
{
struct hostent *hep;
struct sockaddr_in *sip; /* Interface address */
struct ifreq *ifr;
struct in_addr dst_addr;
struct in_addr *dap;
1996-01-23 01:35:04 +00:00
int s;
1994-09-30 05:45:07 +00:00
progname = argv[0]; /* for report */
dap = NULL;
if (argc > 1) {
dap = &dst_addr;
1996-01-23 01:35:04 +00:00
if (isdigit(argv[1][0]))
dst_addr.s_addr = inet_addr(argv[1]);
else {
1994-09-30 05:45:07 +00:00
hep = gethostbyname(argv[1]);
if (!hep) {
printf("gethostbyname(%s)\n", argv[1]);
exit(1);
}
memcpy(&dst_addr, hep->h_addr, sizeof(dst_addr));
}
}
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
perror("socket open");
exit(1);
}
ifr = getif(s, dap);
if (!ifr) {
printf("no interface for address\n");
exit(1);
}
printf("Intf-name:%s\n", ifr->ifr_name);
sip = (struct sockaddr_in *) &(ifr->ifr_addr);
printf("Intf-addr:%s\n", inet_ntoa(sip->sin_addr));
exit(0);
}