4 * Based upon 4.4BSD's /usr/sbin/arp
8 #include <sys/socket.h>
9 #include <sys/sysctl.h>
11 #if __FreeBSD_version >= 300000
12 # include <net/if_var.h>
14 #include <net/if_dl.h>
15 #include <net/if_types.h>
16 #if defined(__FreeBSD__)
17 # include "radix_ipf.h"
20 # include <net/route.h>
22 #include <netinet/in.h>
23 #include <netinet/if_ether.h>
24 #include <arpa/inet.h>
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
27 #include <netinet/ip.h>
28 #include <netinet/ip_var.h>
29 #include <netinet/tcp.h>
38 #include "iplang/iplang.h"
42 * lookup host and return
43 * its IP address in address
46 int resolve(host, address)
52 add = inet_addr(host);
55 if (!(hp = gethostbyname(host)))
57 fprintf(stderr, "unknown host: %s\n", host);
60 bcopy((char *)hp->h_addr, (char *)address, 4);
63 bcopy((char*)&add, address, 4);
73 char *lim, *buf, *next;
74 struct rt_msghdr *rtm;
75 struct sockaddr_inarp *sin;
76 struct sockaddr_dl *sdl;
79 if (arp_getipv4(addr, ether) == 0)
90 mib[4] = NET_RT_FLAGS;
97 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
99 perror("route-sysctl-estimate");
102 if ((buf = malloc(needed)) == NULL)
107 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
109 perror("actual retrieval of routing table");
113 for (next = buf; next < lim; next += rtm->rtm_msglen)
115 rtm = (struct rt_msghdr *)next;
116 sin = (struct sockaddr_inarp *)(rtm + 1);
117 sdl = (struct sockaddr_dl *)(sin + 1);
118 if (!bcmp(addr, (char *)&sin->sin_addr,
119 sizeof(struct in_addr)))
121 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);