From: Florian Obser Subject: rpc.bootparamd(8): Use getaddrinfo to lookup names and parse IP addresses. To: tech Date: Wed, 21 Aug 2024 13:33:25 +0200 Not a user of rpc.bootparamd(8), but it compiles and starts with either IP address or hostname provided for -r. Tests, OKs? diff --git bootparamd.c bootparamd.c index c58c4e9b897..0d848f57eea 100644 --- bootparamd.c +++ bootparamd.c @@ -66,7 +66,7 @@ usage(void) int main(int argc, char *argv[]) { - struct hostent *he; + struct addrinfo hints, *res; struct stat buf; SVCXPRT *transp; int c; @@ -77,15 +77,16 @@ main(int argc, char *argv[]) debug = 1; break; case 'r': - if (inet_aton(optarg, &route_addr) == 1) - break; - he = gethostbyname(optarg); - if (!he) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + + if (getaddrinfo(optarg, NULL, &hints, &res) != 0) { warnx("no such host: %s", optarg); usage(); } - bcopy(he->h_addr, &route_addr.s_addr, - sizeof(route_addr.s_addr)); + route_addr = + ((struct sockaddr_in *)res->ai_addr)->sin_addr; + freeaddrinfo(res); break; case 'f': bootpfile = optarg; -- In my defence, I have been left unsupervised.