Browse Source

[Contribs] Add updated wake-on-LAN patch from Bill <level42@sympatico.ca>

tags/v0.9.4
Michael Brown 16 years ago
parent
commit
7067142fb4

+ 0
- 37
contrib/wakeonlan/Makefile View File

1
-## Makefile for use with gnu make and MinGW32 gnu gcc
2
-
3
-TARGET=wol
4
-
5
-CC=gcc
6
-LD=gcc
7
-
8
-CPPFLAGS= -Wall -O2
9
-LFLAGS= -s
10
-
11
-#LIBFILES= -lwsock
12
-#LIBPATH= -L/usr/lib
13
-
14
-ICON=$(TARGET).ico
15
-OBJS=$(TARGET).o
16
-RESF=$(TARGET).rc
17
-
18
-#RESNAME=$(TARGET).res
19
-#BINNAME=$(TARGET).exe
20
-BINNAME=$(TARGET)
21
-
22
-$(BINNAME): $(OBJS) $(RESNAME)
23
-	$(LD) $(LFLAGS) -o $@ $^ $(LIBPATH) $(LIBFILES)
24
-
25
-%.res:%.rc
26
-	windres -I rc -O coff -i $< -o $@
27
-
28
-%.rc:Makefile
29
-	@echo 100 ICON "$(ICON)" > $@
30
-
31
-dist:$(BINNAME)
32
-	rm -f $(OBJS) $(RESNAME) $(RESF)
33
-
34
-clean:
35
-	rm -f $(OBJS) $(RESNAME) $(RESF)
36
-	rm -f $(BINNAME)
37
-

+ 40
- 3
contrib/wakeonlan/README View File

1
-Here are two programs to send Wake-On-LAN packets to a dormant workstation
2
-using the WOL feature. Please contact the respective authors for any
3
-queries.
1
+From level42@sympatico.ca Tue Mar 18 04:35:31 2008
2
+Date: Mon, 17 Mar 2008 23:47:39 -0400
3
+From: Bill <level42@sympatico.ca>
4
+To: etherboot-developers@lists.sourceforge.net
5
+Subject: [Etherboot-developers] WOL Routine
6
+
7
+Attached is a WOL routine that can be used to wake a remote server from 
8
+gpxe.  I put wol.c in src/usr and wol.h in src/include/usr.  This is really 
9
+in improved replacement of that in contrib\wakeonlan\wakeserver.patch.  This 
10
+version will no longer work since the eth_transmit routine no longer works 
11
+with the newer driver arhitecture such as the e1000 driver.
12
+
13
+Please consider adding it to gpxe preferrably in the main src directory or 
14
+in the contrib directory.
15
+
16
+Thank you 
17
+
18
+
19
+    [ Part 2, Text/PLAIN (Name: "wol.c")  109 lines. ]
20
+    [ Unable to print this part. ]
21
+
22
+
23
+    [ Part 3, Text/PLAIN (Name: "wol.h")  12 lines. ]
24
+    [ Unable to print this part. ]
25
+
26
+
27
+    [ Part 4: "Attached Text" ]
28
+
29
+-------------------------------------------------------------------------
30
+This SF.net email is sponsored by: Microsoft
31
+Defy all challenges. Microsoft(R) Visual Studio 2008.
32
+http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
33
+
34
+    [ Part 5: "Attached Text" ]
35
+
36
+_______________________________________________
37
+Etherboot-developers mailing list
38
+Etherboot-developers@lists.sourceforge.net
39
+https://lists.sourceforge.net/lists/listinfo/etherboot-developers
40
+

+ 0
- 9
contrib/wakeonlan/maclist.txt View File

1
-# maclist - mac addresses for wakeonlan
2
-00:BA:BE:FA:CE:00 mainframe
3
-00:11:22:33:44:5A maschine1
4
-00:11:22:33:44:B5 maschine2
5
-00:11:22:33:44:5C maschine3
6
-0A:BB:CC:DD:EE:F9 macintosh
7
-1A:BB:CC:DD:E6:FF 
8
-3A:BB:CC:DD:EE:F5 testpc
9
-3A:BB:CC:DD:EE:F6 123.45.6.7

+ 0
- 172
contrib/wakeonlan/mp-form.pl View File

1
-#!/perl/bin/perl -w
2
-# Magic Packet for the Web
3
-# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
4
-# Steve_Marfisi@3com.com on the Netboot mailing list
5
-# modified to work with web by G. Knauf <info@gknw.de>
6
-# Released under GNU Public License
7
-#
8
-use CGI qw(:standard); # import shortcuts
9
-use Socket;
10
-
11
-$ver = 'v0.52 &copy; gk 2003-Apr-24 11:00:00';
12
-
13
-# Defaults - Modify to point to the location of your mac file
14
-$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
15
-$maclist = "$www/maclist.txt";
16
-# Defaults - Modify to fit to your network
17
-$defbc = '255.255.255.255';
18
-$port = 60000;
19
-
20
-MAIN:
21
-{
22
-  # Read in all the variables set by the form
23
-  if (param()) {
24
-    &process_form();
25
-  } else {
26
-    &print_form();
27
-  }
28
-}
29
-
30
-sub process_form {
31
-  # Print the header
32
-  print header();
33
-  print start_html("Mp-Form - send Magic Packets");
34
-  # If defined new mac save it
35
-  if (defined(param("mac"))) {
36
-    print h1("Result of adding an entry to the maclist");
37
-    print '<HR><H3><TT>';
38
-    &add_entry();
39
-    print '</TT></H3><HR>';
40
-    print '<FORM method="POST"><input type="submit" value="ok"></FORM>';
41
-  } else {
42
-    # send magic packets to selected macs
43
-    print h1("Result of sending magic packets to multiple PCs");
44
-    print '<HR><H3><TT>';
45
-    if (param("all")) {
46
-      &process_file(S);
47
-    } else {
48
-      for (param()) {
49
-        my ($brc,$mac) = split(/-/,param($_)); 
50
-        &send_broadcast_packet(inet_aton($brc),$mac);
51
-      }
52
-    }
53
-    print '</TT></H3><HR>';
54
-    print '<FORM><input type="button" value="back" onClick="history.back()"></FORM>';
55
-  }
56
-  # Close the document cleanly.
57
-  print end_html;
58
-}
59
-
60
-sub print_form {
61
-  # Print the header
62
-  print header();
63
-  print start_html("Mp-Form - send Magic Packets");
64
-  print h1("Form for sending magic packets to multiple PCs");
65
-  print <<ENDOFTEXT;
66
-<HR>
67
-<FORM method="POST">
68
-<H2>Select the destination mac addresses:</H2>
69
-<TABLE BORDER COLS=3 WIDTH="80%">
70
-<TR>
71
-<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
72
-<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
73
-<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
74
-<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
75
-</TR>
76
-ENDOFTEXT
77
-  # build up table with mac addresses
78
-  &process_file(R);
79
-  # print rest of the form
80
-  print <<ENDOFTEXT;
81
-</TABLE>
82
-<P><B><FONT SIZE="+1">
83
-Press <input type="submit" value="wakeup"> to send the magic packets to your selections. 
84
-Press <input type="reset" value="clear"> to reset the form.
85
-</FONT></B>
86
-</FORM>
87
-<HR>
88
-<FORM method="POST">
89
-<H2>Enter new destination mac address:</H2>
90
-<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc"> 
91
-<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size="17" maxlength="17"> 
92
-<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size="40" maxlength="40">
93
-<P><B><FONT SIZE="+1">
94
-Press <input type="submit" value="save"> to add the entry to your maclist. 
95
-Press <input type="reset" value="clear"> to reset the form.
96
-</FONT></B>
97
-</FORM>
98
-<HR>
99
-$ver
100
-ENDOFTEXT
101
-  # Close the document cleanly.
102
-  print end_html;
103
-}
104
-
105
-sub send_broadcast_packet {
106
-  my ($nbc,$mac) = @_;
107
-  if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i)  {
108
-    print "Malformed MAC address $mac<BR>\n";
109
-    return;
110
-  }
111
-  printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
112
-  # Remove colons
113
-  $mac =~ tr/://d;
114
-  # Magic packet is 6 bytes of FF followed by the MAC address 16 times
115
-  $magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
116
-  # Create socket
117
-  socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
118
-  # Enable broadcast
119
-  setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
120
-  # Send the wakeup packet
121
-  defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
122
-  close(S);
123
-}
124
-
125
-sub process_file {
126
-  unless (open(F, $maclist)) {
127
-    print "Error reading $maclist: $!\n";
128
-  } else {
129
-    while (<F>) {
130
-      next if (/^\s*#|^\s*;/);	# skip comments
131
-      my ($mac, $ip) = split;
132
-      next if (!defined($mac) or $mac eq '');
133
-      $mac = uc($mac);
134
-      my $bc = $defbc;
135
-      ($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
136
-      my $nbc = inet_aton($bc);
137
-      if ($_[0] eq 'S') {
138
-        &send_broadcast_packet($nbc, $mac);
139
-      } else {
140
-        my $hbc = sprintf("0x%08X", unpack('N',$nbc));
141
-        print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
142
-        print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
143
-        $ip = '&nbsp;' if (!defined($ip) or $ip eq '');
144
-        print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
145
-        print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
146
-      }
147
-    }
148
-    close(F);
149
-  }
150
-}
151
-
152
-sub add_entry {
153
-  if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
154
-    print "Malformed broadcast address ",param("brc"),"\n";
155
-    return;
156
-  }
157
-  if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
158
-    print "Malformed MAC address ",param("mac"),"\n";
159
-    return;
160
-  }
161
-  unless (open(F, ">> $maclist")) {
162
-    print "Error writing $maclist: $!\n";
163
-  } else {
164
-    #my $nbc = inet_aton(param("brc"));
165
-    #my $hbc = sprintf("0x%8X", unpack('N',$nbc));
166
-    #print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
167
-    print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
168
-    close(F);
169
-    print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
170
-  }
171
-}
172
-

+ 0
- 26
contrib/wakeonlan/mp-form.txt View File

1
-mp-form.pl - Send magic packets with your web server
2
-
3
-This is my trial of waking up PCs with a form via web server. 
4
-The perl script reads in a text file which contains lines of the form
5
-aa:bb:cc:dd:ee:ff 12.34.56.78 or
6
-aa:bb:cc:dd:ee:ff foo.bar.com
7
-aa:bb:cc:dd:ee:ff
8
-The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package. 
9
-The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both 
10
-modules should belong to your perl distribution. The script runs with linux as well as 
11
-with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with 
12
-Perl build #333 and earlier I got an error from the Socket.pm.
13
-This script uses only broadcast so you don't need root rights to use it.
14
-
15
-To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755 
16
-to the script. Modify the lines which point to the location of the maclist. If you do not 
17
-have a maclist, the form could save new entries to a list (with unix perhaps you have to 
18
-create an empty file). Check also the first line of mp-form.pl and modify it to point to 
19
-your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
20
-
21
-Older version: If you have problems running the script with CGI.pm you could try the older 
22
-version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl 
23
-from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using 
24
-CGI.pm consumes much memory. The older version is also included in the zip archive. 
25
-
26
-Homepage of the script: http://www.gknw.de/mpform.html

+ 0
- 171
contrib/wakeonlan/mp-form1.pl View File

