2 * Based upon 4.4BSD's /usr/sbin/arp
4 #if defined(__sgi) && (IRIX > 602)
5 # include <sys/ptimers.h>
10 #include <sys/param.h>
12 #include <sys/socket.h>
13 #include <sys/sysctl.h>
15 #include <net/if_dl.h>
16 #include <net/if_types.h>
17 #include <net/route.h>
18 #include <netinet/in.h>
19 #include <netinet/if_ether.h>
20 #include <arpa/inet.h>
25 #include <netinet/in.h>
26 #include <netinet/ip_var.h>
27 #include <netinet/tcp.h>
28 #if __FreeBSD_version >= 300000
29 # include <net/if_var.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_inarp *sin;
70 struct sockaddr_dl *sdl;
73 if (arp_getipv4(addr, ether) == 0)
81 mib[4] = NET_RT_FLAGS;
83 if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
85 perror("route-sysctl-estimate");
88 if ((buf = malloc(needed)) == NULL)
93 if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
95 perror("actual retrieval of routing table");
99 for (next = buf; next < lim; next += rtm->rtm_msglen)
101 rtm = (struct rt_msghdr *)next;
102 sin = (struct sockaddr_inarp *)(rtm + 1);
103 sdl = (struct sockaddr_dl *)(sin + 1);
104 if (addr && !bcmp(addr, (char *)&sin->sin_addr,
105 sizeof(struct in_addr)))
107 bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen);