.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "IO::Interface 3pm" .TH IO::Interface 3pm "2018-11-01" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" IO::Interface \- Perl extension for access to network card configuration information .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # ====================== \& # the new, preferred API \& # ====================== \& \& use IO::Interface::Simple; \& \& my $if1 = IO::Interface::Simple\->new(\*(Aqeth0\*(Aq); \& my $if2 = IO::Interface::Simple\->new_from_address(\*(Aq127.0.0.1\*(Aq); \& my $if3 = IO::Interface::Simple\->new_from_index(1); \& \& my @interfaces = IO::Interface::Simple\->interfaces; \& \& for my $if (@interfaces) { \& print "interface = $if\en"; \& print "addr = ",$if\->address,"\en", \& "broadcast = ",$if\->broadcast,"\en", \& "netmask = ",$if\->netmask,"\en", \& "dstaddr = ",$if\->dstaddr,"\en", \& "hwaddr = ",$if\->hwaddr,"\en", \& "mtu = ",$if\->mtu,"\en", \& "metric = ",$if\->metric,"\en", \& "index = ",$if\->index,"\en"; \& \& print "is running\en" if $if\->is_running; \& print "is broadcast\en" if $if\->is_broadcast; \& print "is p\-to\-p\en" if $if\->is_pt2pt; \& print "is loopback\en" if $if\->is_loopback; \& print "is promiscuous\en" if $if\->is_promiscuous; \& print "is multicast\en" if $if\->is_multicast; \& print "is notrailers\en" if $if\->is_notrailers; \& print "is noarp\en" if $if\->is_noarp; \& } \& \& \& # =========== \& # the old API \& # =========== \& \& use IO::Socket; \& use IO::Interface qw(:flags); \& \& my $s = IO::Socket::INET\->new(Proto => \*(Aqudp\*(Aq); \& my @interfaces = $s\->if_list; \& \& for my $if (@interfaces) { \& print "interface = $if\en"; \& my $flags = $s\->if_flags($if); \& print "addr = ",$s\->if_addr($if),"\en", \& "broadcast = ",$s\->if_broadcast($if),"\en", \& "netmask = ",$s\->if_netmask($if),"\en", \& "dstaddr = ",$s\->if_dstaddr($if),"\en", \& "hwaddr = ",$s\->if_hwaddr($if),"\en"; \& \& print "is running\en" if $flags & IFF_RUNNING; \& print "is broadcast\en" if $flags & IFF_BROADCAST; \& print "is p\-to\-p\en" if $flags & IFF_POINTOPOINT; \& print "is loopback\en" if $flags & IFF_LOOPBACK; \& print "is promiscuous\en" if $flags & IFF_PROMISC; \& print "is multicast\en" if $flags & IFF_MULTICAST; \& print "is notrailers\en" if $flags & IFF_NOTRAILERS; \& print "is noarp\en" if $flags & IFF_NOARP; \& } \& \& my $interface = $s\->addr_to_interface(\*(Aq127.0.0.1\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" IO::Interface adds methods to IO::Socket objects that allows them to be used to retrieve and change information about the network interfaces on your system. In addition to the object-oriented access methods, you can use a function-oriented style. .PP \&\s-1THIS API IS DEPRECATED.\s0 Please see IO::Interface::Simple for the preferred way to get and set interface configuration information. .SS "Creating a Socket to Access Interface Information" .IX Subsection "Creating a Socket to Access Interface Information" You must create a socket before you can access interface information. The socket does not have to be connected to a remote site, or even used for communication. The simplest procedure is to create a \s-1UDP\s0 protocol socket: .PP .Vb 1 \& my $s = IO::Socket::INET\->new(Proto => \*(Aqudp\*(Aq); .Ve .PP The various IO::Interface functions will now be available as methods on this socket. .SS "Methods" .IX Subsection "Methods" .ie n .IP "@iflist = $s\->if_list" 4 .el .IP "\f(CW@iflist\fR = \f(CW$s\fR\->if_list" 4 .IX Item "@iflist = $s->if_list" The \fBif_list()\fR method will return a list of active interface names, for example \*(L"eth0\*(R" or \*(L"tu0\*(R". If no interfaces are configured and running, returns an empty list. .ie n .IP "$addr = $s\->if_addr($ifname [,$newaddr])" 4 .el .IP "\f(CW$addr\fR = \f(CW$s\fR\->if_addr($ifname [,$newaddr])" 4 .IX Item "$addr = $s->if_addr($ifname [,$newaddr])" \&\fBif_addr()\fR gets or sets the interface address. Call with the interface name to retrieve the address (in dotted decimal format). Call with a new address to set the interface. In the latter case, the routine will return a true value if the operation was successful. .Sp .Vb 2 \& my $oldaddr = $s\->if_addr(\*(Aqeth0\*(Aq); \& $s\->if_addr(\*(Aqeth0\*(Aq,\*(Aq192.168.8.10\*(Aq) || die "couldn\*(Aqt set address: $!"; .Ve .Sp Special case: the address of the pseudo-device \*(L"any\*(R" will return the \&\s-1IP\s0 address \*(L"0.0.0.0\*(R", which corresponds to the \s-1INADDR_ANY\s0 constant. .ie n .IP "$broadcast = $s\->if_broadcast($ifname [,$newbroadcast]" 4 .el .IP "\f(CW$broadcast\fR = \f(CW$s\fR\->if_broadcast($ifname [,$newbroadcast]" 4 .IX Item "$broadcast = $s->if_broadcast($ifname [,$newbroadcast]" Get or set the interface broadcast address. If the interface does not have a broadcast address, returns undef. .ie n .IP "$mask = $s\->if_netmask($ifname [,$newmask])" 4 .el .IP "\f(CW$mask\fR = \f(CW$s\fR\->if_netmask($ifname [,$newmask])" 4 .IX Item "$mask = $s->if_netmask($ifname [,$newmask])" Get or set the interface netmask. .ie n .IP "$dstaddr = $s\->if_dstaddr($ifname [,$newdest])" 4 .el .IP "\f(CW$dstaddr\fR = \f(CW$s\fR\->if_dstaddr($ifname [,$newdest])" 4 .IX Item "$dstaddr = $s->if_dstaddr($ifname [,$newdest])" Get or set the destination address for point-to-point interfaces. .ie n .IP "$hwaddr = $s\->if_hwaddr($ifname [,$newhwaddr])" 4 .el .IP "\f(CW$hwaddr\fR = \f(CW$s\fR\->if_hwaddr($ifname [,$newhwaddr])" 4 .IX Item "$hwaddr = $s->if_hwaddr($ifname [,$newhwaddr])" Get or set the hardware address for the interface. Currently only ethernet addresses in the form \*(L"00:60:2D:2D:51:70\*(R" are accepted. .ie n .IP "$flags = $s\->if_flags($ifname [,$newflags])" 4 .el .IP "\f(CW$flags\fR = \f(CW$s\fR\->if_flags($ifname [,$newflags])" 4 .IX Item "$flags = $s->if_flags($ifname [,$newflags])" Get or set the flags for the interface. The flags are a bitmask formed from a series of constants. See \*(L"Exportable constants\*(R" below. .ie n .IP "$ifname = $s\->addr_to_interface($ifaddr)" 4 .el .IP "\f(CW$ifname\fR = \f(CW$s\fR\->addr_to_interface($ifaddr)" 4 .IX Item "$ifname = $s->addr_to_interface($ifaddr)" Given an interface address in dotted form, returns the name of the interface associated with it. Special case: the \s-1INADDR_ANY\s0 address, 0.0.0.0 will return a pseudo-interface name of \*(L"any\*(R". .SS "\s-1EXPORT\s0" .IX Subsection "EXPORT" IO::Interface exports nothing by default. However, you can import the following symbol groups into your namespace: .PP .Vb 3 \& :functions Function\-oriented interface (see below) \& :flags Flag constants (see below) \& :all All of the above .Ve .SS "Function-Oriented Interface" .IX Subsection "Function-Oriented Interface" By importing the \*(L":functions\*(R" set, you can access IO::Interface in a function-oriented manner. This imports all the methods described above into your namespace. Example: .PP .Vb 2 \& use IO::Socket; \& use IO::Interface \*(Aq:functions\*(Aq; \& \& my $sock = IO::Socket::INET\->new(Proto=>\*(Aqudp\*(Aq); \& my @interfaces = if_list($sock); \& print "address = ",if_addr($sock,$interfaces[0]); .Ve .SS "Exportable constants" .IX Subsection "Exportable constants" The \*(L":flags\*(R" constant imports the following constants for use with the flags returned by \fBif_flags()\fR: .PP .Vb 10 \& IFF_ALLMULTI \& IFF_AUTOMEDIA \& IFF_BROADCAST \& IFF_DEBUG \& IFF_LOOPBACK \& IFF_MASTER \& IFF_MULTICAST \& IFF_NOARP \& IFF_NOTRAILERS \& IFF_POINTOPOINT \& IFF_PORTSEL \& IFF_PROMISC \& IFF_RUNNING \& IFF_SLAVE \& IFF_UP .Ve .PP This example determines whether interface 'tu0' supports multicasting: .PP .Vb 4 \& use IO::Socket; \& use IO::Interface \*(Aq:flags\*(Aq; \& my $sock = IO::Socket::INET\->new(Proto=>\*(Aqudp\*(Aq); \& print "can multicast!\en" if $sock\->if_flags & IFF_MULTICAST. .Ve .SH "AUTHOR" .IX Header "AUTHOR" Lincoln D. Stein Copyright 2001\-2014, Lincoln D. Stein. .PP This library is distributed under the Perl Artistic License 2.0. Please see \s-1LICENSE\s0 for more information. .SH "SUPPORT" .IX Header "SUPPORT" For feature requests, bug reports and code contributions, please use the GitHub repository at https://github.com/lstein/LibIO\-Interface\-Perl .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1), \fBIO::Socket\fR\|(3), \fBIO::Multicast\fR\|(3), IO::Interface::Simple