Skip to content

Unable to get information with getaddrinfo with default hostname #93822

@Stanislas-MARTIN

Description

@Stanislas-MARTIN

Describe the bug

I am using the RT1170-EVKB. I was trying to use the default hostname zephyr and then use said hostname with getaddrinfo. But it failed with EAI_NONAME .
Afterward, I set the host name to a random string to the same result.
I was able to make it work if I used localhost for the hostname.

Regression

  • This is a regression.

Steps to reproduce

Step to reproduce this behaviour:

  1. mkdir test; cd test
  2. mkdir src
  3. Copy the following in src/main.c
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(Main, LOG_LEVEL_INF);

#include <zephyr/kernel.h>
#include <stdio.h>
#include <zephyr/net/hostname.h>
#include <zephyr/posix/netdb.h>


int main() {
        const char *hostname;
        int result;
        struct addrinfo hints = { 0 };
        struct addrinfo *addrinfos;
        hints.ai_family = AF_INET;

        hostname = net_hostname_get();

        result = getaddrinfo(hostname, NULL, &hints, &addrinfos);

        if (result < 0) {
                LOG_ERR("The function getaddrinfo failed with %d (%s)", result, gai_strerror(result));
                return -1;
        }
        LOG_INF("The function getaddrinfo was successful");
        return 0;
}
  1. Copy the following to CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(test)

target_sources(app PRIVATE src/main.c)
  1. Copy the following to prj.conf
CONFIG_NETWORKING=y
CONFIG_POSIX_API=y
CONFIG_NET_HOSTNAME_ENABLE=y
  1. west build -p -b <your_board>
  2. west flash

Relevant log output

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

  • OS: Windows
  • SDK: 0.17.1
  • Version 4.1

Additional Context

No response

Metadata

Metadata

Assignees

Labels

area: NetworkingbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions