1Interface(3)          User Contributed Perl Documentation         Interface(3)
2
3
4

NAME

6       IO::Interface - Perl extension for access to network card configuration
7       information
8

SYNOPSIS

10        # ======================
11        # the new, preferred API
12        # ======================
13
14        use IO::Interface::Simple;
15
16        my $if1   = IO::Interface::Simple->new('eth0');
17        my $if2   = IO::Interface::Simple->new_from_address('127.0.0.1');
18        my $if3   = IO::Interface::Simple->new_from_index(1);
19
20        my @interfaces = IO::Interface::Simple->interfaces;
21
22        for my $if (@interfaces) {
23           print "interface = $if\n";
24           print "addr =      ",$if->address,"\n",
25                 "broadcast = ",$if->broadcast,"\n",
26                 "netmask =   ",$if->netmask,"\n",
27                 "dstaddr =   ",$if->dstaddr,"\n",
28                 "hwaddr =    ",$if->hwaddr,"\n",
29                 "mtu =       ",$if->mtu,"\n",
30                 "metric =    ",$if->metric,"\n",
31                 "index =     ",$if->index,"\n";
32
33           print "is running\n"     if $if->is_running;
34           print "is broadcast\n"   if $if->is_broadcast;
35           print "is p-to-p\n"      if $if->is_pt2pt;
36           print "is loopback\n"    if $if->is_loopback;
37           print "is promiscuous\n" if $if->is_promiscuous;
38           print "is multicast\n"   if $if->is_multicast;
39           print "is notrailers\n"  if $if->is_notrailers;
40           print "is noarp\n"       if $if->is_noarp;
41         }
42
43         # ===========
44         # the old API
45         # ===========
46
47         use IO::Socket;
48         use IO::Interface qw(:flags);
49
50         my $s = IO::Socket::INET->new(Proto => 'udp');
51         my @interfaces = $s->if_list;
52
53         for my $if (@interfaces) {
54           print "interface = $if\n";
55           my $flags = $s->if_flags($if);
56           print "addr =      ",$s->if_addr($if),"\n",
57                 "broadcast = ",$s->if_broadcast($if),"\n",
58                 "netmask =   ",$s->if_netmask($if),"\n",
59                 "dstaddr =   ",$s->if_dstaddr($if),"\n",
60                 "hwaddr =    ",$s->if_hwaddr($if),"\n";
61
62           print "is running\n"     if $flags & IFF_RUNNING;
63           print "is broadcast\n"   if $flags & IFF_BROADCAST;
64           print "is p-to-p\n"      if $flags & IFF_POINTOPOINT;
65           print "is loopback\n"    if $flags & IFF_LOOPBACK;
66           print "is promiscuous\n" if $flags & IFF_PROMISC;
67           print "is multicast\n"   if $flags & IFF_MULTICAST;
68           print "is notrailers\n"  if $flags & IFF_NOTRAILERS;
69           print "is noarp\n"       if $flags & IFF_NOARP;
70         }
71
72         my $interface = $s->addr_to_interface('127.0.0.1');
73

DESCRIPTION

75       IO::Interface adds methods to IO::Socket objects that allows them to be
76       used to retrieve and change information about the network interfaces on
77       your system.  In addition to the object-oriented access methods, you
78       can use a function-oriented style.
79
80       THIS API IS DEPRECATED. Please see IO::Interface::Simple for the pre‐
81       ferred way to get and set interface configuration information.
82
83       Creating a Socket to Access Interface Information
84
85       You must create a socket before you can access interface information.
86       The socket does not have to be connected to a remote site, or even used
87       for communication.  The simplest procedure is to create a UDP protocol
88       socket:
89
90         my $s = IO::Socket::INET->new(Proto => 'udp');
91
92       The various IO::Interface functions will now be available as methods on
93       this socket.
94
95       Methods
96
97       @iflist = $s->if_list
98           The if_list() method will return a list of active interface names,
99           for example "eth0" or "tu0".  If no interfaces are configured and
100           running, returns an empty list.
101
102       $addr = $s->if_addr($ifname [,$newaddr])
103           if_addr() gets or sets the interface address.  Call with the inter‐
104           face name to retrieve the address (in dotted decimal format).  Call
105           with a new address to set the interface.  In the latter case, the
106           routine will return a true value if the operation was successful.
107
108             my $oldaddr = $s->if_addr('eth0');
109             $s->if_addr('eth0','192.168.8.10') ⎪⎪ die "couldn't set address: $!";
110
111           Special case: the address of the pseudo-device "any" will return
112           the IP address "0.0.0.0", which corresponds to the INADDR_ANY con‐
113           stant.
114
115       $broadcast = $s->if_broadcast($ifname [,$newbroadcast]
116           Get or set the interface broadcast address.  If the interface does
117           not have a broadcast address, returns undef.
118
119       $mask = $s->if_netmask($ifname [,$newmask])
120           Get or set the interface netmask.
121
122       $dstaddr = $s->if_dstaddr($ifname [,$newdest])
123           Get or set the destination address for point-to-point interfaces.
124
125       $hwaddr = $s->if_hwaddr($ifname [,$newhwaddr])
126           Get or set the hardware address for the interface. Currently only
127           ethernet addresses in the form "00:60:2D:2D:51:70" are accepted.
128
129       $flags = $s->if_flags($ifname [,$newflags])
130           Get or set the flags for the interface.  The flags are a bitmask
131           formed from a series of constants.  See "Exportable constants"
132           below.
133
134       $ifname = $s->addr_to_interface($ifaddr)
135           Given an interface address in dotted form, returns the name of the
136           interface associated with it.  Special case: the INADDR_ANY
137           address, 0.0.0.0 will return a pseudo-interface name of "any".
138
139       EXPORT
140
141       IO::Interface exports nothing by default.  However, you can import the
142       following symbol groups into your namespace:
143
144         :functions   Function-oriented interface (see below)
145         :flags       Flag constants (see below)
146         :all         All of the above
147
148       Function-Oriented Interface
149
150       By importing the ":functions" set, you can access IO::Interface in a
151       function-oriented manner.  This imports all the methods described above
152       into your namespace.  Example:
153
154         use IO::Socket;
155         use IO::Interface ':functions';
156
157         my $sock = IO::Socket::INET->new(Proto=>'udp');
158         my @interfaces = if_list($sock);
159         print "address = ",if_addr($sock,$interfaces[0]);
160
161       Exportable constants
162
163       The ":flags" constant imports the following constants for use with the
164       flags returned by if_flags():
165
166         IFF_ALLMULTI
167         IFF_AUTOMEDIA
168         IFF_BROADCAST
169         IFF_DEBUG
170         IFF_LOOPBACK
171         IFF_MASTER
172         IFF_MULTICAST
173         IFF_NOARP
174         IFF_NOTRAILERS
175         IFF_POINTOPOINT
176         IFF_PORTSEL
177         IFF_PROMISC
178         IFF_RUNNING
179         IFF_SLAVE
180         IFF_UP
181
182       This example determines whether interface 'tu0' supports multicasting:
183
184         use IO::Socket;
185         use IO::Interface ':flags';
186         my $sock = IO::Socket::INET->new(Proto=>'udp');
187         print "can multicast!\n" if $sock->if_flags & IFF_MULTICAST.
188

AUTHOR

190       Lincoln Stein <lstein@cshl.org>
191
192       This module is distributed under the same license as Perl itself.
193

SEE ALSO

195       perl(1), IO::Socket(3), IO::Multicast(3), IO::Interface::Simple
196
197
198
199perl v5.8.8                       2007-01-22                      Interface(3)
Impressum