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(char *host, char *address)
42 add = inet_addr(host);
45 if (!(hp = gethostbyname(host)))
47 fprintf(stderr, "unknown host: %s\n", host);
50 bcopy((char *)hp->h_addr, (char *)address, 4);
53 bcopy((char*)&add, address, 4);
58 * ARP for the MAC address corresponding
59 * to the IP address. This taken from
60 * some BSD program, I cant remember which.
67 static char ethersave[6], ipsave[4];
69 struct sockaddr_in *sin, san;
74 if (arp_getipv4(ip, ether) == 0)
77 if (!bcmp(ipsave, ip, 4)) {
78 bcopy(ethersave, ether, 6);
82 bzero((char *)&ar, sizeof(ar));
83 sin = (struct sockaddr_in *)&ar.arp_pa;
84 sin->sin_family = AF_INET;
85 bcopy(ip, (char *)&sin->sin_addr.s_addr, 4);
86 if ((hp = gethostbyaddr(ip, 4, AF_INET)))
87 # if SOLARIS && (SOLARIS2 >= 10)
88 if (!(ether_hostton(hp->h_name, (struct ether_addr *)ether)))
90 if (!(ether_hostton(hp->h_name, ether)))
95 if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
97 perror("arp: socket");
101 if (ioctl(sfd, SIOCGARP, (caddr_t)&ar) == -1)
105 bzero((char *)&san, sizeof(san));
106 san.sin_family = AF_INET;
107 san.sin_port = htons(1);
108 bcopy(ip, &san.sin_addr.s_addr, 4);
109 fd = socket(AF_INET, SOCK_DGRAM, 0);
110 (void) sendto(fd, ip, 4, 0,
111 (struct sockaddr *)&san, sizeof(san));
116 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
122 if ((ar.arp_ha.sa_data[0] == 0) && (ar.arp_ha.sa_data[1] == 0) &&
123 (ar.arp_ha.sa_data[2] == 0) && (ar.arp_ha.sa_data[3] == 0) &&
124 (ar.arp_ha.sa_data[4] == 0) && (ar.arp_ha.sa_data[5] == 0)) {
125 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
129 bcopy(ar.arp_ha.sa_data, ether, 6);
131 bcopy(ether, ethersave, 6);
132 bcopy(ip, ipsave, 4);