Commit e7599d9e33b4d7bab49c5ca0703b8b90f12700a4
1 parent
625b7677
more fixes in network identification.
Showing
1 changed file
with
33 additions
and
8 deletions
... | ... | @@ -86,10 +86,11 @@ gather_if_info_ip() { |
86 | 86 | $1 != current_if { |
87 | 87 | print "IF" no "_IPV4=\"" ipv4 "\";"; |
88 | 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 | 91 | current_if=$1; |
92 | 92 | ipv6=ipv4=""; |
93 | + networks=netmasks=""; | |
93 | 94 | } |
94 | 95 | BEGIN { |
95 | 96 | classes=""; |
... | ... | @@ -119,7 +120,7 @@ gather_if_info_ip() { |
119 | 120 | if (i-1 == full_octets) { |
120 | 121 | mpart=256-lshift(1, 8-part_octets); |
121 | 122 | mask=mask mpart; |
122 | - net=net and(parts[i],mpart); | |
123 | + net=net and(parts[i],mpart); | |
123 | 124 | } else { |
124 | 125 | mask=mask "0"; |
125 | 126 | net=net "0"; |
... | ... | @@ -141,22 +142,46 @@ gather_if_info_ip() { |
141 | 142 | # FIXME This is outdated. It does not set classes at all. |
142 | 143 | # |
143 | 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 | 146 | /^[^ \t]/ { |
148 | 147 | if ("UP" == state) classes=classes mac " "; |
149 | 148 | if ("" != name) { |
150 | 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 | 154 | no++; |
154 | 155 | } |
155 | 156 | ipv4=ipv6=mac=""; |
157 | + networks=netmasks=""; | |
156 | 158 | sub(/:/,"",$1); |
157 | 159 | name=$1; |
158 | 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 | 185 | /inet6/ { |
161 | 186 | sub(/%.*/,"",$2); |
162 | 187 | ipv6=ipv6 $2 " "; | ... | ... |
Please
register
or
login
to post a comment