linuxembeddedembedded-linuxyoctogetaddrinfo

getaddrinfo returns EAI_ADDRFAMILY on a distribution built with Yocto


We are currently using Oat++ (https://oatpp.io/) as a webserver for an embedded project. It is working wonder with several environments: docker container, ubuntu VM, Raspberry Pi 3.

However, for this project we have our own linux distribution built with Yocto (https://www.yoctoproject.org/) and after some debugging, we realize that the getaddrinfo (http://man7.org/linux/man-pages/man3/getaddrinfo.3.html) function is not working.

Here's a sample code of what is happening:

struct addrinfo *result = NULL;
struct addrinfo hints;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;

int iResult = getaddrinfo(NULL, "8080", &hints, &result);

// iResult == EAI_ADDRFAMILY

Has anyone any idea of what could be the problem?

PS: We tried comparing the kernel config with the one from the Raspberry Pi 3 but without success PSS: We also tried to set the IP (i.e.: getaddrinfo("192.168.1.10", "8080", &hints, &result)), also without success


Solution

  • Well, we found that the problem was not with getaddrinfo... Sorry for that.

    The problem was because of IPv6 (the implementation of SimpleTCPConnectionProvider for linux is only using INET6) and our system is built only with IPv4.

    So I created my own ServerConnectionProvider that implements a socket with INET instead of INET6.