Skip to content

Instantly share code, notes, and snippets.

@aharisu
Created June 29, 2012 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aharisu/3018095 to your computer and use it in GitHub Desktop.
Save aharisu/3018095 to your computer and use it in GitHub Desktop.
Wake-on-LANのマジックパケットを投げつけるだけ
(use gauche.parseopt)
(use gauche.uvector)
(use gauche.net)
(define (usage)
(print "Usage: gosh wol.scm [-m|--mac=<mac-addr>]")
(print "Example: gosh wol.scm -m=1a-2b-3c-4d-5e-6f")
)
(define (main args)
(let-args (cdr args)
([mac-addr "m|mac=s" =>
(.$
list->u8vector
(pa$ map (cut string->number <> 16))
(cut string-split <> "-"))]
[#f "help" => usage]
[else (opt . _) (print "Unknown option : " opt) (usage)]
. args)
(if (and mac-addr (= 6 (u8vector-length mac-addr)))
(let ([buf (make-u8vector (* 6 17))]
[sock (make-socket AF_INET SOCK_DGRAM)])
(dotimes [i 6] (u8vector-set! buf i 255))
(dotimes [i 16] (u8vector-copy! buf (* (+ i 1) 6) mac-addr))
(socket-setsockopt sock #xffff #x20 1)
(socket-sendto sock buf
(make <sockaddr-in> :host :broadcast :port 7)))
(usage))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment