/[pxelator]/lib/PXElator/wol.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/wol.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (show annotations)
Sat Jan 23 18:31:14 2010 UTC (14 years, 2 months ago) by dpavlin
File size: 855 byte(s)
use store::audit proxy all over the place

1 package wol;
2
3 use warnings;
4 use strict;
5
6 use IO::Socket::INET;
7 use Regexp::Common qw/net/;
8 use store;
9
10 use client;
11 use server;
12
13 sub power_on {
14 my $target = shift;
15
16 my ( $port, $mac ) = ( 9 );
17
18 if ( $target =~ m/$RE{net}{MAC}{-keep}/ ) {
19 $mac = $1;
20 } elsif ( $target =~ m/$RE{net}{IPv4}{-keep}/ ) {
21 $mac = client::mac_from_ip $1;
22 } else {
23 die "$target isn't IP or MAC";
24 }
25
26 warn "# power_on $mac";
27
28 my $sock = IO::Socket::INET->new( Proto=>'udp' );
29 my $ip_addr = inet_aton($server::bcast);
30 my $sock_addr = sockaddr_in($port, $ip_addr);
31
32 my $mac_payload = $mac;
33 $mac_payload =~ s{:}{}g;
34
35 my $packet = pack('C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac_payload x 16);
36
37 setsockopt($sock, SOL_SOCKET, SO_BROADCAST, 1);
38 send($sock, $packet, 0, $sock_addr);
39 close ($sock);
40
41 store::audit( $target, { ip => $target, mac => $mac } );
42 }
43
44 1;

  ViewVC Help
Powered by ViewVC 1.1.26