diff options
author | rodri <rgl@antares-labs.eu> | 2020-11-08 18:21:19 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2020-11-08 18:21:19 +0000 |
commit | c81c58bb4361f3af31fcdd50c2b41ce193905c65 (patch) | |
tree | 4c07b0b4edff7766d38f77cbaae9268cbc54cce9 | |
parent | ec26199210fcdaf512900413a014f91e20af18db (diff) | |
download | ipcalc-c81c58bb4361f3af31fcdd50c2b41ce193905c65.tar.gz ipcalc-c81c58bb4361f3af31fcdd50c2b41ce193905c65.tar.bz2 ipcalc-c81c58bb4361f3af31fcdd50c2b41ce193905c65.zip |
-rw-r--r-- | main.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -142,10 +142,20 @@ main(int argc, char *argv[]) net.addr = addr&mask; net.mask = mask; net.bcast = addr|~mask; - net.minaddr = net.addr+1; - net.maxaddr = net.bcast-1; - net.nhosts = net.maxaddr-net.minaddr; net.cidr = countmsones(net.mask); + + if(net.cidr < 32){ + /* see RFC3021 */ + net.minaddr = net.addr; + net.maxaddr = net.bcast; + if(net.cidr <= 30){ + net.minaddr++; + net.maxaddr--; + } + }else + net.minaddr = net.maxaddr = net.addr; + + net.nhosts = net.maxaddr-net.minaddr + 1; print("%N", net); exits(nil); |