1
-#!/usr/bin/perl -w
2
-# Magic Packet for the Web
3
-# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
4
-# Steve_Marfisi@3com.com on the Netboot mailing list
5
-# modified to work with web by G. Knauf <info@gknw.de>
6
-# Released under GNU Public License
7
-#
8
-require "cgi-lib.pl";
9
-use Socket;
10
-
11
-$ver = 'v0.52 &copy; gk 2003-Apr-24 11:00:00';
12
-
13
-# Defaults - Modify to point to the location of your mac file
14
-$www = "$ENV{'DOCUMENT_ROOT'}/perldemo";
15
-$maclist = "$www/maclist.txt";
16
-# Defaults - Modify to fit to your network
17
-$defbc = '255.255.255.255';
18
-$port = 60000;
19
-
20
-MAIN: 
21
-{
22
-  # Read in all the variables set by the form
23
-  if (&ReadParse(*input)) {
24
-    &process_form();
25
-  } else {
26
-    &print_form();
27
-  }
28
-}
29
-
30
-sub process_form {
31
-  # Print the header
32
-  print &PrintHeader();
33
-  # If defined new mac save it
34
-  if (defined($input{'mac'})) {
35
-    print &HtmlTop("Result of adding an entry to the maclist");
36
-    print '<HR><H3><TT>';
37
-    &add_entry;
38
-    print '</TT></H3><HR>';
39
-    print '<FORM method="POST"><input type=submit value="ok"></FORM>';
40
-  } else {
41
-    # send magic packets to selected macs
42
-    print &HtmlTop("Result of sending magic packets to multiple PCs");
43
-    print '<HR><H3><TT>';
44
-    if (defined($input{'all'})) {
45
-      &process_file(S);
46
-    } else {
47
-      foreach $x (keys %input) {
48
-        my ($brc,$mac) = split(/-/,$input{$x}); 
49
-        &send_broadcast_packet(inet_aton($brc),$mac);
50
-      }
51
-    }
52
-    print '</TT></H3><HR>';
53
-    print '<form><input type=button value="back" onClick="history.back()"></FORM>';
54
-  }
55
-  # Close the document cleanly.
56
-  print &HtmlBot;
57
-  exit;
58
-}
59
-
60
-sub print_form {
61
-  print &PrintHeader();
62
-  print &HtmlTop("Form for sending magic packets to multiple PCs");
63
-  # Print out the body of the form
64
-  print <<ENDOFTEXT;
65
-<HR>
66
-<FORM method="POST">
67
-<H2> Select the destination mac addresses: </H2>
68
-<TABLE BORDER COLS=3 WIDTH="80%">
69
-<TR>
70
-<TD><CENTER><B><FONT SIZE="+1">Broadcast address</FONT></B></CENTER></TD>
71
-<TD><CENTER><B><FONT SIZE="+1">MAC address</FONT></B></CENTER></TD>
72
-<TD><CENTER><B><FONT SIZE="+1">Name</FONT></B></CENTER></TD>
73
-<TD><CENTER><B><FONT SIZE="+1"><input type=checkbox name="all" value="all">Select all</FONT></B></CENTER></TD>
74
-</TR>
75
-ENDOFTEXT
76
-  # build up table with mac addresses
77
-  &process_file;
78
-  # print rest of the form
79
-  print <<ENDOFTEXT;
80
-</TABLE>
81
-<P><B><FONT SIZE="+1">
82
-Press <input type="submit" value="wakeup"> to send the magic packets to your selections. 
83
-Press <input type="reset" value="clear"> to reset the form.
84
-</FONT></B>
85
-</FORM>
86
-<HR>
87
-<FORM method="POST">
88
-<H2>Enter new destination mac address:</H2>
89
-<B><FONT SIZE="+1">Broadcast: </FONT></B><input name="brc" size="15" maxlength="15" value="$defbc"> 
90
-<B><FONT SIZE="+1">MAC: </FONT></B><input name="mac" size=17 maxlength=17> 
91
-<B><FONT SIZE="+1">Name: </FONT></B><input name="ip" size=40 maxlength=40>
92
-<P><B><FONT SIZE="+1">
93
-Press <input type="submit" value="save"> to add the entry to your maclist. 
94
-Press <input type="reset" value="clear"> to reset the form.
95
-</FONT></B>
96
-</FORM>
97
-<HR>
98
-$ver
99
-ENDOFTEXT
100
-  # Close the document cleanly.
101
-  print &HtmlBot;
102
-}
103
-
104
-sub send_broadcast_packet {
105
-  my ($nbc,$mac) = @_;
106
-  if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i)  {
107
-    print "Malformed MAC address $mac<BR>\n";
108
-    return;
109
-  }
110
-  printf("Sending wakeup packet to %04X:%08X-%s<BR>\n", $port, unpack('N',$nbc), $mac);
111
-  # Remove colons
112
-  $mac =~ tr/://d;
113
-  # Magic packet is 6 bytes of FF followed by the MAC address 16 times
114
-  $magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
115
-  # Create socket
116
-  socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
117
-  # Enable broadcast
118
-  setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
119
-  # Send the wakeup packet
120
-  defined(send(S, $magic, 0, sockaddr_in($port, $nbc))) or print "send: $!\n";
121
-  close(S);
122
-}
123
-
124
-sub process_file {
125
-  unless (open(F, $maclist)) {
126
-    print "Error reading $maclist: $!\n";
127
-  } else {
128
-    while (<F>) {
129
-      next if (/^\s*#|^\s*;/);	# skip comments
130
-      my ($mac, $ip) = split;
131
-      next if (!defined($mac) or $mac eq '');
132
-      $mac = uc($mac);
133
-      my $bc = $defbc;
134
-      ($bc,$mac) = split(/-/,$mac) if ($mac =~ /-/);
135
-      my $nbc = inet_aton($bc);
136
-      if ($_[0] eq 'S') {
137
-        &send_broadcast_packet($nbc, $mac);
138
-      } else {
139
-        my $hbc = sprintf("0x%08X", unpack('N',$nbc));
140
-        print "<TD WIDTH=20%><CENTER><TT>$hbc</TT></CENTER></TD>";
141
-        print "<TD WIDTH=30%><CENTER><TT>$mac</TT></CENTER></TD>";
142
-        $ip = '&nbsp;' if (!defined($ip) or $ip eq '');
143
-        print "<TD WIDTH=30%><CENTER><TT>$ip</TT></CENTER></TD>";
144
-        print "<TD WIDTH=20%><CENTER><input type=checkbox name=mac$. value=$hbc-$mac><TT>WakeUp</TT></CENTER></TD></TR>\n";
145
-      }
146
-    }
147
-    close(F);
148
-  }
149
-}
150
-
151
-sub add_entry {
152
-  if (param("brc") !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i) {
153
-    print "Malformed broadcast address ",param("brc"),"\n";
154
-    return;
155
-  }
156
-  if (param("mac") !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
157
-    print "Malformed MAC address ",param("mac"),"\n";
158
-    return;
159
-  }
160
-  unless (open(F, ">> $maclist")) {
161
-    print "Error writing $maclist: $!\n";
162
-  } else {
163
-    #my $nbc = inet_aton(param("brc"));
164
-    #my $hbc = sprintf("0x%8X", unpack('N',$nbc));
165
-    #print F $hbc."-".uc(param("mac"))." ".param("ip")."\n";
166
-    print F param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
167
-    close(F);
168
-    print "Saved entry to maclist: ".param("brc")."-".uc(param("mac"))." ".param("ip")."\n";
169
-  }
170
-}
171
-

+ 0
- 35
contrib/wakeonlan/readme.txt View File

1
-mp-form.pl - Send magic packets with your web server
2
-
3
-This is my trial of waking up PCs with a form via web server. 
4
-The perl script reads in a text file which contains lines of the form
5
-aa:bb:cc:dd:ee:ff 12.34.56.78 or
6
-aa:bb:cc:dd:ee:ff foo.bar.com
7
-aa:bb:cc:dd:ee:ff
8
-optional a broadcast address mask can be prefixed:
9
-192.168.1.255-aa:bb:cc:dd:ee:ff
10
-
11
-The script is based on wake.pl by Ken Yap who is also the author of the Etherboot package. 
12
-The script uses CGI.pm to parse form input and Socket.pm to send the magic packets, both 
13
-modules should belong to your perl distribution. The script runs with linux as well as 
14
-with NT, with NetWare you have to use the Socket.NLP from recent Perl build #334, with 
15
-Perl build #333 and earlier I got an error from the Socket.pm. You should also update
16
-your Perl to minimum #331 from CPAN: http://www.cpan.org/ports/index.html#netware.
17
-This script uses only broadcast so you don't need root rights to use it.
18
-
19
-To install the script copy it to your ../cgi-bin directory. Then for Linux do a chmod 755 
20
-to the script. Modify the lines which point to the location of the maclist. If you do not 
21
-have a maclist, the form could save new entries to a list (with unix perhaps you have to 
22
-create an empty file). Check also the first line of mp-form.pl and modify it to point to 
23
-your perl5 location. For NetWare copy the script to /novonyx/suitespot/docs/perlroot.
24
-
25
-Older version: If you have problems running the script with CGI.pm you could try the older 
26
-version mp-form1.pl which uses cgi-lib.pl to parse form input. You can get cgi-lib.pl 
27
-from http://cgi-lib.berkeley.edu/. With NetWare you should also use mp-form1.pl as using 
28
-CGI.pm consumes much memory. The older version is also included in the zip archive. 
29
-
30
-A modified version of the original script is now also included which runs with older 
31
-Getopt::Std.pm as shipped with NetWare. This script you could use from command line 
32
-or from cron. With NetWare copy the script to /perl/scripts; then call from console with:
33
-perl wakeup.pl <parameters>.
34
-
35
-Homepage of the script: http://www.gknw.de/mpform.html

+ 0
- 116
contrib/wakeonlan/wake.pl View File

1
-#!/usr/bin/perl -w
2
-#
3
-# If called as wake.pl -f file it reads lines of the form
4
-#
5
-# aa:bb:cc:dd:ee;ff 12.34.56.78 or
6
-# aa:bb:cc:dd:ee:ff foo.bar.com
7
-# aa:bb:cc:dd:ee:ff
8
-#
9
-# which are MAC addresses and hostnames of NICs to send a wakeup packet.
10
-# In the first two cases, unicast is used (and root permission may be
11
-# required if the ARP cache needs to be injected with a mapping).
12
-# In the third case, broadcast is used, and anybody can run the command.
13
-# Comments in the file start with #.
14
-#
15
-# Or MAC addresses can be specified on the command line
16
-#
17
-# wake.pl aa.bb.cc.dd.ee.ff
18
-#
19
-# Or both can be used:
20
-#
21
-# wake.pl -f addresses.cfg 11:22:33:44:55:66
22
-#
23
-# This program may have to be run with superuser privilege because it
24
-# may need to inject an ARP entry into the cache.
25
-# Be careful, you could corrupt valid entries if those NICs are
26
-# already active.
27
-#
28
-# Perl version by ken_yap@users.sourceforge.net after DOS/Windows C version posted by
29
-# Steve_Marfisi@3com.com on the Netboot mailing list
30
-# Released under GNU Public License, 2000-01-08
31
-# Added switch -q for quiet mode, changed Getopt usage to work with older versions,
32
-# added switch -u for unicast mode, now default is always broadcast mode,
33
-# added switch -s for seach pattern so you could filter entries from file.
34
-# Guenter.Knauf@dialup.soco.de, 2000-10-14
35
-#
36
-use Getopt::Std;
37
-use Socket;
38
-
39
-getopts('quf:s:');
40
-if (defined($opt_f)) {
41
-	unless (open(F, $opt_f)) {
42
-		print STDERR "open: $opt_f: $!\n";
43
-	} else {
44
-		while (<F>) {
45
-			next if /^\s*#/;	# skip comments
46
-			($mac, $ip) = split;
47
-			next if !defined($mac) or $mac eq '';
48
-			next if defined($opt_s) and (!/$opt_s/);
49
-			if (!defined($ip) or $ip eq '' or !$opt_u) {
50
-				&send_broadcast_packet($mac);
51
-			} else {
52
-				&send_unicast_packet($mac, $ip);
53
-			}
54
-		}
55
-		close(F);
56
-	}
57
-}
58
-while (@ARGV) {
59
-	send_broadcast_packet(shift(@ARGV));
60
-}
61
-
62
-sub send_broadcast_packet {
63
-	($mac) = @_;
64
-
65
-	if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i)  {
66
-		print STDERR "Malformed MAC address $mac\n";
67
-		return;
68
-	}
69
-	# Remove colons
70
-	$mac =~ tr/://d;
71
-	# Magic packet is 6 bytes of FF followed by the MAC address 16 times
72
-	$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
73
-	# Create socket
74
-	socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
75
-		or die "socket: $!\n";
76
-	# Enable broadcast
77
-	setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1)
78
-		or die "setsockopt: $!\n";
79
-	# Send the wakeup packet
80
-	if (!$opt_q) {
81
-		print "Sending wakeup packet to MAC address $mac";
82
-		print " ($ip)" if (defined($ip));
83
-		print "\n";
84
-	}
85
-	defined(send(S, $magic, 0, sockaddr_in(0x2fff, INADDR_BROADCAST)))
86
-		or print STDERR "send: $!\n";
87
-	close(S);
88
-}
89
-
90
-sub send_unicast_packet {
91
-	($mac, $ip) = @_;
92
-
93
-	if (!defined($iaddr = inet_aton($ip))) {
94
-		print STDERR "Cannot resolve $ip\n";
95
-		return;
96
-	}
97
-	if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i)  {
98
-		print STDERR "Malformed MAC address $mac\n";
99
-		return;
100
-	}
101
-	# Inject entry into ARP table, in case it's not there already
102
-	system("arp -s $ip $mac") == 0
103
-		or print STDERR "Warning: arp command failed, you need to be root\n";
104
-	# Remove colons
105
-	$mac =~ tr/://d;
106
-	# Magic packet is 6 bytes of FF followed by the MAC address 16 times
107
-	$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
108
-	# Create socket
109
-	socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
110
-		or die "socket: $!\n";
111
-	# Send the wakeup packet
112
-	print "Sending wakeup packet to $ip at MAC address $mac\n" if (!$opt_q);
113
-	defined(send(S, $magic, 0, sockaddr_in(0x2fff, $iaddr)))
114
-		or print STDERR "send: $!\n";
115
-	close(S);
116
-}

