]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blobdiff - config/cfgroot/network-functions.pl
Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-2.x
[people/mfischer/ipfire-2.x.git] / config / cfgroot / network-functions.pl
index 9908ee8abd2089962f8a482f8222edc1066c7106..b7a840559ccd5ec52a4cf918065538690a2c32ed 100644 (file)
@@ -332,13 +332,35 @@ sub setup_upstream_proxy() {
        }
 }
 
+sub list_wireless_interfaces() {
+       my %interfaces = ();
+
+       opendir(INTERFACES, "/sys/class/net");
+
+       my $intf;
+       while ($intf = readdir(INTERFACES)) {
+               # Is this a wireless interface?
+               opendir(PHY80211, "/sys/class/net/$intf/phy80211") or next;
+               closedir(PHY80211);
+
+               # Read the MAC address
+               my $address = &get_nic_property($intf, "address");
+
+               $interfaces{$address} = "$address ($intf)";
+       }
+
+       closedir(INTERFACES);
+
+       return %interfaces;
+}
+
 my %wireless_status = ();
 
 sub _get_wireless_status($) {
        my $intf = shift;
 
        if (!$wireless_status{$intf}) {
-               $wireless_status{$intf} = `iwconfig $intf`;
+               $wireless_status{$intf} = &General::system_output("iwconfig", "$intf");
        }
 
        return $wireless_status{$intf};
@@ -416,7 +438,7 @@ sub get_nic_property {
        my $property = shift;
        my $result;
 
-       open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property");
+       open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property $property for $nicname");
        $result = <FILE>;
        close(FILE);
 
@@ -465,6 +487,28 @@ sub get_mac_by_name($) {
        return $mac;
 }
 
+sub get_intf_by_address($) {
+       my $address = shift;
+
+       opendir(INTERFACES, "/sys/class/net");
+
+       while (my $intf = readdir(INTERFACES)) {
+               next if ($intf eq "." or $intf eq "..");
+
+               my $intf_address = &get_nic_property($intf, "address");
+
+               # Skip interfaces without addresses
+               next if ($intf_address eq "");
+
+               # Return a match
+               return $intf if ($intf_address eq $address);
+       }
+
+       closedir(INTERFACES);
+
+       return undef;
+}
+
 #
 ## Function to get a list of all available network zones.
 #