OpenWrt Forum Archive

Topic: ipcalc not reporting PREFIX correctly

The content of this topic has been archived on 19 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I've been using the nbt images, and I'm finding that the ipcalc command has changed and is not reporting the prefix properly (or at least what I understand the prefix should be). I used the old one to produce a CIDR number for my firewall.user scripts and other IPSEC related tools. I've created a work around, but I think the PREFIX is not right, as it is always showing up as 8. Here are some notes on the situation.

the one I'm used to reports this...

~# ipcalc
BusyBox v1.00 (2006.02.18-21:41+0000) multi-call binary

Usage: ipcalc [OPTION]... <ADDRESS>[[/]<NETMASK>] [NETMASK]

Calculate IP network settings from a IP address

Options:
        -b      --broadcast     Display calculated broadcast address.
        -n      --network       Display calculated network address.
        -m      --netmask       Display default netmask for IP.
        -p      --prefix        Display the prefix for IP/NETMASK.      -h     --hostname       Display first resolved host name.
        -s      --silent        Don't ever display error messages.

And the new one shows this...

~# ipcalc
IP=0
NETMASK=0
BROADCAST=255.255.255.255
NETWORK=0
PREFIX=0

I've found that ipcalc also shows up in the /etc/init.d/S50dnsmasq script so I'm sure there was a reason for changing the functionality of this, but I don't understand it, and I can't seem to make it report a correct prefix.
Thanks
-hanz

The syntax is

ipcalc <ip> <netmask>

Or, optionally

ipcalc <ip> <netmask> <start> <number>

which is used for calculating ranges for things like dnsmasq

I see, however the prefix still is different. Here is the new version...

~# ipcalc 10.0.0.1 255.255.255.240
IP=10.0.0.1
NETMASK=255.255.255.240
BROADCAST=10.0.0.15
NETWORK=10.0.0.0
PREFIX=8

and the old version with the prefix switch

~# ipcalc -p 10.0.0.1 255.255.255.240
PREFIX=28

And the shell scripts that I was writing needed the CIDR from the PREFIX to fill in some iptables commands. I got around it by applying a cludge because my math/scripting skills aren't that good.

LM=$(nvram get lan_netmask)
LD=$(echo $LM|awk -F. '{print $4}')
case $LD in 255) LD=32;; 254) LD=31;; 252) LD=30;; 248) LD=29;; 240) LD=28;; 224) LD=27;; 192) LD=26;; 128) LD=25;; 0) LD=24;; *) LD=;; esac

Thanks again
-hanz

The discussion might have continued from here.