diff --git a/routing.c b/routing.c index 4141886..8bbc628 100644 --- a/routing.c +++ b/routing.c @@ -112,13 +112,24 @@ void routing_init(char *ip) { #endif /* Solaris */ #if defined(__linux) char buf[256]; + char tbuf[256]; + const char * uidStart; FILE *p; snprintf(buf, 255, "%s route get %s", IP_BINARY, ip); p = popen(buf, "r"); fgets(buf, 255, p); /* TODO: check for failure of fgets */ - route = strdup(buf); + /* Starting with iproute2 4.10.0, call to 'ip route get' will contain uid value. + * Still uid should not be used in other calls (i.e. replace, delete). */ + uidStart = strstr(buf, " uid"); + if (uidStart) { + snprintf(tbuf, uidStart - buf + 1, "%s", buf); + route = strdup(tbuf); + } + else { + route = strdup(buf); + } pclose(p); /* TODO: check for failure of command */ #endif /* __linux__ */