Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
Re: mount_nfs(8): get rid of inet_aton.
To:
tech <tech@openbsd.org>
Date:
Sun, 18 Aug 2024 22:51:05 +0200

Download raw body.

Thread
On Sun, Aug 18, 2024 at 03:10:32PM +0200, Florian Obser wrote:
> I doubt anyone needs inet_aton's flexibility^W impreciseness.
> 
> OK?

OK bluhm@

> diff --git mount_nfs.c mount_nfs.c
> index 1c2ecf8fbaa..0724936f0b3 100644
> --- mount_nfs.c
> +++ mount_nfs.c
> @@ -383,7 +383,7 @@ int
>  getnfsargs(char *spec, struct nfs_args *nfsargsp)
>  {
>  	CLIENT *clp;
> -	struct hostent *hp;
> +	struct addrinfo hints, *res;
>  	static struct sockaddr_in saddr;
>  	struct timeval pertry, try;
>  	enum clnt_stat clnt_stat;
> @@ -411,14 +411,15 @@ getnfsargs(char *spec, struct nfs_args *nfsargsp)
>  	/*
>  	 * Handle an internet host address
>  	 */
> -	if (inet_aton(hostp, &saddr.sin_addr) == 0) {
> -		hp = gethostbyname(hostp);
> -		if (hp == NULL) {
> -			warnx("can't resolve address for host %s", hostp);
> -			return (0);
> -		}
> -		memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length);
> +	memset(&hints, 0, sizeof(hints));
> +	hints.ai_family = AF_INET;
> +
> +	if (getaddrinfo(hostp, NULL, &hints, &res) != 0) {
> +		warnx("can't resolve address for host %s", hostp);
> +		return (0);
>  	}
> +	saddr.sin_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr;
> +	freeaddrinfo(res);
>  
>  	if (force2) {
>  		nfsvers = NFS_VER2;
> 
> -- 
> In my defence, I have been left unsupervised.