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: arp.c,v 2.8.2.2 2007/02/17 12:41:50 darrenr Exp";
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 "radix_ipf_local.h"
24 #include <netinet/if_ether.h>
26 # include <net/if_arp.h>
28 #include <netinet/in.h>
29 #include <netinet/ip.h>
30 #include <netinet/ip_var.h>
31 #include <netinet/tcp.h>
36 #include "iplang/iplang.h"
40 * lookup host and return
41 * its IP address in address
44 int resolve(host
, address
)
50 add
= inet_addr(host
);
53 if (!(hp
= gethostbyname(host
)))
55 fprintf(stderr
, "unknown host: %s\n", host
);
58 bcopy((char *)hp
->h_addr
, (char *)address
, 4);
61 bcopy((char*)&add
, address
, 4);
66 * ARP for the MAC address corresponding
67 * to the IP address. This taken from
68 * some BSD program, I cant remember which.
75 static char ethersave
[6], ipsave
[4];
77 struct sockaddr_in
*sin
, san
;
82 if (arp_getipv4(ip
, ether
) == 0)
85 if (!bcmp(ipsave
, ip
, 4)) {
86 bcopy(ethersave
, ether
, 6);
90 bzero((char *)&ar
, sizeof(ar
));
91 sin
= (struct sockaddr_in
*)&ar
.arp_pa
;
92 sin
->sin_family
= AF_INET
;
93 bcopy(ip
, (char *)&sin
->sin_addr
.s_addr
, 4);
95 if ((hp
= gethostbyaddr(ip
, 4, AF_INET
)))
96 # if SOLARIS && (SOLARIS2 >= 10)
97 if (!(ether_hostton(hp
->h_name
, (struct ether_addr
*)ether
)))
99 if (!(ether_hostton(hp
->h_name
, ether
)))
105 if ((sfd
= socket(AF_INET
, SOCK_DGRAM
, 0)) == -1)
107 perror("arp: socket");
111 if (ioctl(sfd
, SIOCGARP
, (caddr_t
)&ar
) == -1)
115 bzero((char *)&san
, sizeof(san
));
116 san
.sin_family
= AF_INET
;
117 san
.sin_port
= htons(1);
118 bcopy(ip
, &san
.sin_addr
.s_addr
, 4);
119 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
120 (void) sendto(fd
, ip
, 4, 0,
121 (struct sockaddr
*)&san
, sizeof(san
));
126 fprintf(stderr
, "(%s):", inet_ntoa(sin
->sin_addr
));
132 if ((ar
.arp_ha
.sa_data
[0] == 0) && (ar
.arp_ha
.sa_data
[1] == 0) &&
133 (ar
.arp_ha
.sa_data
[2] == 0) && (ar
.arp_ha
.sa_data
[3] == 0) &&
134 (ar
.arp_ha
.sa_data
[4] == 0) && (ar
.arp_ha
.sa_data
[5] == 0)) {
135 fprintf(stderr
, "(%s):", inet_ntoa(sin
->sin_addr
));
139 bcopy(ar
.arp_ha
.sa_data
, ether
, 6);
141 bcopy(ether
, ethersave
, 6);
142 bcopy(ip
, ipsave
, 4);