Adjust netGetNetmask for new net-tools output, switch netGetIp from ifconfig to ip
authorMichael Prokop <mika@grml.org>
Fri, 6 Oct 2017 11:23:09 +0000 (13:23 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 6 Oct 2017 11:44:29 +0000 (13:44 +0200)
ifconfig from net-tools until 1.60-27 looked like:

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:74133 errors:0 dropped:0 overruns:0 frame:0
          TX packets:74133 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:7122434 (6.7 MiB)  TX bytes:7122434 (6.7 MiB)

Starting with net-tools 1.60+git20150829.73cef8a-1 it looks like:

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

So we need to adjust ifconfig parsing accordingly.
There's no need to use ifconfig for netGetIp, so switch to ip(8) while at it.

Thanks: karlh1 + Patrick Neumann for the bug report
Closes grml/grml#65

sh-lib

diff --git a/sh-lib b/sh-lib
index 1975585..e87b9cb 100644 (file)
--- a/sh-lib
+++ b/sh-lib
@@ -515,7 +515,11 @@ netGetNetmask()
   local ret_=''
 
   setCLang
-  nm_=`ifconfig "$iface_" | awk '/[Mm]ask/{FS="[:   ]*"; $0=$0; print $8; exit}'`
+  if ifconfig "$iface_" | grep -qi 'Mask:' ; then # old ifconfig output:
+    nm_=$(ifconfig "$iface_" | awk '/[Mm]ask/{FS="[:   ]*"; $0=$0; print $8; exit}')
+  else # new ifconfig output (net-tools >1.60-27):
+    nm_=$(ifconfig "$iface_" | awk '/netmask/{print $4}')
+  fi
   ret_=$?
   restoreLang
   if [ -z "$nm_" ]; then
@@ -542,8 +546,7 @@ netGetIp()
   local ret_=""
 
   setCLang
-  #ip_=`ip addr list eth0 |mawk '/inet/{split($2,A,"/"); print A[1]}'`
-  ip_=`ifconfig "$iface_" | awk '/[Ii]net [Aa]ddr/{FS="[:  ]*"; $0=$0; print $4; exit}'`
+  ip_=$(ip addr show dev "$iface_" | awk '/inet /{split($2,a,"/"); print a[1]}')
   ret_=$?
   restoreLang
   if [ -z "$ip_" ]; then