4 ms·
What software actually parses /etc/hosts, at least on Linux?
by vortico 9y ago
What software actually parses /etc/hosts, at least on Linux?
- kazinator 9y ago> What software actually parses /etc/hosts, at least on Linux? glibc resolver A good entry point for reading more about it: $ man nsswitch.conf If your /etc/nsswitch.conf file's "hosts" line contains the keyword "files", then it potentially uses /etc/hosts. If "files" is first (typical default config), it looks there first, before the other places listed. This is done under the hood when programs use resolver functions like gethostbyname or getaddrinfo.
- asamarin 9y agoYou can see this in action on musl source code, which is arguably a much more readily understandable implementation of libc: - Function that actually parses /etc/hosts is name_from_hosts(), implemented here: http://git.musl-libc.org/cgit/musl/tree/src/network/lookup_name.c#n48 http://git.musl-libc.org/cgit/musl/tree/src/network/lookup_n... - Which is called by __lookup_name() on the same file: http://git.musl-libc.org/cgit/musl/tree/src/network/lookup_name.c#n287 http://git.musl-libc.org/cgit/musl/tree/src/network/lookup_n... - Which is, in turn, called directly from getaddrinfo() [http://git.musl-libc.org/cgit/musl/tree/src/network/getaddrinfo.c#n49 http://git.musl-libc.org/cgit/musl/tree/src/network/getaddri...], the actual function exposed to you as libc user.