Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The interfaces file looks like below:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.0.130
    netmask 250.255.255.0
    gateway 192.168.0.254

As you can see the netmask address is sort of invalid. (250 instead of 255) The problem is when we use the following code to get the current IP address and netmask:

ioctl(iSock, SIOCGIFADDR, &stIFReq);
ioctl(iSock, SIOCGIFNETMASK, &stIFReq);

It always returns "72,0,67,33" (hex:0x48004321) on both ioctl functions. I wonder if this is some sort of error code or bug during ifup. I would like to know what type of checking ifup does on netmasks/ip addresses and what does it do if the address is judged as invalid.

Additional info:

  1. Linux version 2.6.35.3

  2. BusyBox v1.18.5

  3. [ifup] is not a script but a C program on the system

share|improve this question
add comment

2 Answers 2

Check on your system, but on most ifup is a shell script, so you can see what it does by taking a peak at the source. You can see where the script resides with this command:

$ type -a ifup
ifup is /sbin/ifup

Feodra/Red Hat Distros

On my system (Fedora 14) /sbin/ifup includes this library of shell script functions, /etc/sysconfig/network-scripts/network-functions. If you grep through this file for "mask":

$ grep -i mask /etc/sysconfig/network-scripts/network-functions
    if [ -z "${NETMASK}" ]; then
    eval $(/bin/ipcalc --netmask ${IPADDR})
    eval $(/bin/ipcalc --prefix ${IPADDR} ${NETMASK})
    eval $(/bin/ipcalc --broadcast ${IPADDR} ${NETMASK})
    eval $(/bin/ipcalc --network ${IPADDR} ${NETMASK})

The tool ipcalc is an executable that is used to do "calculations" regarding network configurations.

You can run it from the command line too:

$ /bin/ipcalc --netmask 192.168.1.1
NETMASK=255.255.255.0

$ /bin/ipcalc --prefix 192.168.1.1 255.255.255.0
PREFIX=24

Debian/Ubuntu

The ipcalc tool is slightly different on Debian/Ubuntu but serves a similar function.

$ ipcalc 192.168.1.1
Address:   192.168.1.1          11000000.10101000.00000001. 00000001
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.1.0/24       11000000.10101000.00000001. 00000000
HostMin:   192.168.1.1          11000000.10101000.00000001. 00000001
HostMax:   192.168.1.254        11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255        11000000.10101000.00000001. 11111111
Hosts/Net: 254                   Class C, Private Internet

You configurations

Fedora:

$ /bin/ipcalc --netmask 192.168.0.130
NETMASK=255.255.255.0

$ /bin/ipcalc --prefix 192.168.0.130 250.255.255.0
PREFIX=24

Ubuntu:

$ ipcalc 192.168.0.130
Address:   192.168.0.130        11000000.10101000.00000000. 10000010
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.0.0/24       11000000.10101000.00000000. 00000000
HostMin:   192.168.0.1          11000000.10101000.00000000. 00000001
HostMax:   192.168.0.254        11000000.10101000.00000000. 11111110
Broadcast: 192.168.0.255        11000000.10101000.00000000. 11111111
Hosts/Net: 254                   Class C, Private Internet

So what's most likely happening is your settings are getting setup with the wrong value in a spot. To debug this further I'd need to see the output of ip.

Example

$ ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:19:d1:e8:4c:95 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.3/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::219:d1ff:fee8:4c95/64 scope link 
       valid_lft forever preferred_lft forever
share|improve this answer
    
Thank you for your information. Sorry I didn't put it earlier but [ifup] on the system is not a script, but a program. Also, the system is on an embedded device so, it lacks some command/functions like [ipcalc]. –  Naze Kimi Oct 24 '13 at 2:53
    
@NazeKimi - figures. What does ifup show you? It should be a text file that you can view with a more command. –  slm Oct 24 '13 at 2:55
    
here was the output –  Naze Kimi Oct 24 '13 at 3:03
    
[root]# ifup -a ifup: interface lo already configured ifup: interface eth0 already configured [root]# [root]# [root]# ip addr show dev eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:06:48:00:43:21 brd ff:ff:ff:ff:ff:ff [root]# –  Naze Kimi Oct 24 '13 at 3:04
    
@NazeKimi - sorry I meant for you to more the file, not run it. –  slm Oct 24 '13 at 3:16
show 13 more comments

You are running BusyBox, whereifup/ifdown are applets. Looking at function count_netmask_bits() in the source code, BusyBox starts at the LSB and stops when it encounters the first 1. So it will not notice your malformed netmask.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.