net/hosts: add module for static hostname definitions
Contribution description
Operating with hostnames instead of raw IP addresses can be more convenient in applications.
On Linux we have /etc/hosts where we can statically define hostname -> IP mappings.
This module adds something similar to RIOT.
Testing procedure
Enable the hosts module. The XFA is by default populated with a localhost entry:
2025-04-11 17:49:05,409 # > ping localhost
2025-04-11 17:49:05,414 # 12 bytes from ::1: icmp_seq=0 ttl=64 time=0.202 ms
2025-04-11 17:49:06,414 # 12 bytes from ::1: icmp_seq=1 ttl=64 time=0.202 ms
2025-04-11 17:49:07,414 # 12 bytes from ::1: icmp_seq=2 ttl=64 time=0.202 ms
2025-04-11 17:49:07,415 #
2025-04-11 17:49:07,417 # --- localhost PING statistics ---
2025-04-11 17:49:07,422 # 3 packets transmitted, 3 packets received, 0% packet loss
2025-04-11 17:49:07,426 # round-trip min/avg/max = 0.202/0.202/0.202 ms
Issues/PRs references
Murdock results
:heavy_check_mark: PASSED
c826d0cddb4add3503a8d7abba9f4291e6b4bf6c sys/net/sock_util: make unconditional use of dns_query()
| Success | Failures | Total | Runtime |
|---|---|---|---|
| 10516 | 0 | 10516 | 12m:43s |
Artifacts
I would like to keep the API compatible with the other backends of dns_query().
Adding support for AF_INET is trivial and useful for lwIP.
@Teufelchen1 you still have an open change-request, is that still valid after Ben's answer?
Thanks for the ping. Please proceed.
I'm not familiar with the networking subsystem in RIOT, but the ping localhost does not appear to work with examples/networking/gnrc_networking.
> ping localhost
2025-09-08 15:49:00,780 # ping localhost
2025-09-08 15:49:00,781 # can't resolve localhost
The gnrc_border_router example seems to only enable the hosts module when the DNS modules are loaded, but on the other hand there is no error when loading the hosts module as it is.
Whats the status here? Rebase is done, @crasbe, can we merge?
Whats the status here? Rebase is done, @crasbe, can we merge?
You didn't give an approval and I can't really judge the technical aspects of it. But from my side it's good, although my side is mostly style related 🤔 😅