4 * larp.c (C) 1995-1998 Darren Reed
6 * See the IPFILTER.LICENCE file for details on licencing.
10 static const char sccsid
[] = "@(#)larp.c 1.1 8/19/95 (C)1995 Darren Reed";
11 static const char rcsid
[] = "@(#)Id: larp.c,v 2.4 2003/12/01 02:01:16 darrenr Exp";
13 #include <sys/param.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <sys/ioctl.h>
17 #include <netinet/in.h>
19 #include <net/if_arp.h>
24 #include "ip_compat.h"
25 #include "iplang/iplang.h"
28 * lookup host and return
29 * its IP address in address
32 int resolve(host
, address
)
38 add
= inet_addr(host
);
41 if (!(hp
= gethostbyname(host
)))
43 fprintf(stderr
, "unknown host: %s\n", host
);
46 bcopy((char *)hp
->h_addr
, (char *)address
, 4);
49 bcopy((char*)&add
, address
, 4);
54 * ARP for the MAC address corresponding
55 * to the IP address. This taken from
56 * some BSD program, I cant remember which.
64 struct sockaddr_in
*sin
;
68 if (arp_getipv4(ip
, ether
) == 0)
71 bzero((char *)&ar
, sizeof(ar
));
72 sin
= (struct sockaddr_in
*)&ar
.arp_pa
;
73 sin
->sin_family
= AF_INET
;
74 bcopy(ip
, (char *)&sin
->sin_addr
.s_addr
, 4);
77 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) == -1)
79 perror("arp: socket");
83 if (ioctl(s
, SIOCGARP
, (caddr_t
)&ar
) == -1)
85 fprintf(stderr
, "(%s):", inet_ntoa(sin
->sin_addr
));
91 bcopy(ar
.arp_ha
.sa_data
, ether
, 6);