wake-on-lan: adding support for Wake-on-LAN protocol.

db4
John Benediktsson 2012-06-18 12:47:21 -07:00
parent a3829530aa
commit 6f1f6767bd
3 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -0,0 +1 @@
Wake-on-LAN support

View File

@ -0,0 +1,22 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: arrays destructors io.sockets kernel math.parser
sequences splitting ;
IN: wake-on-lan
<PRIVATE
: mac-address-bytes ( mac-address -- byte-array )
":-" split [ hex> ] B{ } map-as ;
: wake-on-lan-packet ( mac-address -- bytearray )
[ 16 ] [ mac-address-bytes ] bi* <array> concat
B{ 0xff 0xff 0xff 0xff 0xff 0xff } prepend ;
PRIVATE>
: wake-on-lan ( mac-address broadcast-ip -- )
[ wake-on-lan-packet ] [ 9 <inet4> ] bi*
f 0 <inet4> <broadcast> [ send ] with-disposal ;