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 # include <sys/sockio.h>
15 #include <sys/ioctl.h>
16 #include <netinet/in_systm.h>
17 #include <netinet/in.h>
19 #include <netinet/if_ether.h>
20 # include <net/if_arp.h>
21 #include <netinet/in.h>
22 #include <netinet/ip.h>
23 #include <netinet/ip_var.h>
24 #include <netinet/tcp.h>
29 #include "iplang/iplang.h"
33 * lookup host and return
34 * its IP address in address
37 int resolve(host, address)
43 add = inet_addr(host);
46 if (!(hp = gethostbyname(host)))
48 fprintf(stderr, "unknown host: %s\n", host);
51 bcopy((char *)hp->h_addr, (char *)address, 4);
54 bcopy((char*)&add, address, 4);
59 * ARP for the MAC address corresponding
60 * to the IP address. This taken from
61 * some BSD program, I cant remember which.
68 static char ethersave[6], ipsave[4];
70 struct sockaddr_in *sin, san;
75 if (arp_getipv4(ip, ether) == 0)
78 if (!bcmp(ipsave, ip, 4)) {
79 bcopy(ethersave, ether, 6);
83 bzero((char *)&ar, sizeof(ar));
84 sin = (struct sockaddr_in *)&ar.arp_pa;
85 sin->sin_family = AF_INET;
86 bcopy(ip, (char *)&sin->sin_addr.s_addr, 4);
87 if ((hp = gethostbyaddr(ip, 4, AF_INET)))
88 # if SOLARIS && (SOLARIS2 >= 10)
89 if (!(ether_hostton(hp->h_name, (struct ether_addr *)ether)))
91 if (!(ether_hostton(hp->h_name, ether)))
96 if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
98 perror("arp: socket");
102 if (ioctl(sfd, SIOCGARP, (caddr_t)&ar) == -1)
106 bzero((char *)&san, sizeof(san));
107 san.sin_family = AF_INET;
108 san.sin_port = htons(1);
109 bcopy(ip, &san.sin_addr.s_addr, 4);
110 fd = socket(AF_INET, SOCK_DGRAM, 0);
111 (void) sendto(fd, ip, 4, 0,
112 (struct sockaddr *)&san, sizeof(san));
117 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
123 if ((ar.arp_ha.sa_data[0] == 0) && (ar.arp_ha.sa_data[1] == 0) &&
124 (ar.arp_ha.sa_data[2] == 0) && (ar.arp_ha.sa_data[3] == 0) &&
125 (ar.arp_ha.sa_data[4] == 0) && (ar.arp_ha.sa_data[5] == 0)) {
126 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
130 bcopy(ar.arp_ha.sa_data, ether, 6);
132 bcopy(ether, ethersave, 6);
133 bcopy(ip, ipsave, 4);