laforge has uploaded this change for review.

View Change

core/socket.c: Fix socket binding on IPv4-only hosts

Let's add the AI_ADDRCONFIG flag to prevent getaddrinfo() from returning
IPv6 addresses on sytems that have no IPv6.

From the manpage:

> If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4
> addresses are returned in the list pointed to by res only if the local
> system has at least one IPv4 address configured, and IPv6 addresses are
> returned only if the local system has at least one IPv6 address
> configured. The loopback address is not considered for this case as
> valid as a configured address. *This flag is useful on, for example,
> IPv4-only systems, to ensure that getaddrinfo() does not return IPv6
> socket addresses that would always fail in connect(2) or bind(2).*

Change-Id: I5690a25af98089e3a8a092cb91dfc969720abdc0
Closes: OS#7074
---
M src/core/socket.c
1 file changed, 1 insertion(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/74/37874/1
diff --git a/src/core/socket.c b/src/core/socket.c
index 97708a7..7d10e7b 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -66,6 +66,7 @@
snprintf(portbuf, sizeof(portbuf), "%u", port);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
+ hints.ai_flsgs = AI_ADDRCONFIG;
if (type == SOCK_RAW) {
/* Workaround for glibc, that returns EAI_SERVICE (-8) if
* SOCK_RAW and IPPROTO_GRE is used.

To view, visit change 37874. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5690a25af98089e3a8a092cb91dfc969720abdc0
Gerrit-Change-Number: 37874
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>