udhcpc usage

Guenter lists at gknw.net
Wed Apr 15 17:28:53 UTC 2009


Hi Walter,
walter harms schrieb:
> basicly the script should call ipconfig somewhere.
> can you echo that line ?
I use this script from busybox distro:
http://sources.busybox.net/index.py/branches/busybox_1_13_stable/examples/udhcp/simple.script?revision=23979&view=markup

> That shoulk clearly show what is going on.
it was enough the add a line to echo the $broadcast var to see that is
seems not set from udhcpc, thus ifconfig does it on its own, and gives
the previous described result ending up with a B broadcast with a C
mask. You can easily re-create this behaviour of busybox ifconfig from
commandline when you ommit the broadcast:
ifconfig eth0 172.16.0.1 netmask 255.255.255.0
ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:BA:BE:FA:CE:01
          inet addr:172.16.0.1  Bcast:172.16.255.255  Mask:255.255.255.0

ifconfig eth0 192.168.0.1 netmask 255.255.255.0
ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:BA:BE:FA:CE:01
          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0

The setting CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y seems not to matter
here although looking at the code I found this part:

#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
                        else if ((host[0] == '+' && !host[1]) && (mask &
A_BROADCAST)
                         && (did_flags & (A_NETMASK|A_HOSTNAME)) ==
(A_NETMASK|A_HOSTNAME)
                        ) {
                            /* + is special, meaning broadcast is
derived. */
                            sai.sin_addr.s_addr = (~sai_netmask) |
(sai_hostname & sai_netmask);
                        }
#endif

so this suggests to use 'broadcast +' to trigger the automatic
broadcast, and indeed this works:
ifconfig eth0 172.16.0.1 netmask 255.255.255.0 broadcast +
eth0      Link encap:Ethernet  HWaddr 00:BA:BE:FA:CE:01
          inet addr:172.16.0.1  Bcast:172.16.0.255  Mask:255.255.255.0

but: the order matters! If you try:
ifconfig eth0 172.16.0.1 broadcast + netmask 255.255.255.0
this results:
ifconfig: bad address '+'

now big question is: why does the busybox sample script test for
$broadcast ? Does udhcpc probably with some commandline options pass a
broadcast to the script?
Also I think we should add another sample script which shows the usage
of this auto broadcast feature.

Guen.





More information about the busybox mailing list