summaryrefslogtreecommitdiff
path: root/examples/udhcp/simple.script
diff options
context:
space:
mode:
authorJiří Prchal2018-10-04 09:02:27 +0200
committerDenys Vlasenko2018-10-30 12:05:03 +0100
commit47839ae6797bcded0178893cb950d2e2f8be1f6f (patch)
tree9bb64f377d0c9d2be3b2bc1fe2b2e6357ed579e7 /examples/udhcp/simple.script
parentc05aa6a776ab2420a42c041a3b5d45db587fd9ef (diff)
downloadbusybox-47839ae6797bcded0178893cb950d2e2f8be1f6f.zip
busybox-47839ae6797bcded0178893cb950d2e2f8be1f6f.tar.gz
examples/udhcp/simple.script: add possibility to use modern "ip"
Script uses "ifconfig" only, not up-to-date so much. This patch adds "ip" in condition if exists. Signed-off-by: Jiří Prchal <jiri.prchal@aksignal.cz> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/udhcp/simple.script')
-rwxr-xr-xexamples/udhcp/simple.script18
1 files changed, 15 insertions, 3 deletions
diff --git a/examples/udhcp/simple.script b/examples/udhcp/simple.script
index e4c1f2d..44aa46e 100755
--- a/examples/udhcp/simple.script
+++ b/examples/udhcp/simple.script
@@ -6,19 +6,31 @@ RESOLV_CONF="/etc/resolv.conf"
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
NETMASK=""
-[ -n "$subnet" ] && NETMASK="netmask $subnet"
+if command -v ip >/dev/null; then
+ [ -n "$subnet" ] && NETMASK="/$subnet"
+else
+ [ -n "$subnet" ] && NETMASK="netmask $subnet"
+fi
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
echo "Setting IP address 0.0.0.0 on $interface"
- ifconfig $interface 0.0.0.0
+ if command -v ip >/dev/null; then
+ ip addr flush dev $interface
+ else
+ ifconfig $interface 0.0.0.0
+ fi
;;
renew|bound)
echo "Setting IP address $ip on $interface"
- ifconfig $interface $ip $NETMASK $BROADCAST
+ if command -v ip >/dev/null; then
+ ip addr add $ip$NETMASK $BROADCAST dev $interface
+ else
+ ifconfig $interface $ip $NETMASK $BROADCAST
+ fi
if [ -n "$router" ] ; then
echo "Deleting routers"