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>
17 # include <net/route.h>
19 #include <netinet/in.h>
20 #include <netinet/if_ether.h>
21 #include <arpa/inet.h>
22 #include <netinet/in.h>
23 #include <netinet/in_systm.h>
24 #include <netinet/ip.h>
25 #include <netinet/ip_var.h>
26 #include <netinet/tcp.h>
35 #include "iplang/iplang.h"
39 * lookup host and return
40 * its IP address in address
43 int resolve(host, address)
49 add = inet_addr(host);
52 if (!(hp = gethostbyname(host)))
54 fprintf(stderr, "unknown host: %s\n", host);
57 bcopy((char *)hp->h_addr, (char *)address, 4);
60 bcopy((char*)&add, address, 4);
70 char *lim, *buf, *next;
71 struct rt_msghdr *rtm;
72 struct sockaddr_in *sin;
73 struct sockaddr_dl *sdl;
76 if (arp_getipv4(addr, ether) == 0)
87 mib[4] = NET_RT_FLAGS;
94 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
96 perror("route-sysctl-estimate");
99 if ((buf = malloc(needed)) == NULL)
104 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
106 perror("actual retrieval of routing table");
110 for (next = buf; next < lim; next += rtm->rtm_msglen)
112 rtm = (struct rt_msghdr *)next;
113 sin = (struct sockaddr_in *)(rtm + 1);
114 sdl = (struct sockaddr_dl *)(sin + 1);
115 if (!bcmp(addr, (char *)&sin->sin_addr,
116 sizeof(struct in_addr)))
118 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);