netdb: Add http and https service entries

getaddrinfo() and getservbyname() use the built-in service table when
resolving service names. The table only contained ntp, so common
service names such as http and https could not be resolved without a
numeric port.

Add http and https entries for both TCP and UDP to match the existing
service table style.

Testing:

  - Host: Ubuntu 22.04 x86_64.

  - Board/config: sim:nsh with CONFIG_LIBC_NETDB=y and
    CONFIG_EXAMPLES_HELLO=y.

  - make clean && make -j16.

  - Ran a temporary hello example that called getservbyname("http",
    "tcp") and getservbyname("https", "tcp"). The app verified ports
    80 and 443 and printed "getservbyname http/https test passed".

Assisted-by: Claude:Claude-Fable-5
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2026-07-16 15:34:02 +08:00
parent 5b9707cb5c
commit 2a934fbfba

View file

@ -46,6 +46,10 @@
const struct services_db_s g_services_db[] =
{
{ "http", 80, IP_PROTO_TCP },
{ "http", 80, IP_PROTO_UDP },
{ "https", 443, IP_PROTO_TCP },
{ "https", 443, IP_PROTO_UDP },
{ "ntp", 123, IP_PROTO_TCP },
{ "ntp", 123, IP_PROTO_UDP },
{ NULL, 0, 0 }