blib/lib/Linux/Ethtool/WOL.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 75 CC 5 SCAR 15.5
CC
5
Cov
0%
sopass
12.0
new
6.0
wolopts
6.0
CRAP 4.7
1 =head1 NAME
2  
3 Linux::Ethtool::WOL - Manipulate interface Wake-on-LAN settings
4  
5 =head1 SYNOPSIS
6  
7 use Linux::Ethtool::WOL qw(:all);
8
9 my $wol = Linux::Ethtool::WOL->new("eth0") or die($!);
10
11 unless($wol->supported & WAKE_MAGIC)
12 {
13 die("Network card does not support WOL using Magic Packet");
14 }
15
16 $wol->wolopts(WAKE_MAGIC);
17
18 $wol->apply() or die($!);
19  
20 =head1 DESCRIPTION
21  
22 This module provides a wrapper around the C<ethtool_wolinfo> structure and
23 associated ioctls, used for configuring Wake-on-LAN options.
24  
25 All the constants in this module may be imported individually or by using the
26 C<all> import tag.
27  
28 =head1 METHODS
29  
30 =cut
31  
32 package Linux::Ethtool::WOL;
33  
34 use strict;
35 use warnings;
36  
37 our $VERSION = "0.11";
38  
39 require XSLoader;
40 XSLoader::load("Linux::Ethtool::WOL");
41  
42 use Exporter qw(import);
43  
44 our @EXPORT_OK = qw(
45 WAKE_PHY
46 WAKE_UCAST
47 WAKE_MCAST
48 WAKE_BCAST
49 WAKE_ARP
50 WAKE_MAGIC
51 WAKE_MAGICSECURE
52 );
53  
54 our %EXPORT_TAGS = (
55 all => [ @EXPORT_OK ],
56 );
57  
58 use Linux::Ethtool::Constants;
59  
60 # Duplicate the constants here so we can export them.
61  
62 use constant {
63 WAKE_PHY => Linux::Ethtool::Constants::WAKE_PHY,
64 WAKE_UCAST => Linux::Ethtool::Constants::WAKE_UCAST,
65 WAKE_MCAST => Linux::Ethtool::Constants::WAKE_MCAST,
66 WAKE_BCAST => Linux::Ethtool::Constants::WAKE_BCAST,
67 WAKE_ARP => Linux::Ethtool::Constants::WAKE_ARP,
68 WAKE_MAGIC => Linux::Ethtool::Constants::WAKE_MAGIC,
69 WAKE_MAGICSECURE => Linux::Ethtool::Constants::WAKE_MAGICSECURE,
70 };
71  
72 use Carp;
73  
74 =head2 new($dev)
75  
76 Construct a new instance using the settings of the named interface.
77  
78 Returns an object instance on success, undef on failure.
79  
80 =cut
81  
82 sub new
83 {
84 my ($class, $dev) = @_;
85
86 my $self = bless({ dev => $dev }, $class);
87
88 if(_ethtool_gwol($self, $dev))
89 {
90 return $self;
91 }
92 else{
93 return undef;
94 }
95 }
96  
97 =head2 apply()
98  
99 Apply any changed settings to the interface.
100  
101 Returns true on success, false on failure.
102  
103 =cut
104  
105 sub apply
106 {
107 my ($self) = @_;
108
109 return _ethtool_swol($self->{dev}, $self->{wolopts}, $self->{sopass});
110 }
111  
112 =head2 supported()
113  
114 Return the supported WOL flags which is any of the following constants bitwise
115 OR'd together:
116  
117 WAKE_PHY
118 WAKE_UCAST
119 WAKE_MCAST
120 WAKE_BCAST
121 WAKE_ARP
122 WAKE_MAGIC
123 WAKE_MAGICSECURE
124  
125 =cut
126  
127 sub supported
128 {
129 my ($self) = @_;
130
131 return $self->{supported};
132 }
133  
134 =head2 wolopts([ $wolopts ])
135  
136 Get or set the enabled WOL options, these should be a subset of those returned
137 by C<supported>.
138  
139 Returns the current/new value.
140  
141 =cut
142  
143 sub wolopts
144 {
145 my ($self, $wolopts) = @_;
146
147 if(defined($wolopts))
148 {
149 $self->{wolopts} = $wolopts;
150 }
151
152 return $self->{wolopts};
153 }
154  
155 =head2 sopass([ $sopass ])
156  
157 Get or set the SecureOn(TM) password, only meaningful if the C<WAKE_MAGICSECURE>
158 flag is set, which itself requires C<WAKE_MAGIC>.
159  
160 The value is a scalar which is 6 B<BYTES> (not characters) long.
161  
162 =cut
163  
164 sub sopass
165 {
166 my ($self, $sopass) = @_;
167
168 if(defined($sopass))
169 {
170 use bytes;
171
172 if(length($sopass) != 6)
173 {
174 croak("sopass must be 6 BYTES long");
175 }
176
177 $self->{sopass} = $sopass;
178 }
179
180 return $self->{sopass};
181 }
182  
183 =head1 SEE ALSO
184  
185 L<Linux::Ethtool>, L<Linux::Ethtool::Settings>
186  
187 =cut
188  
189 1;