Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
Re: traceroute: get rid of inet_aton
To:
tech <tech@openbsd.org>
Date:
Wed, 21 Aug 2024 22:06:42 +0200

Download raw body.

Thread
On Wed, Aug 21, 2024 at 01:41:48PM +0200, Florian Obser wrote:
> OK?

OK bluhm@

> diff --git traceroute.c traceroute.c
> index 90b37cbe65a..54a8ae568ac 100644
> --- traceroute.c
> +++ traceroute.c
> @@ -303,7 +303,6 @@ main(int argc, char *argv[])
>  	char	hbuf[NI_MAXHOST];
>  
>  	struct addrinfo		 hints, *res;
> -	struct hostent		*hp;
>  	struct ip		*ip = NULL;
>  	struct iovec		 rcviov[2];
>  	static u_char		*rcvcmsgbuf;
> @@ -449,14 +448,16 @@ main(int argc, char *argv[])
>  		case 'g':
>  			if (conf->lsrr >= MAX_LSRR)
>  				errx(1, "too many gateways; max %d", MAX_LSRR);
> -			if (inet_aton(optarg, &conf->gateway[conf->lsrr]) ==
> -			    0) {
> -				hp = gethostbyname(optarg);
> -				if (hp == 0)
> -					errx(1, "unknown host %s", optarg);
> -				memcpy(&conf->gateway[conf->lsrr], hp->h_addr,
> -				    hp->h_length);
> -			}
> +			memset(&hints, 0, sizeof(hints));
> +			hints.ai_family = AF_INET;
> +
> +			if (getaddrinfo(optarg, NULL, &hints, &res) != 0)
> +				errx(1, "unknown host %s", optarg);
> +
> +			conf->gateway[conf->lsrr] =
> +			    ((struct sockaddr_in *)res->ai_addr)->sin_addr;
> +			freeaddrinfo(res);
> +
>  			if (++conf->lsrr == 1)
>  				conf->lsrrlen = 4;
>  			conf->lsrrlen += 4;
> @@ -713,7 +714,8 @@ main(int argc, char *argv[])
>  		if (conf->source) {
>  			memset(&from4, 0, sizeof(from4));
>  			from4.sin_family = AF_INET;
> -			if (inet_aton(conf->source, &from4.sin_addr) == 0)
> +			if (inet_pton(AF_INET, conf->source, &from4.sin_addr)
> +			    != 1)
>  				errx(1, "unknown host %s", conf->source);
>  			ip->ip_src = from4.sin_addr;
>  			if (ouid != 0 &&
> 
> -- 
> In my defence, I have been left unsupervised.