Commit e7599d9e33b4d7bab49c5ca0703b8b90f12700a4

Authored by Georg Hopp
1 parent 625b7677

more fixes in network identification.

@@ -86,10 +86,11 @@ gather_if_info_ip() { @@ -86,10 +86,11 @@ gather_if_info_ip() {
86 $1 != current_if { 86 $1 != current_if {
87 print "IF" no "_IPV4=\"" ipv4 "\";"; 87 print "IF" no "_IPV4=\"" ipv4 "\";";
88 print "IF" no "_IPV6=\"" ipv6 " \";"; 88 print "IF" no "_IPV6=\"" ipv6 " \";";
89 - print "IF" no "_NETWORK=\"" net "\";";  
90 - print "IF" no "_MASK=\"" mask "\";"; 89 + print "IF" no "_NETWORK=\"" networks "\";";
  90 + print "IF" no "_MASK=\"" netmasks "\";";
91 current_if=$1; 91 current_if=$1;
92 ipv6=ipv4=""; 92 ipv6=ipv4="";
  93 + networks=netmasks="";
93 } 94 }
94 BEGIN { 95 BEGIN {
95 classes=""; 96 classes="";
@@ -119,7 +120,7 @@ gather_if_info_ip() { @@ -119,7 +120,7 @@ gather_if_info_ip() {
119 if (i-1 == full_octets) { 120 if (i-1 == full_octets) {
120 mpart=256-lshift(1, 8-part_octets); 121 mpart=256-lshift(1, 8-part_octets);
121 mask=mask mpart; 122 mask=mask mpart;
122 - net=net and(parts[i],mpart); 123 + net=net and(parts[i],mpart);
123 } else { 124 } else {
124 mask=mask "0"; 125 mask=mask "0";
125 net=net "0"; 126 net=net "0";
@@ -141,22 +142,46 @@ gather_if_info_ip() { @@ -141,22 +142,46 @@ gather_if_info_ip() {
141 # FIXME This is outdated. It does not set classes at all. 142 # FIXME This is outdated. It does not set classes at all.
142 # 143 #
143 gather_if_info_ifconfig() { 144 gather_if_info_ifconfig() {
144 - eval $(${IFCONFIG} -a | ${AWK} '  
145 - /ether/ { mac=$2 }  
146 - /inet / { ipv4=ipv4 $2 " "; classes=classes $2 " " } 145 + eval $(${IFCONFIG} -a | ${AWK} --non-decimal-data '
147 /^[^ \t]/ { 146 /^[^ \t]/ {
148 if ("UP" == state) classes=classes mac " "; 147 if ("UP" == state) classes=classes mac " ";
149 if ("" != name) { 148 if ("" != name) {
150 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ 149 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \
151 - "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \  
152 - "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; 150 + "IF" no "_IPV4=\"" ipv4 "\";" \
  151 + "IF" no "_IPV6=\"" ipv6 "\";" \
  152 + "IF" no "_NETWORK=\"" networks "\";" \
  153 + "IF" no "_MASK=\"" netmasks "\";";
153 no++; 154 no++;
154 } 155 }
155 ipv4=ipv6=mac=""; 156 ipv4=ipv6=mac="";
  157 + networks=netmasks="";
156 sub(/:/,"",$1); 158 sub(/:/,"",$1);
157 name=$1; 159 name=$1;
158 state="DOWN"; 160 state="DOWN";
159 } 161 }
  162 + /ether/ { mac=$2 }
  163 + /inet / {
  164 + ipv4=ipv4 $2 " ";
  165 + if("0x" == substr($4,0,2)) {
  166 + mask=netmask sprintf("%d.%d.%d.%d ",
  167 + "0x" substr($4,2,2),
  168 + "0x" substr($4,4,2),
  169 + "0x" substr($4,6,2),
  170 + "0x" substr($4,8,2));
  171 + } else {
  172 + mask=mask $4 " ";
  173 + }
  174 + split($2,parts,/\./);
  175 + split(mask,mparts,/\./);
  176 + for(i=1; i<5; i++) {
  177 + net=net and(parts[i],mparts[i]);
  178 + if(i < 4) net=net ".";
  179 + }
  180 + classes=classes $2 " ";
  181 + classes=classes net " ";
  182 + networks=networks net " ";
  183 + netmasks=netmasks mask " ";
  184 + }
160 /inet6/ { 185 /inet6/ {
161 sub(/%.*/,"",$2); 186 sub(/%.*/,"",$2);
162 ipv6=ipv6 $2 " "; 187 ipv6=ipv6 $2 " ";
Please register or login to post a comment