4 * arp.c (C) 1995-1998 Darren Reed
6 * See the IPFILTER.LICENCE file for details on licencing.
9 static const char sccsid[] = "@(#)arp.c 1.4 1/11/96 (C)1995 Darren Reed";
10 static const char rcsid[] = "@(#)$Id$";
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #if !defined(ultrix) && !defined(hpux) && !defined(__hpux) && !defined(__osf__) && !defined(_AIX51)
15 # include <sys/sockio.h>
17 #include <sys/ioctl.h>
18 #include <netinet/in_systm.h>
19 #include <netinet/in.h>
21 #include <netinet/if_ether.h>
23 # include <net/if_arp.h>
25 #include <netinet/in.h>
26 #include <netinet/ip.h>
27 #include <netinet/ip_var.h>
28 #include <netinet/tcp.h>
33 #include "iplang/iplang.h"
37 * lookup host and return
38 * its IP address in address
41 int resolve(host, address)
47 add = inet_addr(host);
50 if (!(hp = gethostbyname(host)))
52 fprintf(stderr, "unknown host: %s\n", host);
55 bcopy((char *)hp->h_addr, (char *)address, 4);
58 bcopy((char*)&add, address, 4);
63 * ARP for the MAC address corresponding
64 * to the IP address. This taken from
65 * some BSD program, I cant remember which.
72 static char ethersave[6], ipsave[4];
74 struct sockaddr_in *sin, san;
79 if (arp_getipv4(ip, ether) == 0)
82 if (!bcmp(ipsave, ip, 4)) {
83 bcopy(ethersave, ether, 6);
87 bzero((char *)&ar, sizeof(ar));
88 sin = (struct sockaddr_in *)&ar.arp_pa;
89 sin->sin_family = AF_INET;
90 bcopy(ip, (char *)&sin->sin_addr.s_addr, 4);
92 if ((hp = gethostbyaddr(ip, 4, AF_INET)))
93 # if SOLARIS && (SOLARIS2 >= 10)
94 if (!(ether_hostton(hp->h_name, (struct ether_addr *)ether)))
96 if (!(ether_hostton(hp->h_name, ether)))
102 if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
104 perror("arp: socket");
108 if (ioctl(sfd, SIOCGARP, (caddr_t)&ar) == -1)
112 bzero((char *)&san, sizeof(san));
113 san.sin_family = AF_INET;
114 san.sin_port = htons(1);
115 bcopy(ip, &san.sin_addr.s_addr, 4);
116 fd = socket(AF_INET, SOCK_DGRAM, 0);
117 (void) sendto(fd, ip, 4, 0,
118 (struct sockaddr *)&san, sizeof(san));
123 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
129 if ((ar.arp_ha.sa_data[0] == 0) && (ar.arp_ha.sa_data[1] == 0) &&
130 (ar.arp_ha.sa_data[2] == 0) && (ar.arp_ha.sa_data[3] == 0) &&
131 (ar.arp_ha.sa_data[4] == 0) && (ar.arp_ha.sa_data[5] == 0)) {
132 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
136 bcopy(ar.arp_ha.sa_data, ether, 6);
138 bcopy(ether, ethersave, 6);
139 bcopy(ip, ipsave, 4);