]> gitweb.factorcode.org Git - factor.git/commitdiff
wake-on-lan: adding support for Wake-on-LAN protocol.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 18 Jun 2012 19:47:21 +0000 (12:47 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 18 Jun 2012 19:47:21 +0000 (12:47 -0700)
extra/wake-on-lan/authors.txt [new file with mode: 0644]
extra/wake-on-lan/summary.txt [new file with mode: 0644]
extra/wake-on-lan/wake-on-lan.factor [new file with mode: 0644]

diff --git a/extra/wake-on-lan/authors.txt b/extra/wake-on-lan/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/wake-on-lan/summary.txt b/extra/wake-on-lan/summary.txt
new file mode 100644 (file)
index 0000000..6ecaafb
--- /dev/null
@@ -0,0 +1 @@
+Wake-on-LAN support
diff --git a/extra/wake-on-lan/wake-on-lan.factor b/extra/wake-on-lan/wake-on-lan.factor
new file mode 100644 (file)
index 0000000..4308290
--- /dev/null
@@ -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 ;