Skip to content

Commit

Permalink
Merge pull request #55 from cheng-zhongliang/master
Browse files Browse the repository at this point in the history
bug fix: set bad mask when netmask 32
  • Loading branch information
tleguern authored May 7, 2024
2 parents 77de101 + 90506aa commit ec12137
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tuntap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit ec12137

Please sign in to comment.