Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / ipf / ipsend / larp.c
bloba8e782e6bf7bfc40ce7bd15b852d77b680a55a87
1 /* $NetBSD$ */
3 /*
4 * larp.c (C) 1995-1998 Darren Reed
6 * See the IPFILTER.LICENCE file for details on licencing.
8 */
9 #if !defined(lint)
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";
12 #endif
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>
18 #include <net/if.h>
19 #include <net/if_arp.h>
20 #include <stdio.h>
21 #include <netdb.h>
22 #include <errno.h>
24 #include "ip_compat.h"
25 #include "iplang/iplang.h"
28 * lookup host and return
29 * its IP address in address
30 * (4 bytes)
32 int resolve(host, address)
33 char *host, *address;
35 struct hostent *hp;
36 u_long add;
38 add = inet_addr(host);
39 if (add == -1)
41 if (!(hp = gethostbyname(host)))
43 fprintf(stderr, "unknown host: %s\n", host);
44 return -1;
46 bcopy((char *)hp->h_addr, (char *)address, 4);
47 return 0;
49 bcopy((char*)&add, address, 4);
50 return 0;
54 * ARP for the MAC address corresponding
55 * to the IP address. This taken from
56 * some BSD program, I cant remember which.
58 int arp(ip, ether)
59 char *ip;
60 char *ether;
62 static int s = -1;
63 struct arpreq ar;
64 struct sockaddr_in *sin;
65 char *inet_ntoa();
67 #ifdef IP_SEND
68 if (arp_getipv4(ip, ether) == 0)
69 return 0;
70 #endif
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);
76 if (s == -1)
77 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
79 perror("arp: socket");
80 return -1;
83 if (ioctl(s, SIOCGARP, (caddr_t)&ar) == -1)
85 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
86 if (errno != ENXIO)
87 perror("SIOCGARP");
88 return -1;
91 bcopy(ar.arp_ha.sa_data, ether, 6);
92 return 0;