]> gitweb.factorcode.org Git - factor.git/blob - extra/wake-on-lan/wake-on-lan.factor
scryfall: better moxfield words
[factor.git] / extra / wake-on-lan / wake-on-lan.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: arrays destructors io.sockets kernel math.parser
5 sequences splitting ;
6
7 IN: wake-on-lan
8
9 <PRIVATE
10
11 : mac-address-bytes ( mac-address -- byte-array )
12     ":-" split [ hex> ] B{ } map-as ;
13
14 : wake-on-lan-packet ( mac-address -- byte-array )
15     [ 16 ] [ mac-address-bytes ] bi* <array> concat
16     B{ 0xff 0xff 0xff 0xff 0xff 0xff } prepend ;
17
18 PRIVATE>
19
20 : wake-on-lan ( mac-address broadcast-ip -- )
21     [ wake-on-lan-packet ] [ 9 <inet4> ] bi*
22     broadcast-once ;