Page MenuHomeFreeBSD

D45903.diff
No OneTemporary

D45903.diff

diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c
--- a/usr.sbin/rarpd/rarpd.c
+++ b/usr.sbin/rarpd/rarpd.c
@@ -98,7 +98,7 @@
static struct pidfh *pidfile_fh;
static int bpf_open(void);
-static in_addr_t choose_ipaddr(in_addr_t **, in_addr_t, in_addr_t);
+static in_addr_t choose_ipaddr(struct addrinfo *, in_addr_t, in_addr_t);
static char *eatoa(u_char *);
static int expand_syslog_m(const char *fmt, char **newfmt);
static void init(char *);
@@ -622,12 +622,16 @@
* of the address.
*/
static in_addr_t
-choose_ipaddr(in_addr_t **alist, in_addr_t net, in_addr_t netmask)
+choose_ipaddr(struct addrinfo *alist, in_addr_t net, in_addr_t netmask)
{
+ for (; alist != NULL; alist = alist->ai_next) {
+ if (alist->ai_family == AF_INET) {
+ in_addr_t ip_addr = ((struct sockaddr_in *)alist->ai_addr)->sin_addr.s_addr;
+ if ((ip_addr & netmask) == net)
+ return ip_addr;
+ }
+ }
- for (; *alist; ++alist)
- if ((**alist & netmask) == net)
- return **alist;
return 0;
}
@@ -639,7 +643,7 @@
rarp_process(struct if_info *ii, u_char *pkt, u_int len)
{
struct ether_header *ep;
- struct hostent *hp;
+ struct addrinfo *res;
in_addr_t target_ipaddr;
char ename[256];
@@ -651,22 +655,16 @@
return;
}
- if ((hp = gethostbyname(ename)) == NULL) {
+ if (getaddrinfo(ename, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res) != 0) {
logmsg(LOG_ERR, "cannot map %s to IP address", ename);
return;
}
-
- /*
- * Choose correct address from list.
- */
- if (hp->h_addrtype != AF_INET) {
- logmsg(LOG_ERR, "cannot handle non IP addresses for %s",
- ename);
- return;
- }
- target_ipaddr = choose_ipaddr((in_addr_t **)hp->h_addr_list,
+ target_ipaddr = choose_ipaddr(res,
ii->ii_ipaddr & ii->ii_netmask,
ii->ii_netmask);
+ freeaddrinfo(res);
if (target_ipaddr == 0) {
logmsg(LOG_ERR, "cannot find %s on net %s",
ename, intoa(ntohl(ii->ii_ipaddr & ii->ii_netmask)));

File Metadata

Mime Type
text/plain
Expires
Sun, Jan 18, 2:10 PM (10 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27710362
Default Alt Text
D45903.diff (1 KB)

Event Timeline