4 * Based upon 4.4BSD's /usr/sbin/arp
8 #include <sys/socket.h>
9 #include <sys/sysctl.h>
11 #include <net/if_dl.h>
12 #include <net/if_types.h>
14 # include <net/route.h>
16 #include <netinet/in.h>
17 #include <netinet/if_ether.h>
18 #include <arpa/inet.h>
19 #include <netinet/in.h>
20 #include <netinet/in_systm.h>
21 #include <netinet/ip.h>
22 #include <netinet/ip_var.h>
23 #include <netinet/tcp.h>
32 #include "iplang/iplang.h"
36 * lookup host and return
37 * its IP address in address
40 int resolve(host, address)
46 add = inet_addr(host);
49 if (!(hp = gethostbyname(host)))
51 fprintf(stderr, "unknown host: %s\n", host);
54 bcopy((char *)hp->h_addr, (char *)address, 4);
57 bcopy((char*)&add, address, 4);
67 char *lim, *buf, *next;
68 struct rt_msghdr *rtm;
69 struct sockaddr_in *sin;
70 struct sockaddr_dl *sdl;
73 if (arp_getipv4(addr, ether) == 0)
84 mib[4] = NET_RT_FLAGS;
91 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
93 perror("route-sysctl-estimate");
96 if ((buf = malloc(needed)) == NULL)
101 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
103 perror("actual retrieval of routing table");
107 for (next = buf; next < lim; next += rtm->rtm_msglen)
109 rtm = (struct rt_msghdr *)next;
110 sin = (struct sockaddr_in *)(rtm + 1);
111 sdl = (struct sockaddr_dl *)(sin + 1);
112 if (!bcmp(addr, (char *)&sin->sin_addr,
113 sizeof(struct in_addr)))
115 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);