From: Omar Polo Subject: Re: remove host, host_v4 and host_v6; rename host_dns -> host To: Stefan Sperling Cc: gameoftrees@openbsd.org Date: Mon, 29 May 2023 18:57:33 +0200 On 2023/05/29 18:49:42 +0200, Stefan Sperling wrote: > On Mon, May 29, 2023 at 06:35:02PM +0200, Omar Polo wrote: > > This is an attempt at simplifying how host() works. host() is used in > > the configuration file via get_addrs() to prepare a struct address > > after a "listen on" directive > > > > The current code first tries to resolve it as an ipv4 address via > > inet_pton(), then as an ipv6 address using getaddrinfo() with > > AI_NUMERICHOST, then as an interface name and finally as a name to > > resolve via getaddrinfo() again. > > > > Instead, scratch host(), host_v4() and host_v6() and rename host_dns() > > to host(). It preserve the lookup via interface name, and then uses > > getaddrinfo() only once wich already knows how to deal with IPv4/v6 > > literals and resolving addresses too. > > > > ok? > > Makes sense to me, ok. Thanks, committed. one small bonus: use AF_UNSPEC instead of PF_UNSPEC and use SOCK_STREAM instead of SOCK_DGRAM in the getaddrinfo call. ok? diff /home/op/w/gotacl commit - abf3e3f40c20ebf4efdce3c7e83efe11d0065ed0 path + /home/op/w/gotacl blob - d01669e79c40ee6a64a1ed544069b368ac00bac0 file + gotwebd/parse.y --- gotwebd/parse.y +++ gotwebd/parse.y @@ -1011,8 +1011,8 @@ host(const char *s, struct server *new_srv, int max, return (cnt); memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; /* DUMMY */ + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; /* DUMMY */ hints.ai_flags = AI_ADDRCONFIG; error = getaddrinfo(s, NULL, &hints, &res0); if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME)