From: florian Date: Wed, 21 Aug 2024 10:35:12 +0000 (+0000) Subject: Use getaddrinfo(3) to resolve hostnames / ip addresses. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ac6360cb3956be4f1fcfe441dcf0b72e2f0fd416;p=openbsd Use getaddrinfo(3) to resolve hostnames / ip addresses. OK dlg --- diff --git a/usr.sbin/dhcrelay/dhcrelay.c b/usr.sbin/dhcrelay/dhcrelay.c index ff5b355dfc6..b365dde42d4 100644 --- a/usr.sbin/dhcrelay/dhcrelay.c +++ b/usr.sbin/dhcrelay/dhcrelay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcrelay.c,v 1.66 2021/10/24 21:24:18 deraadt Exp $ */ +/* $OpenBSD: dhcrelay.c,v 1.67 2024/08/21 10:35:12 florian Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -162,12 +162,15 @@ main(int argc, char *argv[]) } while (argc > 0) { - struct hostent *he; + struct addrinfo hints, *res; struct in_addr ia, *iap = NULL; if ((sp = calloc(1, sizeof(*sp))) == NULL) fatalx("calloc"); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + if ((sp->intf = register_interface(argv[0], got_one, 1)) != NULL) { if (drm == DRM_LAYER3) @@ -185,15 +188,14 @@ main(int argc, char *argv[]) continue; } - if (inet_aton(argv[0], &ia)) - iap = &ia; + if (getaddrinfo(argv[0], NULL, &hints, &res) != 0) + log_warnx("%s: host unknown", argv[0]); else { - he = gethostbyname(argv[0]); - if (!he) - log_warnx("%s: host unknown", argv[0]); - else - iap = ((struct in_addr *)he->h_addr_list[0]); + ia = ((struct sockaddr_in *)res->ai_addr)->sin_addr; + iap = &ia; + freeaddrinfo(res); } + if (iap) { if (drm == DRM_LAYER2) fatalx("don't mix interfaces with hosts");