Dear Pablo,
getaddrinfo does not work for the combination of AF_INET, SOCK_RAW
and IPPROTO_GRE. I have attached an example application that can be
compiled with:
$ gcc -o fr fr.c `pkg-config --cflags --libs libosmocore libosmogb`
this prints:
getaddrinfo returned NULL: Success
FAILED
gettadrinfo returns -8 which should be this:
# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
I am not sure what is the most clever way to resolve this. Make SOCK_RAW
branch out early and do the socket/bind(/listen) manually, use getaddrinfo
twice with some more unspefici options, just deal with SOCK_RAW differently
now? The attached code has the benefit of at least handling INET and INET6
inside the getaddrinfo result.
any ideas?
holger
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/core/application.h>
#include <stdio.h>
#include <stdlib.h>
void bssgp_prim_cb()
{
}
const struct log_info log_info = {};
int main(int argc, char **argv)
{
int rc;
struct gprs_ns_inst *nsi;
log_init(&log_info, NULL);
nsi = gprs_ns_instantiate(NULL, NULL);
nsi->frgre.enabled = 1;
rc = gprs_ns_frgre_listen(nsi);
if (rc < 0)
printf("FAILED\n");
return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/src/socket.c b/src/socket.c
index 53205cd..33a4fe1 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -54,9 +54,12 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
sprintf(portbuf, "%u", port);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
- hints.ai_socktype = type;
- hints.ai_flags = 0;
- hints.ai_protocol = proto;
+
+ if (type != SOCK_RAW) {
+ hints.ai_socktype = type;
+ hints.ai_flags = 0;
+ hints.ai_protocol = proto;
+ }
if (flags & OSMO_SOCK_F_BIND)
hints.ai_flags |= AI_PASSIVE;
@@ -68,7 +71,10 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
- sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (type == SOCK_RAW)
+ sfd = socket(rp->ai_family, SOCK_RAW, proto);
+ else
+ sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1)
continue;
if (flags & OSMO_SOCK_F_NONBLOCK) {