LuaP logo
">

Wake on LAN

Or how I did it in less than 2 hours, without crying, wailing, or gnashing my teeth

First off, I had a read of http://www.networking.ibm.com/eji/ejiwake.html (and if IBM move it again, give them some verbal abuse).

At this point, I reckoned that an ethernet packet with a payload of 6 lots of 0xff, and 16 lots of the MAC address would be a suitable wake-up packet (i.e. no mention of IP, tcp or udp) might do the job. However, I didn't know how other things on the network would feel about packets like that flying around, and whether it mgiht cause unintended nasties.

I had a butcher's at http://search.cpan.org/src/CLINTDW/Net-Wake-0.01/, and saw that he'd used udp packets over IP (udp - good choice, its a connectionless protocol, so doesn't expect a reply, you just hammer out a datagram). On the point of IP, sending the packet to the IP address that the target had when it was awake might make sense if you haven't expired your arp cache entry for that host, and any ethernet switches or hubs between source and target aren't going to get confused. So, likelihood is that the WoL packet is going to get sent on the subnet broadcast address, to avoid bad stuff in general.

I also noticed that that guy had decided to send his udp packets to port 9, the "discard" port, which is also sensible, as anybody else who receives them should just ignore it.

So, on to make some packets. Libnet is a wonderful thing. Moreover, libnet samples are also wonderful. I took the udp1 example, and hacked it to have a coded-in payload of lots of FF's, then a MAC address 16 times. I maked it, then ran it to send a packet from my IP to the subnet broadcast address. Behold, yonder computer waked, and I was well pleased.

Some source code follows. As I said, hacked around from the sample code in libnet, and maked using the makefile as supplied in the sample directory. Please bear in mind that I'm not a programmer by reputation, profession or claim, and that I'm very very very lazy. Ugly code, of which I think I wrote only 2 lines, an those badly, and in the wrong place.

Here's how I ran it:

./udp1 -s 192.1.1.207.122 -d 192.1.255.255.9 -p werble

Yes I did mean 192.1.1.207, no I don't own that IP, my company is abusing someone else's IPs rather than using one of the ranges reserved for local networks. Yes, I am horrified by it.


This page has been created by, and is maintained by Paul Norton. All content is Copyright Paul Norton 2002/2003 unless otherwise stated.
Comments, questions, notices etc should be sent to: luap@icculus.org
(Timezone: America/New York)