summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Vyatta/Interface.pm47
1 files changed, 22 insertions, 25 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm
index e8e2e30..2cc47ba 100755
--- a/lib/Vyatta/Interface.pm
+++ b/lib/Vyatta/Interface.pm
@@ -24,11 +24,13 @@ use warnings;
use Vyatta::Config;
use Vyatta::Misc;
use base 'Exporter';
+use Socket;
+require 'sys/ioctl.ph';
+
our @EXPORT = qw(IFF_UP IFF_BROADCAST IFF_DEBUG IFF_LOOPBACK
IFF_POINTOPOINT IFF_RUNNING IFF_NOARP
IFF_PROMISC IFF_MULTICAST);
-
use constant {
IFF_UP => 0x1, # interface is up
IFF_BROADCAST => 0x2, # broadcast address valid
@@ -210,7 +212,7 @@ sub _ppp_intf {
chomp;
# looking for line like:
# pty "/usr/sbin/pppoe -m 1412 -I eth1"
- next unless /pty\s.*-I\s*(\w+)"/;
+ next unless /^pty\s.*-I\s*(\w+)"/;
$intf = $1;
last;
}
@@ -404,34 +406,29 @@ sub address {
return Vyatta::Misc::getIP($self->{name}, $type);
}
-sub exists {
- my $self = shift;
+# Do SIOCGIFFLAGS ioctl in perl
+sub flags {
+ my $self = shift;
- return ( -d "/sys/class/net/$self->{name}" );
-}
+ my $SIOCGIFFLAGS = &SIOCGIFFLAGS;
+ die "SIOCGIFFLAGS not found"
+ unless defined($SIOCGIFFLAGS);
-sub flags {
- my $self = shift;
+ socket (my $sock, AF_INET, SOCK_DGRAM, 0)
+ or die "open UDP socket failed: $!";
- open my $flags, '<', "/sys/class/net/$self->{name}/flags"
- or return;
+ my $ifreq = pack('a16', $self->{name});
+ ioctl($sock, $SIOCGIFFLAGS, $ifreq)
+ or return; #undef
- my $val = <$flags>;
- chomp $val;
- close $flags;
- return hex($val);
+ my (undef, $flags) = unpack('a16s', $ifreq);
+ return $flags;
}
-sub carrier {
+sub exists {
my $self = shift;
- open my $carrier, '<', "/sys/class/net/$self->{name}/carrier"
- or return;
-
- my $val = <$carrier>;
- $val = 0 if ! defined $val; # proc entry not readable on down interface
- chomp $val;
- close $carrier;
- return $val;
+ my $flags = $self->flags();
+ return defined($flags);
}
sub hw_address {
@@ -471,7 +468,7 @@ sub up {
my $self = shift;
my $flags = $self->flags();
- return $flags && ( $flags & IFF_UP );
+ return defined($flags) && ( $flags & IFF_UP );
}
# device exists and is running (ie carrier present)
@@ -479,7 +476,7 @@ sub running {
my $self = shift;
my $flags = $self->flags();
- return $flags && ( $flags & IFF_RUNNING );
+ return defined($flags) && ( $flags & IFF_RUNNING );
}
# device description information in kernel (future use)