Skip to content

net/hosts: add module for static hostname definitions#21397

Merged
Teufelchen1 merged 7 commits intoRIOT-OS:masterfrom
benpicco:hostnames
Oct 6, 2025
Merged

net/hosts: add module for static hostname definitions#21397
Teufelchen1 merged 7 commits intoRIOT-OS:masterfrom
benpicco:hostnames

Conversation

@benpicco
Copy link
Copy Markdown
Contributor

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

@github-actions github-actions bot added Area: network Area: Networking Area: sys Area: System Area: examples Area: Example Applications labels Apr 11, 2025
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 11, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Apr 11, 2025

Murdock results

✔️ PASSED

c826d0c sys/net/sock_util: make unconditional use of dns_query()

Success Failures Total Runtime
10516 0 10516 12m:43s

Artifacts

Copy link
Copy Markdown
Contributor

@Teufelchen1 Teufelchen1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful. I feel like the hassle with AF_INET and AF_UNSPEC are not worth it, as the implementation only supports v6 anyways and it looks unlikely to me, that this will change anytime soon. Hence I propose to change the API. Instead of: one function suits all but only ever does v6 and you don't know the resulting buffer size or type - let's have a: This queries the v6 hosts file, takes name, gives ipv6_addr_t back, xoxo.

What do you think, what are your longterm plans?

@crasbe crasbe added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label May 7, 2025
@benpicco
Copy link
Copy Markdown
Contributor Author

benpicco commented May 7, 2025

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.

Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small style/documentation comments.

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Sep 8, 2025

@Teufelchen1 you still have an open change-request, is that still valid after Ben's answer?

@Teufelchen1 Teufelchen1 dismissed their stale review September 8, 2025 13:36

Changed my mind

@Teufelchen1
Copy link
Copy Markdown
Contributor

Thanks for the ping. Please proceed.

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Sep 8, 2025

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.

@crasbe crasbe added the State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary label Sep 11, 2025
@benpicco benpicco removed the State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary label Sep 11, 2025
@Teufelchen1
Copy link
Copy Markdown
Contributor

Whats the status here? Rebase is done, @crasbe, can we merge?

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Oct 6, 2025

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 🤔 😅

@Teufelchen1 Teufelchen1 added this pull request to the merge queue Oct 6, 2025
Merged via the queue into RIOT-OS:master with commit 0d5e3f0 Oct 6, 2025
26 checks passed
@benpicco benpicco deleted the hostnames branch October 6, 2025 14:01
@benpicco benpicco added this to the Release 2025.10 milestone Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: examples Area: Example Applications Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants