diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2012-06-18 09:56:31 -0700 |
---|---|---|
committer | Stephen Hemminger <shemminger@vyatta.com> | 2012-06-18 09:56:31 -0700 |
commit | 8c690feda90f5bd20934a48bd346e6d8e54100b4 (patch) | |
tree | 9d609f4569d5abaccc746d5d2a8b744e3e4a19e8 /lib/Vyatta/ioctl.pm | |
parent | 5dc721184ae73ac0bb3fa46b181e3eb1a117dcdb (diff) | |
download | vyatta-cfg-8c690feda90f5bd20934a48bd346e6d8e54100b4.tar.gz vyatta-cfg-8c690feda90f5bd20934a48bd346e6d8e54100b4.zip |
ioctl interface improvements
Do some minor enhancements for usability.
* export get_terminal_size and get_interface_flags
* handle case where /dev/tty is inaccessible
* turn on warnings in this code
Diffstat (limited to 'lib/Vyatta/ioctl.pm')
-rw-r--r-- | lib/Vyatta/ioctl.pm | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Vyatta/ioctl.pm b/lib/Vyatta/ioctl.pm index b237854..8ed8b93 100644 --- a/lib/Vyatta/ioctl.pm +++ b/lib/Vyatta/ioctl.pm @@ -20,14 +20,23 @@ package Vyatta::ioctl; use strict; +use warnings; use Socket; use Socket6; + require 'sys/ioctl.ph'; +our @EXPORT = qw(get_terminal_size get_interface_flags); +use base qw(Exporter); + + # returns (rows, columns) for terminal size; sub get_terminal_size { + # undefined if not terminal attached + open(my $TTY, '>', '/dev/tty') + or return; + my $winsize = ''; - open(my $TTY, '>', '/dev/tty'); # undefined if output not going to terminal return unless (ioctl($TTY, &TIOCGWINSZ, $winsize)); close($TTY); @@ -40,15 +49,11 @@ sub get_terminal_size { sub get_interface_flags { my $name = shift; - my $SIOCGIFFLAGS = &SIOCGIFFLAGS; - die "SIOCGIFFLAGS not found" - unless defined($SIOCGIFFLAGS); - socket (my $sock, AF_INET, SOCK_DGRAM, 0) or die "open UDP socket failed: $!"; my $ifreq = pack('a16', $name); - ioctl($sock, $SIOCGIFFLAGS, $ifreq) + ioctl($sock, &SIOCGIFFLAGS, $ifreq) or return; #undef my (undef, $flags) = unpack('a16s', $ifreq); |