Connectionless Ethernet library

The Ethernet library dearly needs a way to send packets without connecting a Client.

I would specifically want to send Wake-On-LAN magic packets - a UDP datagram would work just fine, but there's currently no high-level way to send anything to remote hosts that obviously aren't there to respond...

Check out this thread, which points to this site.

haven't tried it myself (yet).

I would be interested in seeing your WoL code, if you feel like sharing.

-j

Thanks for the hint - looks pretty straightforward, unfortunately it seems to consume resources and might not fit into my already crammed application...

I'll probably need to try it as a proof of concept anyway, I will then post the code :slight_smile:

OK - I actually didn't use any of that UDP wrapper code, since all it does is wrap... The minimal code to send a WOL packet, assuming we live in subnet 10.0.0.x/24:

extern "C" {
#include "utility/types.h"
#include "utility/w5100.h"
#include "utility/socket.h"
}
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 111 };

void setup() {
Ethernet.begin(mac, ip);
}

void loop() {
uint8_t socket_index = 0;
uint8_t txbuf[102]; /* Size of magic packet = 6 + 16*6 */
uint8_t p;
byte n, i;
uint8_t remote_ip[] = {10, 0, 0, 255}; /
Broadcast address /
uint8_t remote_mac[] = {0x00, 0x0e, 0x2e, 0x0a, 0x23, 0x19}; /
Remote's MAC */

/* Use 9999 as source port, shouldn't be of any relevance */
socket(socket_index, Sn_MR_UDP, 9999, 0);

/* Magic packet is 6 * 0xff followed by 16 times the destination MAC */
p = txbuf;
for(n = 0; n < 6; n++) p++ = 0xff;
for(n = 0; n < 16; n++) {
for(i = 0; i < 6; i++) p++ = remote_mac;

  • }*
    /* Send to remote_ip and port 0 (port doesn't matter) /
    sendto(socket_index, txbuf, 6 + 616, remote_ip, 9999);
  • close(socket_index);*
  • for(;;);*
    }
    The sad part here is that this can't really coexist with the normal Ethernet code during the time it is actually used, since we run over it - e.g. Server.begin() allocates all of the four sockets W5100 offers us, and so socket 0 used above is not free anymore then. That UDP example code linked previously in this topic has the same problem, though.
    I only tested this with one remote, and for some peculiar reason it really needed this packet to be sent to the broadcast IP address. As far as I understand, it should not matter since the NIC - which does all the work while the host system sleeps - doesn't even know its IP address when it receives the WOL packet.

for some peculiar reason it really needed this packet to be sent to the broadcast IP address.

Isn't that part of the specification for how WoL works?

--Phil.

Yes, you're right - but for some reason the helper program I've used to send WOL packets (wolcmd.exe) worked just fine using a single IP as destination address. I guess it sets the broadcast bit anyway.

But still, I would like to see further development on the Ethernet library, it's quite rudimentary as it is now (how do you shut down a server, for example?) :slight_smile: But I guess this is a hard task, it uses a large part of the sketch space already...