2 * arp.c (C) 1995-1998 Darren Reed
4 * See the IPFILTER.LICENCE file for details on licencing.
7 static const char sccsid[] = "@(#)arp.c 1.4 1/11/96 (C)1995 Darren Reed";
8 static const char rcsid[] = "@(#)$Id: arp.c,v 2.8.2.2 2007/02/17 12:41:50 darrenr Exp $";
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #if !defined(ultrix) && !defined(hpux) && !defined(__hpux) && !defined(__osf__) && !defined(_AIX51)
13 # include <sys/sockio.h>
15 #include <sys/ioctl.h>
16 #include <netinet/in_systm.h>
17 #include <netinet/in.h>
19 # include "radix_ipf_local.h"
22 #include <netinet/if_ether.h>
24 # include <net/if_arp.h>
26 #include <netinet/in.h>
27 #include <netinet/ip.h>
28 #include <netinet/ip_var.h>
29 #include <netinet/tcp.h>
34 #include "iplang/iplang.h"
38 * lookup host and return
39 * its IP address in address
42 int resolve(host, address)
48 add = inet_addr(host);
51 if (!(hp = gethostbyname(host)))
53 fprintf(stderr, "unknown host: %s\n", host);
56 bcopy((char *)hp->h_addr, (char *)address, 4);
59 bcopy((char*)&add, address, 4);
64 * ARP for the MAC address corresponding
65 * to the IP address. This taken from
66 * some BSD program, I cant remember which.
73 static char ethersave[6], ipsave[4];
75 struct sockaddr_in *sin, san;
80 if (arp_getipv4(ip, ether) == 0)
83 if (!bcmp(ipsave, ip, 4)) {
84 bcopy(ethersave, ether, 6);
88 bzero((char *)&ar, sizeof(ar));
89 sin = (struct sockaddr_in *)&ar.arp_pa;
90 sin->sin_family = AF_INET;
91 bcopy(ip, (char *)&sin->sin_addr.s_addr, 4);
93 if ((hp = gethostbyaddr(ip, 4, AF_INET)))
94 # if SOLARIS && (SOLARIS2 >= 10)
95 if (!(ether_hostton(hp->h_name, (struct ether_addr *)ether)))
97 if (!(ether_hostton(hp->h_name, ether)))
103 if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
105 perror("arp: socket");
109 if (ioctl(sfd, SIOCGARP, (caddr_t)&ar) == -1)
113 bzero((char *)&san, sizeof(san));
114 san.sin_family = AF_INET;
115 san.sin_port = htons(1);
116 bcopy(ip, &san.sin_addr.s_addr, 4);
117 fd = socket(AF_INET, SOCK_DGRAM, 0);
118 (void) sendto(fd, ip, 4, 0,
119 (struct sockaddr *)&san, sizeof(san));
124 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
130 if ((ar.arp_ha.sa_data[0] == 0) && (ar.arp_ha.sa_data[1] == 0) &&
131 (ar.arp_ha.sa_data[2] == 0) && (ar.arp_ha.sa_data[3] == 0) &&
132 (ar.arp_ha.sa_data[4] == 0) && (ar.arp_ha.sa_data[5] == 0)) {
133 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
137 bcopy(ar.arp_ha.sa_data, ether, 6);
139 bcopy(ether, ethersave, 6);
140 bcopy(ip, ipsave, 4);