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"
19 #include <net/route.h>
20 #include <netinet/in.h>
21 #include <netinet/if_ether.h>
22 #include <arpa/inet.h>
23 #include <netinet/in.h>
24 #include <netinet/in_systm.h>
25 #include <netinet/ip.h>
26 #include <netinet/ip_var.h>
27 #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);
71 char *lim, *buf, *next;
72 struct rt_msghdr *rtm;
73 struct sockaddr_inarp *sin;
74 struct sockaddr_dl *sdl;
77 if (arp_getipv4(addr, ether) == 0)
88 mib[4] = NET_RT_FLAGS;
90 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
92 perror("route-sysctl-estimate");
95 if ((buf = malloc(needed)) == NULL)
100 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
102 perror("actual retrieval of routing table");
106 for (next = buf; next < lim; next += rtm->rtm_msglen)
108 rtm = (struct rt_msghdr *)next;
109 sin = (struct sockaddr_inarp *)(rtm + 1);
110 sdl = (struct sockaddr_dl *)(sin + 1);
111 if (!bcmp(addr, (char *)&sin->sin_addr,
112 sizeof(struct in_addr)))
114 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);