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>
13 # include <net/route.h>
14 #include <netinet/in.h>
15 #include <netinet/if_ether.h>
16 #include <arpa/inet.h>
17 #include <netinet/in.h>
18 #include <netinet/in_systm.h>
19 #include <netinet/ip.h>
20 #include <netinet/ip_var.h>
21 #include <netinet/tcp.h>
30 #include "iplang/iplang.h"
34 * lookup host and return
35 * its IP address in address
38 int resolve(host, address)
44 add = inet_addr(host);
47 if (!(hp = gethostbyname(host)))
49 fprintf(stderr, "unknown host: %s\n", host);
52 bcopy((char *)hp->h_addr, (char *)address, 4);
55 bcopy((char*)&add, address, 4);
65 char *lim, *buf, *next;
66 struct rt_msghdr *rtm;
67 struct sockaddr_in *sin;
68 struct sockaddr_dl *sdl;
71 if (arp_getipv4(addr, ether) == 0)
82 mib[4] = NET_RT_FLAGS;
89 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
91 perror("route-sysctl-estimate");
94 if ((buf = malloc(needed)) == NULL)
99 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
101 perror("actual retrieval of routing table");
105 for (next = buf; next < lim; next += rtm->rtm_msglen)
107 rtm = (struct rt_msghdr *)next;
108 sin = (struct sockaddr_in *)(rtm + 1);
109 sdl = (struct sockaddr_dl *)(sin + 1);
110 if (!bcmp(addr, (char *)&sin->sin_addr,
111 sizeof(struct in_addr)))
113 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);