Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
Re: rpc.bootparamd(8): Use getaddrinfo to lookup names and parse IP addresses.
To:
tech <tech@openbsd.org>
Date:
Wed, 21 Aug 2024 21:57:42 +0200

Download raw body.

Thread
On Wed, Aug 21, 2024 at 01:33:25PM +0200, Florian Obser wrote:
> Not a user of rpc.bootparamd(8), but it compiles and starts with either IP
> address or hostname provided for -r.
> 
> Tests, OKs?

OK bluhm@

> 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.