+ 0
- 179
contrib/wakeonlan/wakeserver.patch View File

1
-To: etherboot-developers@lists.sourceforge.net
2
-X-face: #Qvg5o3u!)WoVDDi4-bFy`fl@""4^pm68%_,`puon{0Q6lQ-O,)3D.J.":A&^,#4O2vc8`?
3
- 3^1lhBh=EQH,"Qq*e1vY":she&t^8:!&Fb32Ed:nM2Y<E9|i[+z20G?CO=E=-IWv;bL"=Y`+`q,ML6
4
- ,!Me?==j&In1
5
-Mime-Version: 1.0
6
-Content-Type: multipart/mixed ;
7
-	boundary="==_Exmh_-19971541890"
8
-From: Tilmann Bubeck <bubeck@think-at-work.de>
9
-Message-Id: <20010219195622.C97A84ABD8@chaos.think-at-work.de>
10
-Subject: [Etherboot-developers] Wake-on-LAN patch
11
-Sender: etherboot-developers-admin@lists.sourceforge.net
12
-Errors-To: etherboot-developers-admin@lists.sourceforge.net
13
-X-BeenThere: etherboot-developers@lists.sourceforge.net
14
-X-Mailman-Version: 2.0
15
-Precedence: bulk
16
-List-Help: <mailto:etherboot-developers-request@lists.sourceforge.net?subject=help>
17
-List-Post: <mailto:etherboot-developers@lists.sourceforge.net>
18
-List-Subscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
19
-	<mailto:etherboot-developers-request@lists.sourceforge.net?subject=subscribe>
20
-List-Id: Discussion list for Etherboot developers <etherboot-developers.lists.sourceforge.net>
21
-List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/etherboot-developers>,
22
-	<mailto:etherboot-developers-request@lists.sourceforge.net?subject=unsubscribe>
23
-List-Archive: <http://lists.sourceforge.net/archives//etherboot-developers/>
24
-Date: Mon, 19 Feb 2001 20:56:22 +0100
25
-Status: RO
26
-Content-Length: 5351
27
-Lines: 152
28
-
29
-This is a multipart MIME message.
30
-
31
---==_Exmh_-19971541890
32
-Content-Type: text/plain; charset=us-ascii
33
-
34
-
35
-Hello!
36
-
37
-please find enclosed a patch to optionally enable etherboot to start the 
38
-server it is booting from by sending a magic wake-on-lan packet to the 
39
-sleeping server first.
40
-
41
-This is very important for an etherboot-server, which is not running all the 
42
-time and is not easily accessible from the etherboot machine (e.g. because it 
43
-is installed in the basement of the house and one must climb several stairs to 
44
-switch the server on...)
45
-
46
-Are the authors of etherboot willing to accept this patch for inclusion? 
47
-Please note, that the wake-on-lan code is only compiled in, when setting 
48
-appropriate flags in src/Config.
49
-
50
-If you don't want to include the patch, should I change anything of the 
51
-implementation or do you dislike the idea at all?
52
- 
53
-Thanks!
54
-   Till
55
-
56
-+-------+--------------------------------------------------------------+
57
-|       | dr. tilmann bubeck               think@work it consulting    |
58
-|       |                                  professional services       |
59
-| think | cell.: +49 172 8842972           widmaierstrasse 58          |
60
-| @work | fax  : +49 711 7227734           70567 stuttgart             |
61
-|       | email: bubeck@think-at-work.de   http://www.think-at-work.de |
62
-+-------+ -------------------------------------------------------------+
63
-
64
-
65
---==_Exmh_-19971541890
66
-Content-Type: application/x-patch ; name="etherboot-4.7.17-wol.patch"
67
-Content-Description: etherboot-4.7.17-wol.patch
68
-Content-Disposition: attachment; filename="etherboot-4.7.17-wol.patch"
69
-
70
-diff -r -u etherboot-4.7.17/src/Config etherboot-4.7.17-wol/src/Config
71
---- etherboot-4.7.17/src/Config	Sat Jan  6 16:25:23 2001
72
-+++ etherboot-4.7.17-wol/src/Config	Mon Feb 19 20:28:00 2001
73
-@@ -113,6 +113,16 @@
74
- #	-DINTERNAL_BOOTP_DATA
75
- #			- define if the area 0x93C00-0x93FFF is not available
76
- #			  for use for bootpd_data by the loader for some reason
77
-+#	-DWAKEUP_SERVER 
78
-+#                       - define this for sending a Wake-On-LAN (WOL) 
79
-+#                         "Magic Packet" to a sleeping server, before trying 
80
-+#                         a etherboot. Useful if your server is soft-off all
81
-+#                         the time and must be switched on when booting a 
82
-+#                         client. Define SERVER_MAC with the MAC address of the
83
-+#                         server to wakeup. CAUTION! This MAC address is 
84
-+#                         stored in the rom image. The rom is therefore not
85
-+#                         generic anymore but tailored for a specific
86
-+#                         server!
87
- 
88
- # These default settings compile Etherboot with a small number of options.
89
- # You may wish to enable more of the features if the size of your ROM allows.
90
-@@ -142,6 +152,10 @@
91
- 
92
- # These flags affect the loader that is prepended to the Etherboot image
93
- LCONFIG+=	-DMOVEROM
94
-+
95
-+# Include code for sending a Wake-On-LAN (WOL) "Magic Packet" to a sleeping
96
-+# server, before trying a etherboot.
97
-+CFLAGS32+=	-DWAKEUP_SERVER -DSERVER_MAC=0x00,0x01,0x02,0xDA,0xDF,0x77
98
- 
99
- # you should normally not need to change these
100
- RM=		rm -f
101
-diff -r -u etherboot-4.7.17/src/main.c etherboot-4.7.17-wol/src/main.c
102
---- etherboot-4.7.17/src/main.c	Fri Jan  5 12:45:29 2001
103
-+++ etherboot-4.7.17-wol/src/main.c	Thu Feb  8 20:46:59 2001
104
-@@ -137,6 +137,7 @@
105
-  *	declarations, but in this case I like to see main() as the first
106
-  *	routine.
107
-  */
108
-+static void wakeup_server(void) ;
109
- static int bootp(void);
110
- static int rarp(void);
111
- static void load(void);
112
-@@ -217,6 +218,11 @@
113
- 			rfc951_sleep(++card_retries);
114
- 	}
115
- #endif
116
-+
117
-+#ifdef WAKEUP_SERVER
118
-+	wakeup_server();
119
-+#endif
120
-+
121
- 	while (1) {
122
- 		/* -1:	timeout or ESC
123
- 		   -2:	error return from loader
124
-@@ -650,6 +656,46 @@
125
- 	return (0);
126
- }
127
- #endif	/* DOWNLOAD_PROTO_TFTP */
128
-+
129
-+#ifdef WAKEUP_SERVER
130
-+#ifndef SERVER_MAC 
131
-+#error "Please define SERVER_MAC to the MAC address of the sleeping server"
132
-+#endif
133
-+
134
-+/**************************************************************************
135
-+WOL - Wake up a sleeping server by transmitting a Wake-On-LAN (WOL) "Magic
136
-+      Packet", used for restarting machines that have been soft-powered-down
137
-+      (ACPI D3-warm state). It currently generates the standard AMD Magic
138
-+      Packet format.
139
-+**************************************************************************/
140
-+static void wakeup_server(void) 
141
-+{
142
-+	unsigned char data[100];
143
-+	int i, len, retry;
144
-+	char server_adr[] = { SERVER_MAC };
145
-+	unsigned long time;
146
-+
147
-+	/* build "Magic Packet" */
148
-+	len = 0;
149
-+	data[len++] = 0xff;
150
-+	data[len++] = 0xff;
151
-+	data[len++] = 0xff;
152
-+	data[len++] = 0xff;
153
-+	data[len++] = 0xff;
154
-+	data[len++] = 0xff;
155
-+	for ( i = 0; i < 16; i++ ) {
156
-+		memcpy(&data[len], server_adr, 6);
157
-+		len += 6;
158
-+	}
159
-+
160
-+	printf("Sending Wake-On-LAN (WOL) \"Magic Packet\" to server %b:%b:%b:%b:%b:%b...", 
161
-+	       server_adr[0], server_adr[1], server_adr[2],
162
-+	       server_adr[3], server_adr[4], server_adr[5]);
163
-+	
164
-+	eth_transmit(broadcast, 0x0842, len, data);
165
-+	printf("done\n");
166
-+}
167
-+#endif
168
- 
169
- #ifdef	RARP_NOT_BOOTP
170
- /**************************************************************************
171
-
172
---==_Exmh_-19971541890--
173
-
174
-
175
-
176
-_______________________________________________
177
-Etherboot-developers mailing list
178
-Etherboot-developers@lists.sourceforge.net
179
-http://lists.sourceforge.net/lists/listinfo/etherboot-developers

+ 0
- 86
contrib/wakeonlan/wakeup.pl View File

1
-#!/usr/bin/perl
2
-#!/usr/bin/perl -w
3
-#
4
-# If called as wakeup.pl -f file it reads lines of the form
5
-#
6
-# aa:bb:cc:dd:ee;ff 12.34.56.78 or
7
-# aa:bb:cc:dd:ee:ff foo.bar.com
8
-# aa:bb:cc:dd:ee:ff
9
-#
10
-# which are MAC addresses and hostnames of NICs to send a wakeup packet.
11
-# Broadcast is used to send the magic packets, so anybody can run the command.
12
-# Notice that many routers do NOT forward broadcasts automatically!!
13
-# Comments in the file start with #.
14
-#
15
-# Or MAC addresses can be specified on the command line
16
-#
17
-# wakeup.pl aa.bb.cc.dd.ee.ff
18
-#
19
-# Or both can be used:
20
-#
21
-# wakeup.pl -f addresses.cfg 11:22:33:44:55:66
22
-# 
23
-# Use option -b to specify broadcast mask.
24
-# Use option -d for screen output.
25
-#
26
-# Perl version by ken.yap@acm.org after DOS/Windows C version posted by
27
-# Steve_Marfisi@3com.com on the Netboot mailing list
28
-# Released under GNU Public License, 2000-01-08
29
-# Modified for use with NetWare by gk@gknw.de, 2000-09-18
30
-# With NetWare you have to use Socket.NLP from NetWare Perl #334 or higher!
31
-# You could download Socket.NLP #334 from: http://www.gknw.de/mpform.html
32
-#
33
-
34
-use Getopt::Std;
35
-use Socket;
36
-
37
-getopts('b:df:p:q');
38
-
39
-$brc = $opt_b || '255.255.255.255';
40
-$port = $opt_p || 60000;
41
-die "Malformed broadcast address: $brc!\n" if ($brc !~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/);
42
-
43
-if (defined($opt_f)) {
44
-	unless (open(F, $opt_f)) {
45
-		print "open: $opt_f: $!\n";
46
-	} else {
47
-		print "Using file $opt_f...\n" if ($opt_d);
48
-		while (<F>) {
49
-			next if /^\s*#/;	# skip comments
50
-			my ($mac, $ip) = split;
51
-			next if !defined($mac) or $mac eq '';
52
-			&send_broadcast_packet($mac,$ip);
53
-		}
54
-		close(F);
55
-	}
56
-}
57
-while (@ARGV) {
58
-	send_broadcast_packet(shift(@ARGV));
59
-}
60
-
61
-sub send_broadcast_packet {
62
-	my ($mac,$ip) = @_;
63
-	if ($mac =~ /-/) {
64
-		($bc,$mac) = split(/-/,$mac);
65
-	} else {
66
-		$bc = $brc;
67
-	}
68
-	if ($mac !~ /^[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}$/i) {
69
-		print "Malformed MAC address $mac\n";
70
-		return;
71
-	}
72
-	my $nbc = inet_aton($bc);
73
-	# Remove colons
74
-	$mac =~ tr/://d;
75
-	# Magic packet is 6 bytes of FF followed by the MAC address 16 times
76
-	$magic = ("\xff" x 6) . (pack('H12', $mac) x 16);
77
-	# Create socket
78
-	socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket: $!\n";
79
-	# Enable broadcast
80
-	setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
81
-	# Send the wakeup packet
82
-	printf("$0: Sending wakeup packet to %04X:%08X-%s %s\n",$port,unpack('N',$nbc),uc($mac),$ip) if ($opt_d);
83
-	defined(send(S, $magic, 0, sockaddr_in($port, $nbc)))
84
-		or print "send: $!\n";
85
-	close(S);
86
-}

+ 0
- 9
contrib/wakeonlan/wakeup.txt View File

1
-# maclist - mac addresses for wakeonlan
2
-00:BA:BE:FA:CE:00 mainframe
3
-00:11:22:33:44:5A maschine1
4
-00:11:22:33:44:B5 maschine2
5
-00:11:22:33:44:5C maschine3
6
-0A:BB:CC:DD:EE:F9 macintosh
7
-1A:BB:CC:DD:E6:FF 
8
-3A:BB:CC:DD:EE:F5 testpc
9
-3A:BB:CC:DD:EE:F6 123.45.6.7

+ 93
- 359
contrib/wakeonlan/wol.c View File

1
-/*****************************************************************************
1
+/*
2
+ * Copyright (C) 2008 William Stewart.
2
  *
3
  *
3
- * wol.c - Wake-On-LAN utility to wake a networked PC
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
4
  *
8
  *
5
- * by R. Edwards (bob@cs.anu.edu.au), January 2000
6
- * (in_ether routine adapted from net-tools-1.51/lib/ether.c by
7
- * Fred N. van Kempen)
8
- * added file input, some minor changes for compiling for NetWare
9
- * added switches -q and -d=<ms>, added Win32 target support
10
- * by G. Knauf (gk@gknw.de), 30-Jan-2001
11
- * added switches -b=<bcast> and -p=<port>
12
- * by G. Knauf (gk@gknw.de), 10-Okt-2001
13
- * added OS/2 target support
14
- * by G. Knauf (gk@gknw.de), 24-May-2002
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
15
  *
13
  *
16
- * This utility allows a PC with WOL configured to be powered on by
17
- * sending a "Magic Packet" to it's network adaptor (see:
18
- * http://www.amd.com/products/npd/overview/20212.html).
19
- * Only the ethernet dest address needs to be given to make this work.
20
- * Current version uses a UDP broadcast to send out the Magic Packet.
21
- *
22
- * compile with: gcc -Wall -o wol wol.c
23
- * with Solaris: (g)cc -o wol wol.c -lsocket -lnsl
24
- * with MingW32: gcc -Wall -o wol wol.c -lwsock32
25
- *
26
- * usage: wol <dest address>
27
- * where <dest address> is in [ddd.ddd.ddd.ddd-]xx:xx:xx:xx:xx:xx format.
28
- * or: wol [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<File name>
29
- * where <File name> is a file containing one dest address per line,
30
- * optional followed by a hostname or ip separated by a blank.
31
- * -b sets optional broadcast address, -p sets optional port,
32
- * -q supresses output, -d=<ms> delays ms milliseconds between sending.
33
- *
34
- * Released under GNU Public License January, 2000.
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35
  */
17
  */
36
-
37
-#define VERSION "1.12.2 (c) G.Knauf http://www.gknw.de/"
38
-
39
-#include <errno.h>
40
 #include <stdio.h>
18
 #include <stdio.h>
19
+#include <stdint.h>
41
 #include <stdlib.h>
20
 #include <stdlib.h>
42
 #include <string.h>
21
 #include <string.h>
43
-#ifdef WATTCP
44
-  #define strncasecmp strnicmp
45
-  #include <ctype.h>
46
-  #include <dos.h>
47
-  #include <tcp.h>
48
-#else
49
-#ifdef WIN32                            /* Win32 platform */
50
-  #define USE_WINSOCKAPI
51
-  #define delay Sleep
52
-  #if (defined(__LCC__) || defined(__BORLANDC__))
53
-    #define strncasecmp strnicmp
54
-  #else
55
-    #define strncasecmp _strnicmp
56
-  #endif
57
-#elif defined(N_PLAT_NLM)               /* NetWare platform */
58
-#ifdef __NOVELL_LIBC__
59
-  #include <ctype.h>
60
-#else
61
-  extern int isdigit(int c);            /* no ctype.h for NW3.x */
62
-  #include <nwthread.h>
63
-  #define strncasecmp strnicmp
64
-#endif
65
-#elif defined(__OS2__)                  /* OS/2 platform */
66
-  #ifdef __EMX__
67
-    #define strncasecmp strnicmp
68
-  #endif
69
-  extern int DosSleep(long t);
70
-  #define delay DosSleep
71
-#else                                   /* all other platforms */
72
-  #define delay(t) usleep(t*1000)
73
-#endif
74
-#ifndef N_PLAT_NLM                      /* ! NetWare platform */
75
-  #include <ctype.h>
76
-#endif
77
-#ifndef WIN32                           /* ! Win32 platform */
78
-  #include <unistd.h>
79
-#endif
80
-#ifdef USE_WINSOCKAPI                   /* Winsock2 platforms */
81
-  #ifdef N_PLAT_NLM                     /* NetWare platform */
82
-    #include <ws2nlm.h>
83
-  #else
84
-    #include <winsock.h>
85
-  #endif
86
-  #define close(s) { \
87
-    closesocket(s); \
88
-    WSACleanup(); \
89
-  }
90
-#else                                   /* Socket platforms */
91
-  #include <sys/types.h>
92
-  #include <sys/socket.h>
93
-  #include <netinet/in.h>
94
-  #if defined(__OS2__) && !defined(__EMX__)
95
-    #include <utils.h>
96
-  #else
97
-    #include <arpa/inet.h>
98
-  #endif
99
-#endif
100
-
101
-#endif
102
-
103
-static int read_file (char *destfile);
104
-static int in_ether (char *bufp, unsigned char *addr);
105
-static int send_wol (char *dest, char *host);
106
-
107
-
108
-char *progname;
109
-int quiet = 0;
110
-int twait = 0;
111
-unsigned int port = 60000;
112
-unsigned long bcast = 0xffffffff;
113
-
114
-int main (int argc, char *argv[]) {
115
-
116
-    int cmdindx = 0;
117
-    progname    = argv[0];
118
-
119
-    if (argc > 1) {
120
-        /* parse input parameters */
121
-        for (argc--, argv++; *argv; argc--, argv++) {
122
-            char *bp;
123
-            char *ep;
124
-
125
-            if (strncasecmp (*argv, "-", 1) == 0) {
126
-                if (strncasecmp (*argv, "-F=", 3) == 0) {
127
-                    bp = *argv + 3;
128
-                    read_file (bp);
129
-                } else if (strncasecmp (*argv, "-B=", 3) == 0) {
130
-                    bp = *argv + 3;
131
-                    bcast = inet_addr(bp);
132
-                    if (bcast == -1) {
133
-                        fprintf (stderr, "%s: expected address argument at %s\n", progname, *argv);
134
-                        exit (1);
135
-                    }
136
-                } else if (strncasecmp (*argv, "-D=", 3) == 0) {
137
-                    bp = *argv + 3;
138
-                    twait = strtol (bp, &ep, 0);
139
-                    if (ep == bp || *ep != '\0') {
140
-                        fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
141
-                        exit (1);
142
-                    }
143
-                } else if (strncasecmp (*argv, "-P=", 3) == 0) {
144
-                    bp = *argv + 3;
145
-                    port = strtol (bp, &ep, 0);
146
-                    if (ep == bp || *ep != '\0') {
147
-                        fprintf (stderr, "%s: expected integer argument at %s\n", progname, *argv);
148
-                        exit (1);
149
-                    }
150
-                } else if (strncasecmp (*argv, "-Q", 2) == 0) {
151
-                    quiet = 1;
152
-                } else if (strncasecmp (*argv, "-V", 2) == 0) {
153
-                    fprintf (stderr, "\r%s Version %s\n", progname, VERSION);
154
-                    exit (0);
155
-                } else {
156
-                    fprintf (stderr, "\r%s: invalid or unknown option %s\n", progname, *argv);
157
-                    exit (1);
158
-                }
159
-            } else {
160
-                send_wol (*argv, "");
161
-            }
162
-        cmdindx++;
163
-        }
164
-        return (0);
165
-    } else {
166
-        /* No arguments given -> usage message */
167
-        fprintf (stderr, "\rUsage: %s [-q] [-b=<bcast>] [-p=<port>] [-d=<ms>] -f=<file> | <dest>\n", progname);
168
-        fprintf (stderr, "       need at least hardware address or file option\n");
169
-        return (-1);
170
-    }
171
-}
172
-
173
-
174
-
175
-static int in_ether (char *bufp, unsigned char *addr) {
176
-
177
-    char c, *orig;
178
-    int i;
179
-    unsigned char *ptr = addr;
180
-    unsigned val;
181
-
182
-    i = 0;
183
-    orig = bufp;
184
-    while ((*bufp != '\0') && (i < 6)) {
185
-        val = 0;
186
-        c = *bufp++;
187
-        if (isdigit(c))
188
-            val = c - '0';
189
-        else if (c >= 'a' && c <= 'f')
190
-            val = c - 'a' + 10;
191
-        else if (c >= 'A' && c <= 'F')
192
-            val = c - 'A' + 10;
193
-        else {
194
-#ifdef DEBUG
195
-            fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
196
-#endif
197
-            errno = EINVAL;
198
-            return (-1);
199
-        }
200
-        val <<= 4;
201
-        c = *bufp;
202
-        if (isdigit(c))
203
-            val |= c - '0';
204
-        else if (c >= 'a' && c <= 'f')
205
-            val |= c - 'a' + 10;
206
-        else if (c >= 'A' && c <= 'F')
207
-            val |= c - 'A' + 10;
208
-        else if (c == ':' || c == 0)
209
-            val >>= 4;
210
-        else {
211
-#ifdef DEBUG
212
-            fprintf (stderr, "\rin_ether(%s): invalid ether address!\n", orig);
213
-#endif
214
-            errno = EINVAL;
215
-            return (-1);
216
-        }
217
-        if (c != 0)
218
-            bufp++;
219
-        *ptr++ = (unsigned char) (val & 0377);
220
-        i++;
221
-
222
-        /* We might get a semicolon here - not required. */
223
-        if (*bufp == ':') {
224
-            if (i == 6) {
225
-                ;           /* nothing */
226
-            }
227
-            bufp++;
228
-        }
229
-    }
230
-    if (bufp - orig != 17) {
231
-        return (-1);
232
-    } else {
233
-        return (0);
234
-    }
235
-} /* in_ether */
236
-
237
-
238
-static int read_file (char *destfile) {
239
-
240
-    FILE    *pfile = NULL;
241
-    char    dest[64];
242
-    char    host[32];
243
-    char    buffer[512];
244
-
245
-    pfile = fopen (destfile, "r+");
22
+#include <errno.h>
23
+#include <byteswap.h>
24
+#include <gpxe/features.h>
25
+#include <gpxe/netdevice.h>
26
+#include <gpxe/if_ether.h>
27
+#include <gpxe/iobuf.h>
28
+#include <usr/ifmgmt.h>
29
+#include <usr/wol.h>
30
+#include <timer.h>
31
+
32
+/** @file
33
+ *
34
+ * Wake on lan
35
+ *
36
+ */
246
 
37
 
247
-    if (pfile) {
248
-        while (fgets (buffer, 511, pfile) != NULL) {
249
-            if (buffer[0] != '#' && buffer[0] != ';') {
250
-                dest[0] = host[0] = '\0';
251
-                sscanf (buffer, "%s %s", dest, host);
252
-                send_wol (dest, host);
253
-            }
38
+/**
39
+ * Boot from a network device
40
+ *
41
+ * @v netdev		Network device
42
+ * @ret rc		Return status code
43
+ */
44
+#define WOL_MSG_LEN (6 + 16*6)
45
+ 
46
+void wakeup_server(char *server_adr)
47
+{
48
+	int rc, i,j;
49
+	unsigned char *buf;
50
+	uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
51
+	unsigned int len;
52
+        struct io_buffer *iobuf;
53
+        struct ethhdr *ethhdr;
54
+        struct net_device *netdev;
55
+	
56
+	for_each_netdev ( netdev ) {
57
+	   break;
58
+	}
59
+
60
+        if (netdev == NULL)
61
+        {
62
+          printf("Could not find netdev\n");
63
+          return;
254
         }
64
         }
255
-        fclose (pfile);
256
-        return (0);
257
-    } else {
258
-        fprintf (stderr, "\r%s: destfile '%s' not found\n", progname, destfile);
259
-        return (-1);
260
-    }
261
-}
262
-
263
-
264
-static int send_wol (char *dest, char *host) {
265
-
266
-    int i, j;
267
-    int packet;
268
-    struct sockaddr_in sap;
269
-    unsigned char ethaddr[8];
270
-    unsigned char *ptr;
271
-    unsigned char buf [128];
272
-    unsigned long bc;
273
-    char mask[32];
274
-    char *tmp;
275
-#ifdef USE_WINSOCKAPI
276
-    WORD wVersionRequested;
277
-    WSADATA wsaData;
278
-    int err;
279
-#endif
280
-#ifdef WATTCP
281
-    static udp_Socket sock;
282
-    udp_Socket *s;
283
-#else
284
-    int optval = 1;
285
-#endif
286
-
287
-    /* Fetch the broascast address if present. */
288
-    if ((tmp = strstr(dest,"-"))) {
289
-printf("found: %s\n", tmp);
290
-       tmp[0] = 32;
291
-       sscanf (dest, "%s %s", mask, dest);
292
-       bc = inet_addr(mask);
293
-printf("bc: string %s address %08lX\n", mask, bc);
294
-       if (bc == -1) {
295
-           fprintf (stderr, "\r%s: expected address argument at %s\n", progname, mask);
296
-           return (-1);
297
-       }
298
-    } else
299
-       bc = bcast;
300
-
301
-    /* Fetch the hardware address. */
302
-    if (in_ether (dest, ethaddr) < 0) {
303
-        fprintf (stderr, "\r%s: invalid hardware address\n", progname);
304
-        return (-1);
305
-    }
306
-
307
-#ifdef USE_WINSOCKAPI
308
-    /* I would like to have Socket Vers. 1.1 */
309
-    wVersionRequested = MAKEWORD(1, 1);
310
-    err = WSAStartup (wVersionRequested, &wsaData);
311
-    if (err != 0) {
312
-        fprintf (stderr, "\r%s: couldn't init Winsock Version 1.1\n", progname);
313
-        WSACleanup ();
314
-        return (-1);
315
-    }
316
-#endif
317
-
318
-    /* setup the packet socket */
319
-#ifdef WATTCP
320
-    sock_init();
321
-    s = &sock;
322
-    if (!udp_open( s, 0, bc, port, NULL )) {
323
-#else
324
-    if ((packet = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
325
-#endif
326
-        fprintf (stderr, "\r%s: socket failed\n", progname);
327
-#ifdef USE_WINSOCKAPI
328
-        WSACleanup ();
329
-#endif
330
-        return (-1);
331
-    }
65
+               
66
+	/* Open device and display device status */
67
+	if ( (ifopen ( netdev ) ) != 0 )
68
+	{
69
+	  printf("Could not open netdev\n");
70
+	  return;
71
+	}
72
+
73
+	/* Create outgoing I/O buffer */
74
+	iobuf = alloc_iob ((ETH_HLEN + WOL_MSG_LEN)*2);
75
+	if (!iobuf)
76
+	{
77
+	   printf("Could not allocate iob\n");
78
+	   return;
79
+	}
80
+
81
+        ethhdr = iob_put(iobuf, sizeof(*ethhdr));
82
+        
83
+	/* Build Ethernet header */
84
+	memcpy (ethhdr->h_dest, eth_broadcast, ETH_ALEN );
85
+	memcpy (ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
86
+	ethhdr->h_protocol = htons (0x0842);
87
+	
88
+	buf    = iob_put (iobuf, WOL_MSG_LEN);
89
+
90
+        /* Build the message to send - 6 x 0xff then 16 x dest address */
91
+        len =0;
92
+        for (i = 0; i < 6; i++)
93
+           buf[len++] = 0xff;
94
+        for (j = 0; j < 16; j++)
95
+           for (i = 0; i < 6; i++)
96
+               buf[len++] = server_adr[i];      
332
 
97
 
333
-#ifndef WATTCP
334
-    /* Set socket options */
335
-    if (setsockopt (packet, SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof (optval)) < 0) {
336
-        fprintf (stderr, "\r%s: setsocket failed %s\n", progname, strerror (errno));
337
-        close (packet);
338
-        return (-1);
339
-    }
98
+	rc = netdev_tx (netdev, iobuf);
340
 
99
 
341
-    /* Set up broadcast address */
342
-    sap.sin_family = AF_INET;
343
-    sap.sin_addr.s_addr = bc;                 /* broadcast address */
344
-    sap.sin_port = htons(port);
345
-#endif
100
+	if (rc !=0)
101
+	   printf("Failed to transmit WOL packet\n");
346
 
102
 
347
-    /* Build the message to send - 6 x 0xff then 16 x dest address */
348
-    ptr = buf;
349
-    for (i = 0; i < 6; i++)
350
-        *ptr++ = 0xff;
351
-    for (j = 0; j < 16; j++)
352
-        for (i = 0; i < 6; i++)
353
-            *ptr++ = ethaddr [i];
103
+        /* Give the controller a chance to send it before checking */
104
+        mdelay(100);
354
 
105
 
355
-    /* Send the packet out */
356
-#ifdef WATTCP
357
-    sock_write( s, buf, 102 );
358
-    sock_close( s );
359
-#else
360
-    if (sendto (packet, (char *)buf, 102, 0, (struct sockaddr *)&sap, sizeof (sap)) < 0) {
361
-        fprintf (stderr, "\r%s: sendto failed, %s\n", progname, strerror(errno));
362
-        close (packet);
363
-        return (-1);
364
-    }
365
-    close (packet);
366
-#endif
367
-    if (!quiet) fprintf (stderr, "\r%s: packet sent to %04X:%08lX-%s %s\n",
368
-            progname, port, (unsigned long)htonl(bc), dest, host);
369
-    if (twait > 0 ) {
370
-        delay (twait);
371
-    }
372
-    return (0);
106
+	netdev_poll(netdev); 
373
 }
107
 }
374
 
108
 

+ 12
- 0
contrib/wakeonlan/wol.h View File

1
+#ifndef _USR_WOL_H
2
+#define _USR_WOL_H
3
+
4
+/** @file
5
+ *
6
+ * Wakeon lan
7
+ *
8
+ */
9
+
10
+extern void wakeup_server(char *);
11
+
12
+#endif /* _USR_WOL_H */

Loading…
Cancel
Save