diff --git a/src/switch_utils.c b/src/switch_utils.c index 505c85cbd5..2ac36a7ad4 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -747,7 +747,7 @@ static int get_netmask(struct sockaddr_in *me, int *mask) { struct ifaddrs *ifaddrs, *i = NULL; - if (getifaddrs(&ifaddrs) < 0) { + if (!me || getifaddrs(&ifaddrs) < 0) { return -1; } @@ -755,7 +755,7 @@ static int get_netmask(struct sockaddr_in *me, int *mask) struct sockaddr_in *s = (struct sockaddr_in *)i->ifa_addr; struct sockaddr_in *m = (struct sockaddr_in *)i->ifa_netmask; - if (s->sin_addr.s_addr == me->sin_addr.s_addr) { + if (s && m && s->sin_addr.s_addr == me->sin_addr.s_addr) { *mask = m->sin_addr.s_addr; return 0; }