mirror of https://gerrit.osmocom.org/libosmocore
socket: fix osmo_sock_init with SOCK_RAW and IPPROTO_RAW
getaddrinfo returns EAI_SERVICE (-8) if that combination is used. More information available in here: http://sourceware.org/bugzilla/show_bug.cgi?id=15015 Reported by Holger Hans Peter Freyther. While at it, this patch also removes hints.ai_flags = 0 as memset to zero already happened just a bit before that.
This commit is contained in:
parent
06ddf8bd24
commit
e04a14d9a2
19
src/socket.c
19
src/socket.c
|
@ -54,9 +54,16 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
|
||||||
sprintf(portbuf, "%u", port);
|
sprintf(portbuf, "%u", port);
|
||||||
memset(&hints, 0, sizeof(struct addrinfo));
|
memset(&hints, 0, sizeof(struct addrinfo));
|
||||||
hints.ai_family = family;
|
hints.ai_family = family;
|
||||||
hints.ai_socktype = type;
|
if (type == SOCK_RAW) {
|
||||||
hints.ai_flags = 0;
|
/* Workaround for glibc, that returns EAI_SERVICE (-8) if
|
||||||
hints.ai_protocol = proto;
|
* SOCK_RAW and IPPROTO_GRE is used.
|
||||||
|
*/
|
||||||
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
|
} else {
|
||||||
|
hints.ai_socktype = type;
|
||||||
|
hints.ai_protocol = proto;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & OSMO_SOCK_F_BIND)
|
if (flags & OSMO_SOCK_F_BIND)
|
||||||
hints.ai_flags |= AI_PASSIVE;
|
hints.ai_flags |= AI_PASSIVE;
|
||||||
|
@ -68,6 +75,12 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
|
/* Workaround for glibc again */
|
||||||
|
if (type == SOCK_RAW) {
|
||||||
|
rp->ai_socktype = SOCK_RAW;
|
||||||
|
rp->ai_protocol = proto;
|
||||||
|
}
|
||||||
|
|
||||||
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||||
if (sfd == -1)
|
if (sfd == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue