summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2018-01-02 18:43:32 +0100
committergregor herrmann <gregoa@debian.org>2018-01-02 18:43:32 +0100
commit6f9dff057fb710b1fef5606571a9605fccf77545 (patch)
treea6c3a15bcb26aaf978dba53ced543c5aef902966
parent5515bd833261d12ffd2437975b50ced95fdc1844 (diff)
parentc2f92406e4deb4386a1948d8f2efb9da711e421e (diff)
Update upstream source from tag 'upstream/0.16'
Update to upstream version '0.16' with Debian dir 6d71a9fb12a734a5f91d3f6f8c648b5410a26834
-rw-r--r--Changes4
-rw-r--r--MANIFEST3
-rw-r--r--META.json8
-rw-r--r--META.yml6
-rw-r--r--Makefile.PL6
-rw-r--r--README.md4
-rw-r--r--lib/Net/Ifconfig/Wrapper.pm1049
-rw-r--r--xt/test.pl172
8 files changed, 722 insertions, 530 deletions
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..0a0206a
--- /dev/null
+++ b/Changes
@@ -0,0 +1,4 @@
+2016-02-06 Kingpin <martin@localhost.localdomain>
+
+ * Wrapper.pm (if_ipaddr): force locale when running ifconfig command
+
diff --git a/MANIFEST b/MANIFEST
index 859a95b..7c20445 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,10 +1,11 @@
+Changes
lib/Net/Ifconfig/Wrapper.pm
Makefile.PL
MANIFEST This list of files
README
README.md
t/20_list.t
-t/test.pl
t/uni-ifconfig.pl
+xt/test.pl
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
diff --git a/META.json b/META.json
index 45d3a97..f4b9bfe 100644
--- a/META.json
+++ b/META.json
@@ -4,13 +4,13 @@
"Daniel Podolsky <tpaba@cpan.org>"
],
"dynamic_config" : 1,
- "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005",
+ "generated_by" : "ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
- "version" : "2"
+ "version" : 2
},
"name" : "Net-Ifconfig-Wrapper",
"no_index" : {
@@ -37,6 +37,6 @@
}
},
"release_status" : "stable",
- "version" : "0.14",
- "x_serialization_backend" : "JSON::PP version 2.27300"
+ "version" : 0.16,
+ "x_serialization_backend" : "JSON::PP version 2.94"
}
diff --git a/META.yml b/META.yml
index cabad72..3ee7696 100644
--- a/META.yml
+++ b/META.yml
@@ -7,7 +7,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005'
+generated_by: 'ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -19,5 +19,5 @@ no_index:
- inc
requires:
POSIX: '0'
-version: '0.14'
-x_serialization_backend: 'CPAN::Meta::YAML version 0.016'
+version: 0.16
+x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff --git a/Makefile.PL b/Makefile.PL
index 23d571b..8127232 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,4 +1,8 @@
use 5.008004;
+
+use warnings;
+use strict;
+
# TODO: convert to Module::Install
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
@@ -39,3 +43,5 @@ WriteMakefile(
(ABSTRACT_FROM => 'lib/Net/Ifconfig/Wrapper.pm', # retrieve abstract from module
AUTHOR => 'Daniel Podolsky <tpaba@cpan.org>') : ()),
);
+
+__END__
diff --git a/README.md b/README.md
index 9f5aa20..634d4a7 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,6 @@
# Net-Ifconfig-Wrapper
Perl module Net::Ifconfig::Wrapper
+
+written by Daniel Podolsky, tpaba@cpan.org
+
+maintained by Martin Thurn, mthurn@cpan.org
diff --git a/lib/Net/Ifconfig/Wrapper.pm b/lib/Net/Ifconfig/Wrapper.pm
index 8f6b3b8..1a3e35d 100644
--- a/lib/Net/Ifconfig/Wrapper.pm
+++ b/lib/Net/Ifconfig/Wrapper.pm
@@ -1,11 +1,10 @@
package Net::Ifconfig::Wrapper;
+use warnings;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @EXPORT_FAIL);
-$VERSION = 0.14;
-
-#$^W++;
+$VERSION = 0.16;
require Exporter;
@@ -102,173 +101,177 @@ my $Name2Index = undef;
my %Ifconfig = ();
my $RunCmd = sub($$)
- {
- my ($CName, $Iface, $Logic, $Addr, $Mask) = @_;
-
- my $Cmd = (defined($Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'ifconfig'}) ?
- $Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'ifconfig'} :
- $Ifconfig{$CName}{$^O}{'ifconfig'}).' 2>&1';
-
- #print "\n=== RunCmd ===\n\$CName: $CName, \$Iface: $Iface, \$Logic: $Logic, \$Addr: $Addr, \$Mask: $Mask\n";
-
- $Cmd =~ s{%Iface%}{$Iface}gsex;
- $Cmd =~ s{%Logic%}{$Logic}gsex;
- $Cmd =~ s{%Addr%}{$Addr}gsex;
- $Cmd =~ s{%Mask%}{$Mask}gsex;
-
- my $saveLang = $ENV{'LANG'} || '';
- $ENV{'LANG'} = 'C';
- my @Output = `$Cmd`;
- $ENV{'LANG'} = $saveLang;
-
- $@ = "Command '$Cmd', exit code '".(defined($?) ? $? : '!UNDEFINED!')."'".join("\t", @Output);
-
- $? ? return : return \@Output;
- };
+ {
+ my ($CName, $Iface, $Logic, $Addr, $Mask) = @_;
+
+ my $Cmd = (defined($Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'ifconfig'}) ?
+ $Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'ifconfig'} :
+ $Ifconfig{$CName}{$^O}{'ifconfig'}).' 2>&1';
+
+ #print "\n=== RunCmd ===\n\$CName: $CName, \$Iface: $Iface, \$Logic: $Logic, \$Addr: $Addr, \$Mask: $Mask\n";
+
+ $Cmd =~ s{%Iface%}{$Iface}gsex;
+ $Cmd =~ s{%Logic%}{$Logic}gsex;
+ $Cmd =~ s{%Addr%}{$Addr}gsex;
+ $Cmd =~ s{%Mask%}{$Mask}gsex;
+
+ my $saveLang = $ENV{'LANG'} || '';
+ $ENV{'LANG'} = 'C';
+ my @Output = `$Cmd`;
+ $ENV{'LANG'} = $saveLang;
+
+ $@ = "Command '$Cmd', exit code '".(defined($?) ? $? : '!UNDEFINED!')."'".join("\t", @Output);
+
+ $? ? return : return \@Output;
+ }; # RunCmd
my $SolarisList = sub($$$$)
-{
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- my $Output = &{$RunCmd}('list', '', '', '', '')
- or return;
-
- $Inet2Logic = {};
- $Logic2Inet = {};
-
- my $Iface = undef;
- my $Logic = undef;
- my $LogUp = undef;
- my $Info = {};
- foreach (@{$Output})
+ {
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ my $Output = &{$RunCmd}('list', '', '', '', '') or return;
+
+ $Inet2Logic = {};
+ $Logic2Inet = {};
+
+ my $Iface = undef;
+ my $Logic = undef;
+ my $LogUp = undef;
+ my $Info = {};
+ foreach (@{$Output})
{
- if (
- ($_ =~ m/\A([a-z]+\d+)(?:\:(\d+))?\:\s+flags=[^\<]+\<(?:\w+\,)*(up)?(?:\,\w+)*\>.*\n?\Z/io)
- ||
- ($_ =~ m/\A([a-z]+\d+)(?:\:(\d+))?\:\s+flags=[^\<]+\<(?:\w+(?:\,\w+)*)*\>.*\n?\Z/io)
- )
- {
- $Iface = $1;
- $Logic = defined($2) ? $2 : '';
- $LogUp = 1 && $3;
- #$Info->{$Iface}{'status'} = ($Info->{$Iface}{'status'} || $LogUp) ? 1 : 0;
- $Info->{$Iface}{'status'} = $Info->{$Iface}{'status'} || $LogUp;
- }
- elsif (!$Iface)
- {
- next;
- }
- elsif (
- ($_ =~ m/\A\s+inet\s+(\d{1,3}(?:\.\d{1,3}){3})\s+netmask\s+(?:0x)?([a-f\d]{8})(?:\s.*)?\n?\Z/io)
- ||
- 0
- )
- {
- $LogUp
- and $Info->{$Iface}{'inet'}{$1} = $Hex2Mask{$2};
- $Inet2Logic->{$Iface}{$1} = $Logic;
- $Logic2Inet->{$Iface}{$Logic} = $1;
- }
- elsif (($_ =~ m/\A\s+media\:?\s+(ethernet.*)\s*\n?\Z/io) && !$Info->{$Iface}{'ether'})
- {
- $Info->{$Iface}{'ether'} = $ETHERNET;
- if (!$Info->{$Iface}{'media'})
- {$Info->{$Iface}{'media'} = $1; };
- }
- elsif (($_ =~ m/\A\s+supported\s+media\:?\s+(.*)\s*\n?\Z/io) && !$Info->{$Iface}{'media'})
- {
- $Info->{$Iface}{'media'} = $1;
- }
- elsif ($_ =~ m/\A\s+ether\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})(?:\s.*)?\n?\Z/io)
- {
- $Info->{$Iface}{'ether'} = $1;
- };
- };
-
- return $Info;
- };
+ if (
+ ($_ =~ m/\A([a-z]+\d+)(?:\:(\d+))?\:\s+flags=[^\<]+\<(?:\w+\,)*(up)?(?:\,\w+)*\>.*\n?\Z/io)
+ ||
+ ($_ =~ m/\A([a-z]+\d+)(?:\:(\d+))?\:\s+flags=[^\<]+\<(?:\w+(?:\,\w+)*)*\>.*\n?\Z/io)
+ )
+ {
+ $Iface = $1;
+ $Logic = defined($2) ? $2 : '';
+ $LogUp = 1 && $3;
+ #$Info->{$Iface}{'status'} = ($Info->{$Iface}{'status'} || $LogUp) ? 1 : 0;
+ $Info->{$Iface}{'status'} = $Info->{$Iface}{'status'} || $LogUp;
+ }
+ elsif (!$Iface)
+ {
+ next;
+ }
+ elsif (
+ ($_ =~ m/\A\s+inet\s+(\d{1,3}(?:\.\d{1,3}){3})\s+netmask\s+(?:0x)?([a-f\d]{8})(?:\s.*)?\n?\Z/io)
+ ||
+ 0
+ )
+ {
+ $LogUp
+ and $Info->{$Iface}{'inet'}{$1} = $Hex2Mask{$2};
+ $Inet2Logic->{$Iface}{$1} = $Logic;
+ $Logic2Inet->{$Iface}{$Logic} = $1;
+ }
+ elsif (($_ =~ m/\A\s+media\:?\s+(ethernet.*)\s*\n?\Z/io) && !$Info->{$Iface}{'ether'})
+ {
+ $Info->{$Iface}{'ether'} = $ETHERNET;
+ if (!$Info->{$Iface}{'media'})
+ {$Info->{$Iface}{'media'} = $1; };
+ }
+ elsif (($_ =~ m/\A\s+supported\s+media\:?\s+(.*)\s*\n?\Z/io) && !$Info->{$Iface}{'media'})
+ {
+ $Info->{$Iface}{'media'} = $1;
+ }
+ elsif ($_ =~ m/\A\s+ether\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})(?:\s.*)?\n?\Z/io)
+ {
+ $Info->{$Iface}{'ether'} = $1;
+ };
+ };
+ return $Info;
+ }; # SolarisList
my $LinuxList = sub($$$$)
- {
- # warn " DDD start sub LinuxList...\n";
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- my $Output = &{$RunCmd}('list', '', '', '', '')
- or return;
-
- $Inet2Logic = {};
- $Logic2Inet = {};
-
- my $Iface = undef;
- my $Logic = undef;
- my $Info = {};
- foreach (@{$Output})
- {
- $DEBUG && warn " DDD looking at line of Output=$_";
- if (
- ($_ =~ m/\A([a-z0-9]+)(?:\:(\d+))?\s+link\s+encap\:(?:ethernet\s+hwaddr\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5}))?.*\n?\Z/io)
+ {
+ # warn " DDD start sub LinuxList...\n";
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ my $Output = &{$RunCmd}('list', '', '', '', '')
+ or return;
+
+ $Inet2Logic = {};
+ $Logic2Inet = {};
+
+ my $Iface = undef;
+ my $Logic = undef;
+ my $Info = {};
+ foreach (@{$Output})
+ {
+ $DEBUG && warn " DDD looking at line of Output=$_";
+ if (
+ ($_ =~ m/\A([a-z0-9]+)(?:\:(\d+))?\s+link\s+encap\:(?:ethernet\s+hwaddr\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5}))?.*\n?\Z/io)
+ ||
+ # German locale de_DE.UTF-8
+ ($_ =~ m/\A([a-z0-9]+)(?:\:(\d+))?\s+Link\s+encap\:(?:Ethernet\s+Hardware\s+Adresse\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5}))?.*\n?\Z/io)
+ )
+ {
+ $Iface = $1;
+ $Logic = defined($2) ? $2 : '';
+ defined($3)
+ and $Info->{$Iface}{'ether'} = $3;
+ $Info->{$Iface}{'status'} = 0;
+ }
+ elsif (
+ ($_ =~ m/\A([a-z0-9]+)(?:\:(\d+))?\:\s+flags=\d+<(\w+(?:,\w+)*)*>.*\n?\Z/io)
+ )
+ {
+ $Iface = $1;
+ $Logic = defined($2) ? $2 : '';
+ my $sFlags = $3;
+ $DEBUG && warn " DDD matched 'flags' line, Iface=$Iface, sFlags=$sFlags\n";
+ $Info->{$Iface}{'status'} = 1 if ($sFlags =~ m/\bUP\b/);
+ }
+ elsif (!$Iface)
+ {
+ next;
+ }
+ elsif (
+ # RHEL 6 et alia:
+ ($_ =~ m/\A\s+inet\s+addr\:(\d{1,3}(?:\.\d{1,3}){3})\s+(?:.*\s)?mask\:(\d{1,3}(?:\.\d{1,3}){3}).*\n?\Z/io)
+ ||
+ # RHEL 7 et alia:
+ ($_ =~ m/\A\s+inet\s+(\d{1,3}(?:\.\d{1,3}){3})\s+netmask\s+(\d{1,3}(?:\.\d{1,3}){3})(?:\s.*)?\n?\Z/io)
||
# German locale de_DE.UTF-8
- ($_ =~ m/\A([a-z0-9]+)(?:\:(\d+))?\s+Link\s+encap\:(?:Ethernet\s+Hardware\s+Adresse\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5}))?.*\n?\Z/io)
+ ($_ =~ m/\A\s+inet\s+Adresse\:(\d{1,3}(?:\.\d{1,3}){3})\s+(?:.*\s)?Maske\:(\d{1,3}(?:\.\d{1,3}){3}).*\n?\Z/io)
)
- {
- $Iface = $1;
- $Logic = defined($2) ? $2 : '';
- defined($3)
- and $Info->{$Iface}{'ether'} = $3;
- $Info->{$Iface}{'status'} = 0;
- }
- elsif (
- ($_ =~ m/\A([a-z0-9]+)\:\s+flags=\d+<(\w+(?:,\w+)*)*>.*\n?\Z/io)
- )
- {
- $Iface = $1;
- my $sFlags = $2;
- $DEBUG && warn " DDD matched 'flags' line, Iface=$Iface, sFlags=$sFlags\n";
- $Info->{$Iface}{'status'} = 1 if ($sFlags =~ m/\bUP\b/);
- }
- elsif (!$Iface)
- {
- next;
- }
- elsif (
- ($_ =~ m/\A\s+inet\s+addr\:(\d{1,3}(?:\.\d{1,3}){3})\s+(?:.*\s)?mask\:(\d{1,3}(?:\.\d{1,3}){3}).*\n?\Z/io)
- ||
- ($_ =~ m/\A\s+inet\s+(\d{1,3}(?:\.\d{1,3}){3})\s+netmask\s+(\d{1,3}(?:\.\d{1,3}){3})(?:\s.*)?\n?\Z/io)
- ||
- # German locale de_DE.UTF-8
- ($_ =~ m/\A\s+inet\s+Adresse\:(\d{1,3}(?:\.\d{1,3}){3})\s+(?:.*\s)?Maske\:(\d{1,3}(?:\.\d{1,3}){3}).*\n?\Z/io)
- )
- {
- my $sIP = $1;
- my $sNetmask = $2;
- $DEBUG && warn " DDD matched 'netmask' line, sIP=$sIP, sNetmask=$sNetmask\n";
- $Info->{$Iface}{'inet'}{$sIP} = $sNetmask;
- $Inet2Logic->{$Iface}{$sIP} = $Logic;
- $Logic2Inet->{$Iface}{$Logic} = $sIP;
- }
- elsif ($_ =~ m/\A\s+ether\s+([a-f0-9]{1,2}(?:\:[a-f0-9]{1,2}){5})(?:\s|\n|\Z)/io)
- {
- $Info->{$Iface}{'ether'} = $1;
- }
- elsif ($_ =~ m/\A\s+up(?:\s+[^\s]+)*\s*\n?\Z/io)
- {
- $DEBUG && warn " DDD matched 'up' line\n";
- $Info->{$Iface}{'status'} = 1;
- };
- };
-
- return $Info;
- };
-
-
+ {
+ my $sIP = $1;
+ my $sNetmask = $2;
+ $DEBUG && warn " DDD matched 'netmask' line, sIP=$sIP, sNetmask=$sNetmask\n";
+ $Info->{$Iface}{'inet'}{$sIP} = $sNetmask;
+ $Inet2Logic->{$Iface}{$sIP} = $Logic;
+ $Logic2Inet->{$Iface}{$Logic} = $sIP;
+ }
+ elsif ($_ =~ m/\A\s+ether\s+([a-f0-9]{1,2}(?:\:[a-f0-9]{1,2}){5})(?:\s|\n|\Z)/io)
+ {
+ $Info->{$Iface}{'ether'} = $1;
+ }
+ elsif ($_ =~ m/\A\s+up(?:\s+[^\s]+)*\s*\n?\Z/io)
+ {
+ $DEBUG && warn " DDD matched 'up' line\n";
+ $Info->{$Iface}{'status'} = 1;
+ };
+ };
+
+ return $Info;
+ }; # LinuxList
+
+# 64-bit Windows support added by Laurent Aml: use 'Q' for pointers,
+# and align to 8 bytes.
+my ($LQ, @pad) = (length(pack('P')) == 4) ? ('L') : ('Q', '_pad' => 'L');
my $st_IP_ADDR_STRING =
- ['Next' => 'L', #struct _IP_ADDR_STRING*
+ ['Next' => $LQ, #struct _IP_ADDR_STRING*
'IpAddress' => 'a16', #IP_ADDRESS_STRING
'IpMask' => 'a16', #IP_MASK_STRING
- 'Context' => 'L' #DWORD
+ 'Context' => 'L', #DWORD
+ @pad,
];
my $MAX_ADAPTER_NAME_LENGTH = 256;
@@ -276,7 +279,7 @@ my $MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
my $MAX_ADAPTER_ADDRESS_LENGTH = 8;
my $st_IP_ADAPTER_INFO =
- ['Next' => 'L', #struct _IP_ADAPTER_INFO*
+ ['Next' => $LQ, #struct _IP_ADAPTER_INFO*
'ComboIndex' => 'L', #DWORD
'AdapterName' => 'a'.($MAX_ADAPTER_NAME_LENGTH+4), #char[MAX_ADAPTER_NAME_LENGTH + 4]
'Description' => 'a'.($MAX_ADAPTER_DESCRIPTION_LENGTH+4), #char[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]
@@ -285,15 +288,17 @@ my $st_IP_ADAPTER_INFO =
'Index' => 'L', #DWORD
'Type' => 'L', #UINT
'DhcpEnabled' => 'L', #UINT
- 'CurrentIpAddress' => 'L', #PIP_ADDR_STRING
+ @pad,
+ 'CurrentIpAddress' => $LQ, #PIP_ADDR_STRING
'IpAddressList' => $st_IP_ADDR_STRING, #IP_ADDR_STRING
'GatewayList' => $st_IP_ADDR_STRING, #IP_ADDR_STRING
'DhcpServer' => $st_IP_ADDR_STRING, #IP_ADDR_STRING
'HaveWins' => 'L', #BOOL
+ @pad,
'PrimaryWinsServer' => $st_IP_ADDR_STRING, #IP_ADDR_STRING
'SecondaryWinsServer' => $st_IP_ADDR_STRING, #IP_ADDR_STRING
- 'LeaseObtained' => 'L', #time_t
- 'LeaseExpires' => 'L', #time_t
+ 'LeaseObtained' => $LQ, #time_t
+ 'LeaseExpires' => $LQ, #time_t
];
#my $st_MIB_IPADDRROW =
@@ -309,189 +314,190 @@ my $st_IP_ADAPTER_INFO =
my %UnpackStrCache = ();
my $UnpackStr = undef;
$UnpackStr = sub($$)
- {
- my ($Struct, $Repeat) = @_;
- $Repeat or $Repeat = 1;
-
- my $StructUpStr = '';
-
- if (!defined($UnpackStrCache{$Struct}))
- {
- for (my $RI = 1; defined($Struct->[$RI]); $RI += 2)
- {
- $StructUpStr .= ref($Struct->[$RI]) ?
- &{$UnpackStr}($Struct->[$RI], 1) :
- $Struct->[$RI];
- };
- $UnpackStrCache{$Struct} = $StructUpStr;
- }
- else
- { $StructUpStr = $UnpackStrCache{$Struct}; };
-
- my $UpStr = '';
- for (; $Repeat > 0; $Repeat--)
- { $UpStr .= $StructUpStr; };
-
- return $UpStr;
- };
+ {
+ my ($Struct, $Repeat) = @_;
+ $Repeat or $Repeat = 1;
+
+ my $StructUpStr = '';
+
+ if (!defined($UnpackStrCache{$Struct}))
+ {
+ for (my $RI = 1; defined($Struct->[$RI]); $RI += 2)
+ {
+ $StructUpStr .= ref($Struct->[$RI]) ?
+ &{$UnpackStr}($Struct->[$RI], 1) :
+ $Struct->[$RI];
+ };
+ $UnpackStrCache{$Struct} = $StructUpStr;
+ }
+ else
+ { $StructUpStr = $UnpackStrCache{$Struct}; };
+
+ my $UpStr = '';
+ for (; $Repeat > 0; $Repeat--)
+ { $UpStr .= $StructUpStr; };
+
+ return $UpStr;
+ }; # $Unpackstr
my $ShiftStruct = undef;
$ShiftStruct = sub($$)
- {
- my ($Array, $Struct) = @_;
-
- my $Result = {};
- #tie(%{$Result}, 'Tie::IxHash');
-
- for (my $RI = 0; defined($Struct->[$RI]); $RI += 2)
- {
- $Result->{$Struct->[$RI]} = ref($Struct->[$RI+1]) ?
- &{$ShiftStruct}($Array, $Struct->[$RI+1]) :
- shift(@{$Array});
- };
- return $Result;
- };
+ {
+ my ($Array, $Struct) = @_;
+
+ my $Result = {};
+ #tie(%{$Result}, 'Tie::IxHash');
+
+ for (my $RI = 0; defined($Struct->[$RI]); $RI += 2)
+ {
+ $Result->{$Struct->[$RI]} = ref($Struct->[$RI+1]) ?
+ &{$ShiftStruct}($Array, $Struct->[$RI+1]) :
+ shift(@{$Array});
+ };
+ return $Result;
+ };
my $UnpackStruct = sub($$)
- {
- my ($pBuff, $Struct) = @_;
-
- my $UpStr = &{$UnpackStr}($Struct);
-
- my @Array = unpack($UpStr, ${$pBuff});
-
- substr(${$pBuff}, 0, length(pack($UpStr)), '');
-
- return &{$ShiftStruct}(\@Array, $Struct);
- };
+ {
+ my ($pBuff, $Struct) = @_;
+
+ my $UpStr = &{$UnpackStr}($Struct);
+
+ my @Array = unpack($UpStr, ${$pBuff});
+
+ substr(${$pBuff}, 0, length(pack($UpStr)), '');
+
+ return &{$ShiftStruct}(\@Array, $Struct);
+ };
my $if_hwaddr = sub($$)
- {
- my($len, $addr) = @_;
- return join(':', map {sprintf '%02x', $_ } unpack('C' x $len, $addr));
- };
+ {
+ my($len, $addr) = @_;
+ return join(':', map {sprintf '%02x', $_ } unpack('C' x $len, $addr));
+ };
-sub if_ipaddr
- {
- my ($addr) = @_;
- return join(".", unpack("C4", pack("L", $addr)));
- };
+sub if_ipaddr {
+ my ($addr) = @_;
+ return join(".", unpack("C4", pack("L", $addr)));
+ };
my $Win32List = sub($$$$)
- {
- $Inet2Logic = undef;
- $Logic2Inet = undef;
- $Name2Index = undef;
-
- my $Buff = '';
- my $BuffLen = pack('L', 0);
-
- my $Res = $Win32API{'iphlpapi'}{'GetAdaptersInfo'}->Call(0, $BuffLen);
-
- while ($Res == $Win32_ERROR_BUFFER_OVERFLOW)
- {
- $Buff = "\0" x unpack("L", $BuffLen);
- $Res = $Win32API{'iphlpapi'}{'GetAdaptersInfo'}->Call($Buff, $BuffLen);
- };
-
- if ($Res != $Win32_NO_ERROR)
- {
- $! = $Res;
- $@ = "Error running 'GetAdaptersInfo' function: ".&{$Win32_FormatMessage}($Res);
- return;
- };
-
- my $Info = {};
-
- $Inet2Logic = {};
- $Logic2Inet = {};
- $Name2Index = {};
-
- while (1)
- {
- my $ADAPTER_INFO = &{$UnpackStruct}(\$Buff, $st_IP_ADAPTER_INFO);
-
- foreach my $Field ('AdapterName', 'Description')
- { $ADAPTER_INFO->{$Field} =~ s/\x00+\Z//o; };
-
- foreach my $AddrField ('IpAddressList', 'GatewayList', 'DhcpServer', 'PrimaryWinsServer', 'SecondaryWinsServer')
- {
- foreach my $Field ('IpAddress', 'IpMask')
- { $ADAPTER_INFO->{$AddrField}{$Field} =~ s/\x00+\Z//o; };
- };
-
-
- $ADAPTER_INFO->{'Address'} = &{$if_hwaddr}($ADAPTER_INFO->{'AddressLength'}, $ADAPTER_INFO->{'Address'});
-
- foreach my $IpList ('IpAddressList', 'GatewayList')
- {
- my $ADDR_STRING = $ADAPTER_INFO->{$IpList};
- $ADAPTER_INFO->{$IpList} = [$ADDR_STRING,];
- while ($ADDR_STRING->{'Next'})
- {
- $ADDR_STRING = &{$UnpackStruct}(\$Buff, $st_IP_ADDR_STRING);
- foreach my $Field ('IpAddress', 'IpMask')
- { $ADDR_STRING->{$Field} =~ s/\x00+\Z//o; };
- push(@{$ADAPTER_INFO->{$IpList}}, $ADDR_STRING);
- };
- };
-
- my $Iface = $ADAPTER_INFO->{'AdapterName'};
-
- $Info->{$Iface}{'descr'} = $ADAPTER_INFO->{'Description'};
- $Info->{$Iface}{'ether'} = $ADAPTER_INFO->{'Address'};
- $Info->{$Iface}{'status'} = 1;
-
- foreach my $Addr (@{$ADAPTER_INFO->{'IpAddressList'}})
- {
- ($Addr->{'IpAddress'} eq '0.0.0.0')
- and next;
- $Info->{$Iface}{'inet'}{$Addr->{'IpAddress'}} = $Addr->{'IpMask'};
- $Inet2Logic->{$Iface}{$Addr->{'IpAddress'}} = $Addr->{'Context'};
- $Logic2Inet->{$Iface}{$Addr->{'Context'}} = $Addr->{'IpAddress'};
- };
-
- $Name2Index->{$Iface} = $ADAPTER_INFO->{'Index'};
-
- $ADAPTER_INFO->{'Next'}
- or last;
- };
-
-
- #$Buff = '';
- #$BuffLen = pack('L', 0);
- #$Res = $Win32API{'iphlpapi'}{'GetIpAddrTable'}->Call($Buff, $BuffLen, 0);
- #
- #while ($Res == ERROR_INSUFFICIENT_BUFFER)
- # {
- # $Buff = "\0" x unpack("L", $BuffLen);
- # $Res = $Win32API{'iphlpapi'}{'GetIpAddrTable'}->Call($Buff, $BuffLen, 0);
- # };
- #
- #if ($Res != $Win32_NO_ERROR)
- # {
- # $! = $Res;
- # $@ = "Error running 'GetIpAddrTable' function: ".&{$Win32_FormatMessage}($Res);
- # return;
- # };
- #
- #my $IpAddrTable = &{$UnpackStruct}(\$Buff, ['Len' => 'L']);
- #my %Info1 = ();
- #for (; $IpAddrTable->{'Len'} > 0; $IpAddrTable->{'Len'}--)
- # {
- # my $IPADDRROW = &{$UnpackStruct}(\$Buff, $st_MIB_IPADDRROW);
- # $Info->{$IPADDRROW->{'dwIndex'}}
- # and next;
- # $Info1{$IPADDRROW->{'dwIndex'}}{'inet'}{if_ipaddr($IPADDRROW->{'dwAddr'})} = if_ipaddr($IPADDRROW->{'dwMask'});
- # };
- #
- #foreach my $Iface (keys(%Info1))
- # { $Info->{$Iface} = $Info1{$Iface}; };
-
- return wantarray ? %{$Info} : $Info;
- };
+ {
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+ $Name2Index = undef;
+
+ my $Buff = '';
+ my $BuffLen = pack('L', 0);
+
+ my $Res = $Win32API{'iphlpapi'}{'GetAdaptersInfo'}->Call(0, $BuffLen);
+
+ while ($Res == $Win32_ERROR_BUFFER_OVERFLOW)
+ {
+ $Buff = "\0" x unpack("L", $BuffLen);
+ $Res = $Win32API{'iphlpapi'}{'GetAdaptersInfo'}->Call($Buff, $BuffLen);
+ } # while
+
+ if ($Res != $Win32_NO_ERROR)
+ {
+ $! = $Res;
+ $@ = "Error running 'GetAdaptersInfo' function: ".&{$Win32_FormatMessage}($Res);
+ return;
+ } # if
+
+ my $Info = {};
+
+ $Inet2Logic = {};
+ $Logic2Inet = {};
+ $Name2Index = {};
+
+ while (1)
+ {
+ my $ADAPTER_INFO = &{$UnpackStruct}(\$Buff, $st_IP_ADAPTER_INFO);
+
+ foreach my $Field ('AdapterName', 'Description')
+ { $ADAPTER_INFO->{$Field} =~ s/\x00+\Z//o; };
+
+ foreach my $AddrField ('IpAddressList', 'GatewayList', 'DhcpServer', 'PrimaryWinsServer', 'SecondaryWinsServer')
+ {
+ foreach my $Field ('IpAddress', 'IpMask')
+ { $ADAPTER_INFO->{$AddrField}{$Field} =~ s/\x00+\Z//o; };
+ };
+
+
+ $ADAPTER_INFO->{'Address'} = &{$if_hwaddr}($ADAPTER_INFO->{'AddressLength'}, $ADAPTER_INFO->{'Address'});
+
+ foreach my $IpList ('IpAddressList', 'GatewayList')
+ {
+ my $ADDR_STRING = $ADAPTER_INFO->{$IpList};
+ $ADAPTER_INFO->{$IpList} = [$ADDR_STRING,];
+ while ($ADDR_STRING->{'Next'})
+ {
+ $ADDR_STRING = &{$UnpackStruct}(\$Buff, $st_IP_ADDR_STRING);
+ foreach my $Field ('IpAddress', 'IpMask')
+ {
+ $ADDR_STRING->{$Field} =~ s/\x00+\Z//o;
+ } # foreach
+ push(@{$ADAPTER_INFO->{$IpList}}, $ADDR_STRING);
+ } # while
+ } # foreach
+
+ my $Iface = $ADAPTER_INFO->{'AdapterName'};
+
+ $Info->{$Iface}{'descr'} = $ADAPTER_INFO->{'Description'};
+ $Info->{$Iface}{'ether'} = $ADAPTER_INFO->{'Address'};
+ $Info->{$Iface}{'status'} = 1;
+
+ foreach my $Addr (@{$ADAPTER_INFO->{'IpAddressList'}})
+ {
+ ($Addr->{'IpAddress'} eq '0.0.0.0')
+ and next;
+ $Info->{$Iface}{'inet'}{$Addr->{'IpAddress'}} = $Addr->{'IpMask'};
+ $Inet2Logic->{$Iface}{$Addr->{'IpAddress'}} = $Addr->{'Context'};
+ $Logic2Inet->{$Iface}{$Addr->{'Context'}} = $Addr->{'IpAddress'};
+ } # foreach
+
+ $Name2Index->{$Iface} = $ADAPTER_INFO->{'Index'};
+
+ $ADAPTER_INFO->{'Next'}
+ or last;
+ } # while
+
+
+ #$Buff = '';
+ #$BuffLen = pack('L', 0);
+ #$Res = $Win32API{'iphlpapi'}{'GetIpAddrTable'}->Call($Buff, $BuffLen, 0);
+ #
+ #while ($Res == ERROR_INSUFFICIENT_BUFFER)
+ # {
+ # $Buff = "\0" x unpack("L", $BuffLen);
+ # $Res = $Win32API{'iphlpapi'}{'GetIpAddrTable'}->Call($Buff, $BuffLen, 0);
+ # };
+ #
+ #if ($Res != $Win32_NO_ERROR)
+ # {
+ # $! = $Res;
+ # $@ = "Error running 'GetIpAddrTable' function: ".&{$Win32_FormatMessage}($Res);
+ # return;
+ # };
+ #
+ #my $IpAddrTable = &{$UnpackStruct}(\$Buff, ['Len' => 'L']);
+ #my %Info1 = ();
+ #for (; $IpAddrTable->{'Len'} > 0; $IpAddrTable->{'Len'}--)
+ # {
+ # my $IPADDRROW = &{$UnpackStruct}(\$Buff, $st_MIB_IPADDRROW);
+ # $Info->{$IPADDRROW->{'dwIndex'}}
+ # and next;
+ # $Info1{$IPADDRROW->{'dwIndex'}}{'inet'}{if_ipaddr($IPADDRROW->{'dwAddr'})} = if_ipaddr($IPADDRROW->{'dwMask'});
+ # };
+ #
+ #foreach my $Iface (keys(%Info1))
+ # { $Info->{$Iface} = $Info1{$Iface}; };
+
+ return wantarray ? %{$Info} : $Info;
+ }; # Win32List
@@ -511,92 +517,92 @@ $Ifconfig{'list'}{'cygwin'} = $Ifconfig{'list'}{'MSWin32'};
my $UpDown = sub($$$$)
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
-
- if (!(defined($Iface) && defined($Addr) && defined($Mask)))
- {
- $@ = "Command '$CName': interface, inet address and netmask have to be defined";
- return;
- };
-
- my $Output = &{$RunCmd}($CName, $Iface, '', $Addr, $Mask);
-
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- $Output ? return $Output : return;
- };
+ {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+
+ if (!(defined($Iface) && defined($Addr) && defined($Mask)))
+ {
+ $@ = "Command '$CName': interface, inet address and netmask have to be defined";
+ return;
+ };
+
+ my $Output = &{$RunCmd}($CName, $Iface, '', $Addr, $Mask);
+
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ $Output ? return $Output : return;
+ }; # $UpDown
my $UpDownNewLog = sub($$$$)
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
-
- if (!(defined($Iface) && defined($Addr) && defined($Mask)))
- {
- $@ = "Command '$CName': interface, inet address and netmask have to be defined";
- return;
- };
-
- defined($Inet2Logic)
- or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
- &{$Ifconfig{'list'}{$^O}{'function'}}())
- or return;
-
- my $Logic = $Inet2Logic->{$Iface}{$Addr};
-
- my $RunIndex = 1;
- for(; !defined($Logic); $RunIndex++)
- {
- if ($RunIndex > $MAXLOGIC)
- {
- $@ = "Command '$CName': maximum number of logic interfaces ($MAXLOGIC) on interface '$Iface' exceeded";
- return;
- };
- defined($Logic2Inet->{$Iface}{$RunIndex})
- or $Logic = $RunIndex;
- };
-
- my $Output = &{$RunCmd}($CName, $Iface, $Logic, $Addr, $Mask);
-
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- $Output ? return $Output : return;
- };
+ {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+
+ if (!(defined($Iface) && defined($Addr) && defined($Mask)))
+ {
+ $@ = "Command '$CName': interface, inet address and netmask have to be defined";
+ return;
+ };
+
+ defined($Inet2Logic)
+ or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
+ &{$Ifconfig{'list'}{$^O}{'function'}}())
+ or return;
+
+ my $Logic = $Inet2Logic->{$Iface}{$Addr};
+
+ my $RunIndex = 1;
+ for(; !defined($Logic); $RunIndex++)
+ {
+ if ($RunIndex > $MAXLOGIC)
+ {
+ $@ = "Command '$CName': maximum number of logic interfaces ($MAXLOGIC) on interface '$Iface' exceeded";
+ return;
+ };
+ defined($Logic2Inet->{$Iface}{$RunIndex})
+ or $Logic = $RunIndex;
+ };
+
+ my $Output = &{$RunCmd}($CName, $Iface, $Logic, $Addr, $Mask);
+
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ $Output ? return $Output : return;
+ }; # $UpDownNewLog
my $UpDownReqLog = sub($$$$)
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
-
- if (!(defined($Iface) && defined($Addr) && defined($Mask)))
- {
- $@ = "Command '$CName': interface, inet address and netmask have to be defined";
- return;
- };
-
- defined($Inet2Logic)
- or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
- &{$Ifconfig{'list'}{$^O}{'function'}}())
- or return;
-
- my $Logic = $Inet2Logic->{$Iface}{$Addr};
-
- if (!defined($Logic))
- {
- $@ = "Command '$CName': can not get logic interface for interface '$Iface', inet address '$Addr'";
- return;
- };
-
- my $Output = &{$RunCmd}($CName, $Iface, $Logic, $Addr, $Mask);
-
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- $Output ? return $Output : return;
- };
+ {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+
+ if (!(defined($Iface) && defined($Addr) && defined($Mask)))
+ {
+ $@ = "Command '$CName': interface, inet address and netmask have to be defined";
+ return;
+ };
+
+ defined($Inet2Logic)
+ or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
+ &{$Ifconfig{'list'}{$^O}{'function'}}())
+ or return;
+
+ my $Logic = $Inet2Logic->{$Iface}{$Addr};
+
+ if (!defined($Logic))
+ {
+ $@ = "Command '$CName': can not get logic interface for interface '$Iface', inet address '$Addr'";
+ return;
+ };
+
+ my $Output = &{$RunCmd}($CName, $Iface, $Logic, $Addr, $Mask);
+
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ $Output ? return $Output : return;
+ }; # $UpDownReqLog
#my $Win32UpDown = sub($$)
# {
@@ -631,104 +637,104 @@ my $UpDownReqLog = sub($$$$)
my $PackIP = sub($)
- {
- my @Bytes = split('\.', $_[0]);
- return unpack("L", pack('C4', @Bytes));
- };
+ {
+ my @Bytes = split('\.', $_[0]);
+ return unpack("L", pack('C4', @Bytes));
+ };
my $Win32AddAlias = sub($$$$)
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
-
- if (!(defined($Iface) && defined($Addr) && defined($Mask)))
- {
- $@ = "Command '$CName': interface, inet address and netmask have to be defined";
- return;
- };
-
- defined($Inet2Logic)
- or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
- &{$Ifconfig{'list'}{$^O}{'function'}}())
- or return;
-
- my $NTEContext = pack('L', 0);
- my $NTEInstance = pack('L', 0);
-
- my $Index = $Name2Index->{$Iface};
-
- if (!defined($Index))
- {
- $@ = "Command '$CName': can not get interface index for interface '$Iface'";
- return;
- };
-
- my $Res = $Win32API{'iphlpapi'}{'AddIPAddress'}->Call(&{$PackIP}($Addr), &{$PackIP}($Mask), $Index, $NTEContext, $NTEInstance);
-
- if ($Res != $Win32_NO_ERROR)
- {
- $! = $Res;
- $@ = &{$Win32_FormatMessage}($Res)
- or $@ = 'Unknown error :(';
- return;
- };
-
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- return ['Command completed successfully'];
- };
+ {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+
+ if (!(defined($Iface) && defined($Addr) && defined($Mask)))
+ {
+ $@ = "Command '$CName': interface, inet address and netmask have to be defined";
+ return;
+ };
+
+ defined($Inet2Logic)
+ or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
+ &{$Ifconfig{'list'}{$^O}{'function'}}())
+ or return;
+
+ my $NTEContext = pack('L', 0);
+ my $NTEInstance = pack('L', 0);
+
+ my $Index = $Name2Index->{$Iface};
+
+ if (!defined($Index))
+ {
+ $@ = "Command '$CName': can not get interface index for interface '$Iface'";
+ return;
+ };
+
+ my $Res = $Win32API{'iphlpapi'}{'AddIPAddress'}->Call(&{$PackIP}($Addr), &{$PackIP}($Mask), $Index, $NTEContext, $NTEInstance);
+
+ if ($Res != $Win32_NO_ERROR)
+ {
+ $! = $Res;
+ $@ = &{$Win32_FormatMessage}($Res)
+ or $@ = 'Unknown error :(';
+ return;
+ };
+
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ return ['Command completed successfully'];
+ };
my $Win32RemAlias = sub($$$$)
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
-
- if (!(defined($Iface) && defined($Addr) && defined($Mask)))
- {
- $@ = "Command '$CName': interface, inet address and netmask have to be defined";
- return;
- };
-
- defined($Inet2Logic)
- or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
- &{$Ifconfig{'list'}{$^O}{'function'}}())
- or return;
-
- my $Logic = $Inet2Logic->{$Iface}{$Addr};
-
- if (!defined($Logic))
- {
- $@ = "Command '$CName': can not get logic interface for interface '$Iface', inet address '$Addr'";
- return;
- };
-
- my $Res = $Win32API{'iphlpapi'}{'DeleteIPAddress'}->Call($Logic);
-
- if ($Res != $Win32_NO_ERROR)
- {
- $! = $Res;
- $@ = &{$Win32_FormatMessage}($Res);
- return;
- };
-
- $Inet2Logic = undef;
- $Logic2Inet = undef;
-
- return ['Command completed successfully'];
- };
+ {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+
+ if (!(defined($Iface) && defined($Addr) && defined($Mask)))
+ {
+ $@ = "Command '$CName': interface, inet address and netmask have to be defined";
+ return;
+ };
+
+ defined($Inet2Logic)
+ or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
+ &{$Ifconfig{'list'}{$^O}{'function'}}())
+ or return;
+
+ my $Logic = $Inet2Logic->{$Iface}{$Addr};
+
+ if (!defined($Logic))
+ {
+ $@ = "Command '$CName': can not get logic interface for interface '$Iface', inet address '$Addr'";
+ return;
+ };
+
+ my $Res = $Win32API{'iphlpapi'}{'DeleteIPAddress'}->Call($Logic);
+
+ if ($Res != $Win32_NO_ERROR)
+ {
+ $! = $Res;
+ $@ = &{$Win32_FormatMessage}($Res);
+ return;
+ };
+
+ $Inet2Logic = undef;
+ $Logic2Inet = undef;
+
+ return ['Command completed successfully'];
+ };
$Ifconfig{'inet'} = {'solaris' => {'ifconfig' => '/sbin/ifconfig %Iface% inet %Addr% netmask %Mask% up',
'function' => $UpDown},
-# 'MSWin32' => {'ifconfig' => '',
-# 'function' => $Win32Inet,},
+ # 'MSWin32' => {'ifconfig' => '',
+ # 'function' => $Win32Inet,},
};
$Ifconfig{'inet'}{'freebsd'} = $Ifconfig{'inet'}{'solaris'};
$Ifconfig{'inet'}{'openbsd'} = $Ifconfig{'inet'}{'solaris'};
$Ifconfig{'inet'}{'linux'} = $Ifconfig{'inet'}{'solaris'};
$Ifconfig{'inet'}{'darwin'} = $Ifconfig{'inet'}{'solaris'};
-
+
$Ifconfig{'up'} = $Ifconfig{'inet'};
$Ifconfig{'down'}{'solaris'} = {'ifconfig' => '/sbin/ifconfig %Iface% down',
@@ -770,27 +776,26 @@ $Ifconfig{'-alias'}{'darwin'} = $Ifconfig{'-alias'}{'freebsd'};
$Ifconfig{'-alias'}{'solaris'}{'SunOS'}{'5.9'}{'ifconfig'} = '/sbin/ifconfig %Iface%:%Logic% unplumb';
-sub Ifconfig
- {
- my ($CName, $Iface, $Addr, $Mask) = @_;
- if (!($CName && $Ifconfig{$CName} && $Ifconfig{$CName}{$^O}))
- {
- $@ = "Command '$CName' is not defined for system '$^O'";
- return;
- };
-
- defined($Inet2Logic)
- or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
- &{$Ifconfig{'list'}{$^O}{'function'}}())
- or return;
-
- my $Output = (defined($Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'function'}) ?
- &{$Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'function'}}($CName, $Iface, $Addr, $Mask) :
- &{$Ifconfig{$CName}{$^O}{'function'}}($CName, $Iface, $Addr, $Mask));
-
- $Output ? return $Output : return;
- };
+sub Ifconfig {
+ my ($CName, $Iface, $Addr, $Mask) = @_;
+ if (!($CName && $Ifconfig{$CName} && $Ifconfig{$CName}{$^O}))
+ {
+ $@ = "Command '$CName' is not defined for system '$^O'";
+ return;
+ };
+
+ defined($Inet2Logic)
+ or (defined($Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{'list'}{$^O}{$OsName}{$OsVers}{'function'}}() :
+ &{$Ifconfig{'list'}{$^O}{'function'}}())
+ or return;
+
+ my $Output = (defined($Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'function'}) ?
+ &{$Ifconfig{$CName}{$^O}{$OsName}{$OsVers}{'function'}}($CName, $Iface, $Addr, $Mask) :
+ &{$Ifconfig{$CName}{$^O}{'function'}}($CName, $Iface, $Addr, $Mask));
+
+ $Output ? return $Output : return;
+ }
1;
diff --git a/xt/test.pl b/xt/test.pl
new file mode 100644
index 0000000..8ec72cd
--- /dev/null
+++ b/xt/test.pl
@@ -0,0 +1,172 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl test.pl'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test;
+BEGIN { plan tests => 5 };
+
+$^W++;
+
+my %IfCfgCmd = ('freebsd' => '/sbin/ifconfig -a',
+ 'solaris' => '/sbin/ifconfig -a',
+ 'openbsd' => '/sbin/ifconfig -A',
+ 'linux' => '/sbin/ifconfig -a',
+ 'darwin' => '/sbin/ifconfig -a',
+ );
+
+print 'Loading Net::Ifconfig::Wrapper........';
+
+use Net::Ifconfig::Wrapper;
+
+ok(1); # If we made it this far, we're ok.
+
+
+
+print 'Geting information about interfaces...';
+
+my $Info = Net::Ifconfig::Wrapper::Ifconfig('list')
+ or die $@;
+
+ok(1);
+
+if ($IfCfgCmd{$^O})
+ {
+ print "\n== '".$IfCfgCmd{$^O}. "' command output ==\n";
+ system($IfCfgCmd{$^O});
+ print "======================================\n";
+ };
+
+print "\n== Net\:\:Ifconfig\:\:Wrapper info output ==\n";
+foreach (sort(keys(%{$Info})))
+ { print IfaceInfo($Info, $_); };
+print "======================================\n";
+
+print "Is Net\:\:Ifconfig\:\:Wrapper info output correct? Y/N:";
+
+while (<STDIN>)
+ {
+ $_ =~ m/\A\s*y(es)?\s*\n?\Z/i
+ and last;
+ $_ =~ m/\A\s*n(o)?\s*\n?\Z/i
+ and die "Net\:\:Ifconfig\:\:Wrapper info is incorrect!";
+ print "Is Net\:\:Ifconfig\:\:Wrapper info output correct? Y/N:";
+ };
+
+print "\nInformation displayed correctly.......";
+
+ok(1);
+
+
+
+if (($^O eq "MSWin32") || ($> == 0))
+ {
+ print "\nPlease choose the interface for add/remove alias function test\n";
+
+ my @Ifaces = ('skip test');
+
+ push(@Ifaces, sort(keys(%{$Info})));
+
+ my $DefIface = '';
+
+ for (my $RI = 0; defined($Ifaces[$RI]); $RI++)
+ {
+ (($Ifaces[$RI] =~ m/\Alo/i) && !length($DefIface))
+ and $DefIface = $RI;
+ print "$RI:\t".$Ifaces[$RI]."\n";
+ };
+
+ print "($DefIface):";
+
+ while (<STDIN>)
+ {
+ if (($_ =~ m/\A\s*\n?\Z/i) && length($DefIface))
+ { last; }
+ elsif (($_ =~ m/\A\s*(\d+)\s*\n?\Z/i) && defined($Ifaces[$1]))
+ {
+ $DefIface = $1;
+ last;
+ };
+ print "Please choose the interface for add/remove alias function tests\n";
+ for (my $RI = 0; defined($Ifaces[$RI]); $RI++)
+ { print "$RI:\t".$Ifaces[$RI]."\n"; };
+ print "($DefIface):";
+ };
+
+ if (!$DefIface)
+ {
+ print "add/remove alias function tests (4,5) skipped\n";
+ exit 0;
+ };
+
+ my $Addr = '192.168.192.168';
+ my $Mask = '255.255.255.0';
+
+ print "Please choose address and mask for test alias\n($Addr:$Mask):";
+
+ while (<STDIN>)
+ {
+ $_ =~ m/\A\s*\n?\Z/i
+ and last;
+ if ($_ =~ m/\A\s*(\d{1,3}(?:\.\d{1,3}){3})\s*\:?\s*(\d{1,3}(?:\.\d{1,3}){3})\s*\n?\Z/i)
+ {
+ $Addr = $1;
+ $Mask = $2;
+ last;
+ };
+ print "Please choose address and mask for test alias\n($Addr:$Mask):";
+ };
+ print "\nAdding alias '$Addr:$Mask' to interface ".$Ifaces[$DefIface]."...";
+
+ Net::Ifconfig::Wrapper::Ifconfig('+alias', $Ifaces[$DefIface], $Addr, $Mask)
+ or die $@;
+
+ $Info = Net::Ifconfig::Wrapper::Ifconfig('list')
+ or die $@;
+
+ defined($Info->{$Ifaces[$DefIface]}->{'inet'}->{$Addr}) &&
+ ($Info->{$Ifaces[$DefIface]}->{'inet'}->{$Addr} eq $Mask)
+ or die "Can not find recently added address '$Addr:$Mask' on interface ".$Ifaces[$DefIface];
+
+ ok(1);
+
+ print "Removing alias '$Addr:$Mask' from interface ".$Ifaces[$DefIface]."...";
+
+ Net::Ifconfig::Wrapper::Ifconfig('-alias', $Ifaces[$DefIface], $Addr, '')
+ or die $@;
+
+ $Info = Net::Ifconfig::Wrapper::Ifconfig('list')
+ or die $@;
+
+ defined($Info->{$Ifaces[$DefIface]}->{'inet'}->{$Addr})
+ and die "Can not remove recently added address '$Addr:$Mask' from interface ".$Ifaces[$DefIface];
+
+ ok(1);
+ }
+else
+ {
+ print "add/remove alias function tests (4,5) skipped: insufficient privileges\n";
+ exit 0;
+ };
+
+#exit 0;
+
+sub IfaceInfo
+ {
+ my ($Info, $Iface) = @_;
+
+ my $Res = "$Iface:\t".($Info->{$Iface}->{'status'} ? 'UP' : 'DOWN')."\n";
+
+ while (my ($Addr, $Mask) = each(%{$Info->{$Iface}->{'inet'}}))
+ { $Res .= sprintf("\tinet %-15s mask $Mask\n", $Addr); };
+
+ $Info->{$Iface}->{'ether'}
+ and $Res .= "\tether ".$Info->{$Iface}->{'ether'}."\n";
+
+ $Info->{$Iface}->{'descr'}
+ and $Res .= "\tdescr '".$Info->{$Iface}->{'descr'}."'\n";
+
+ return $Res;
+ }; \ No newline at end of file