serenity icon indicating copy to clipboard operation
serenity copied to clipboard

RequestServer: Replace use of gethostbyname with getaddrinfo

Open ADKaster opened this issue 2 years ago • 2 comments

On non-Serenity systems that support IPv6, using gethostbyname is an anti-pattern that distros such as SUSE and Red Hat have been trying to eliminate.

In ConnectionFromClient::ensure_connection, we use gethostbyname to ensure that a DNS lookup is performed for the ResolveOnly cache level.

https://github.com/SerenityOS/serenity/blob/3a820ddbdfd53a5627903715e7c5a51f998c0845/Userland/Services/RequestServer/ConnectionFromClient.cpp#L149-L154

Replace this usage of gethostbyname with one of getaddrinfo or the LibCore equivalent that will also force the host system to perform a DNS lookup.

cc @alimpfard

ADKaster avatar Dec 07 '23 17:12 ADKaster

:thinking: is there something wrong with gethostbyname (aside from not supporting ipv6, which is probably not supported by the rest of the stack anyway)?

The change would be good for when RS (and serenity) gains support for ipv6 though, so :+1:.

alimpfard avatar Dec 08 '23 10:12 alimpfard

The OpenSUSE guidelines link to a post by Ulrich Drepper (of all people :thinking: ) explaining why it's not great on IPv4 networks either, when a host has both an internal and an external IP address. gethostbyname just returns one at random, while getaddrinfo has a spec mandated order.

ADKaster avatar Dec 08 '23 22:12 ADKaster