From 90506aa15b97879714a7eebd22119d87c281b2f3 Mon Sep 17 00:00:00 2001 From: pilot Date: Fri, 26 Apr 2024 19:01:13 +0800 Subject: [PATCH] bug fix: set bad mask when netmask 32 --- tuntap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tuntap.c b/tuntap.c index c59e438..57fa3cb 100644 --- a/tuntap.c +++ b/tuntap.c @@ -97,9 +97,13 @@ tuntap_set_ip(struct device *dev, const char *addr, int netmask) { if (inet_pton(AF_INET, addr, &(baddr4)) == 1) { /* Netmask */ - mask = ~0; - mask = ~(mask >> netmask); - mask = htonl(mask); + if (netmask == 32) { + mask = htonl(INADDR_NONE); + } else { + mask = ~0; + mask = ~(mask >> netmask); + mask = htonl(mask); + } return tuntap_sys_set_ipv4(dev, &baddr4, mask); } else if (inet_pton(AF_INET6, addr, &(baddr6)) == 1) { /* ipv6 prefix no need to convert */