7.2 Forward Lookups

7.2.1 localhost in the shim #

  • A name that, with trailing dots removed, is localhost or ends in .localhost, compared case-insensitively, is answered inside the calling process without contacting resolvd — whether resolvd is running or not.
  • The answer is 127.0.0.1 for IPv4, ::1 for IPv6, or both, IPv4 first, with canonical name localhost and TTL 0.

7.2.2 Other names #

  • Any other name is sent as a lookup (§4.9), with the family the entry point asks for. The addresses in the reply are filtered to that family, and an empty result is NOTFOUND (§7.1).
  • Addresses are returned in the order resolvd's reply lists them.

resolvd does not fix which family comes first (§4.9); glibc's own sorting of getaddrinfo results is what callers normally see.

7.2.3 gethostbyname4_r #

The result is a linked list of gaih_addrtuple, and the pointer glibc passes is overwritten with the head of the list:

FieldContent
nextThe next tuple: one tuple per address, in reply order
nameOne copy of the canonical name, shared by every tuple
familyAF_INET or AF_INET6, per address
addrThe address
scopeid0, so an IPv6 link-local address is returned without the interface it belongs to

7.2.3.1 The gethostbyname4_r TTL #

When ttlp is given it receives the least TTL among the addresses.

7.2.4 The forward hostent #

gethostbyname3_r, 2_r and _r return a hostent:

FieldContent
h_nameThe reply's canonical name
h_aliasesEmpty
h_addrtypeThe af asked for
h_length4 or 16
h_addr_listEvery address, in reply order

7.2.5 The gethostbyname3_r TTL and canonical name #

When ttlp is given it receives the least TTL among the addresses, and when canonp is given it is pointed at h_name.

Edit this page