From e7599d9e33b4d7bab49c5ca0703b8b90f12700a4 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Thu, 14 Aug 2014 11:40:20 +0100 Subject: [PATCH] more fixes in network identification. --- gatherer/interface_information.sh | 41 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/gatherer/interface_information.sh b/gatherer/interface_information.sh index 9eef021..2f1d299 100644 --- a/gatherer/interface_information.sh +++ b/gatherer/interface_information.sh @@ -86,10 +86,11 @@ gather_if_info_ip() { $1 != current_if { print "IF" no "_IPV4=\"" ipv4 "\";"; print "IF" no "_IPV6=\"" ipv6 " \";"; - print "IF" no "_NETWORK=\"" net "\";"; - print "IF" no "_MASK=\"" mask "\";"; + print "IF" no "_NETWORK=\"" networks "\";"; + print "IF" no "_MASK=\"" netmasks "\";"; current_if=$1; ipv6=ipv4=""; + networks=netmasks=""; } BEGIN { classes=""; @@ -119,7 +120,7 @@ gather_if_info_ip() { if (i-1 == full_octets) { mpart=256-lshift(1, 8-part_octets); mask=mask mpart; - net=net and(parts[i],mpart); + net=net and(parts[i],mpart); } else { mask=mask "0"; net=net "0"; @@ -141,22 +142,46 @@ gather_if_info_ip() { # FIXME This is outdated. It does not set classes at all. # gather_if_info_ifconfig() { - eval $(${IFCONFIG} -a | ${AWK} ' - /ether/ { mac=$2 } - /inet / { ipv4=ipv4 $2 " "; classes=classes $2 " " } + eval $(${IFCONFIG} -a | ${AWK} --non-decimal-data ' /^[^ \t]/ { if ("UP" == state) classes=classes mac " "; if ("" != name) { print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ - "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ - "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; + "IF" no "_IPV4=\"" ipv4 "\";" \ + "IF" no "_IPV6=\"" ipv6 "\";" \ + "IF" no "_NETWORK=\"" networks "\";" \ + "IF" no "_MASK=\"" netmasks "\";"; no++; } ipv4=ipv6=mac=""; + networks=netmasks=""; sub(/:/,"",$1); name=$1; state="DOWN"; } + /ether/ { mac=$2 } + /inet / { + ipv4=ipv4 $2 " "; + if("0x" == substr($4,0,2)) { + mask=netmask sprintf("%d.%d.%d.%d ", + "0x" substr($4,2,2), + "0x" substr($4,4,2), + "0x" substr($4,6,2), + "0x" substr($4,8,2)); + } else { + mask=mask $4 " "; + } + split($2,parts,/\./); + split(mask,mparts,/\./); + for(i=1; i<5; i++) { + net=net and(parts[i],mparts[i]); + if(i < 4) net=net "."; + } + classes=classes $2 " "; + classes=classes net " "; + networks=networks net " "; + netmasks=netmasks mask " "; + } /inet6/ { sub(/%.*/,"",$2); ipv6=ipv6 $2 " ";