- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / contrib / ipfilter / ipsend / larp.c
blobd178d644895c0ea5325653b03452bfe377f2266e
1 /*
2 * larp.c (C) 1995-1998 Darren Reed
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6 #if !defined(lint)
7 static const char sccsid[] = "@(#)larp.c 1.1 8/19/95 (C)1995 Darren Reed";
8 static const char rcsid[] = "@(#)$Id: larp.c,v 2.1.4.1 2001/06/26 10:43:22 darrenr Exp $";
9 #endif
10 #include <stdio.h>
11 #include <errno.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <sys/ioctl.h>
15 #include <netdb.h>
16 #include <netinet/in.h>
17 #include <net/if.h>
18 #include <net/if_arp.h>
20 #include "ip_compat.h"
21 #include "iplang/iplang.h"
24 * lookup host and return
25 * its IP address in address
26 * (4 bytes)
28 int resolve(host, address)
29 char *host, *address;
31 struct hostent *hp;
32 u_long add;
34 add = inet_addr(host);
35 if (add == -1)
37 if (!(hp = gethostbyname(host)))
39 fprintf(stderr, "unknown host: %s\n", host);
40 return -1;
42 bcopy((char *)hp->h_addr, (char *)address, 4);
43 return 0;
45 bcopy((char*)&add, address, 4);
46 return 0;
50 * ARP for the MAC address corresponding
51 * to the IP address. This taken from
52 * some BSD program, I cant remember which.
54 int arp(ip, ether)
55 char *ip;
56 char *ether;
58 static int s = -1;
59 struct arpreq ar;
60 struct sockaddr_in *sin;
61 char *inet_ntoa();
63 #ifdef IP_SEND
64 if (arp_getipv4(ip, ether) == 0)
65 return 0;
66 #endif
67 bzero((char *)&ar, sizeof(ar));
68 sin = (struct sockaddr_in *)&ar.arp_pa;
69 sin->sin_family = AF_INET;
70 bcopy(ip, (char *)&sin->sin_addr.s_addr, 4);
72 if (s == -1)
73 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
75 perror("arp: socket");
76 return -1;
79 if (ioctl(s, SIOCGARP, (caddr_t)&ar) == -1)
81 fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr));
82 if (errno != ENXIO)
83 perror("SIOCGARP");
84 return -1;
87 bcopy(ar.arp_ha.sa_data, ether, 6);
88 return 0;