An OCaml library for constructing Wake-on-LAN magic packets
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Mirage support

+132 -44
+1
.gitignore
··· 1 + _build
+1
.ocamlformat
··· 1 + version=0.26.0
+2 -1
bin/dune
··· 1 1 (executable 2 2 (name owol) 3 3 (public_name owol) 4 + (package wol-eio) 4 5 (modules owol) 5 - (libraries wol cmdliner)) 6 + (libraries eio_main wol_eio cmdliner))
+1 -1
bin/owol.ml
··· 1 1 2 2 let send_wol mac port broadcast = 3 3 Eio_posix.run @@ fun env -> 4 - Wol.send ~net:env#net ~port ~broadcast mac 4 + Wol_eio.send ~net:env#net ~port ~broadcast mac 5 5 6 6 let () = 7 7 let open Cmdliner in
+17 -1
dune-project
··· 19 19 (name wol) 20 20 (synopsis "A short synopsis") 21 21 (description "A longer description") 22 - (depends ocaml dune eio_main ipaddr) 22 + (depends ipaddr) 23 + (tags 24 + (topics "to describe" your project))) 25 + 26 + (package 27 + (name wol-mirage) 28 + (synopsis "A short synopsis") 29 + (description "A longer description") 30 + (depends wol tcpip) 31 + (tags 32 + (topics "to describe" your project))) 33 + 34 + (package 35 + (name wol-eio) 36 + (synopsis "A short synopsis") 37 + (description "A longer description") 38 + (depends wol eio eio_main) 23 39 (tags 24 40 (topics "to describe" your project))) 25 41
-3
lib/dune
··· 1 - (library 2 - (name wol) 3 - (libraries eio_main ipaddr str))
-36
lib/wol.ml
··· 1 - 2 - let mac_of_string mac_str = 3 - List.map (fun x -> int_of_string ("0x" ^ x)) (Str.split (Str.regexp ":") mac_str) 4 - |> Array.of_list 5 - 6 - let mac_to_bytes mac = 7 - String.split_on_char ':' mac 8 - |> List.map (fun x -> int_of_string ("0x" ^ x)) 9 - 10 - let repeat_list n list = 11 - List.init n (fun _ -> list) 12 - |> List.concat 13 - 14 - let construct_magic_packet mac_str = 15 - let prefix = [0xFF; 0xFF; 0xFF; 0xFF; 0xFF; 0xFF] in 16 - let mac_bytes = mac_to_bytes mac_str in 17 - let repeated_mac = repeat_list 16 mac_bytes in 18 - let packet_data = prefix @ repeated_mac in 19 - let buf = Cstruct.create (List.length packet_data) in 20 - List.iteri (fun i byte -> Cstruct.set_uint8 buf i byte) packet_data; 21 - buf 22 - 23 - let send ~net ?(port=9) ?(broadcast="255.255.255.255") mac_str = 24 - Eio.Switch.run @@ fun sw -> 25 - let addr = Ipaddr.V4.of_string_exn broadcast |> Ipaddr.V4.to_octets |> Eio.Net.Ipaddr.of_raw in 26 - let sock = 27 - let proto = 28 - Eio.Net.Ipaddr.fold 29 - ~v4:(fun _v4 -> `UdpV4) 30 - ~v6:(fun _v6 -> `UdpV6) 31 - addr 32 - in 33 - Eio.Net.datagram_socket ~sw net proto 34 - in 35 - let packet = construct_magic_packet mac_str in 36 - Eio.Net.send sock ~dst:(`Udp (addr, port)) [ packet ]
+4
src/eio/dune
··· 1 + (library 2 + (name wol_eio) 3 + (public_name wol-eio) 4 + (libraries eio wol))
+14
src/eio/wol_eio.ml
··· 1 + let send ~net ?(port=9) ?(broadcast="255.255.255.255") mac_str = 2 + Eio.Switch.run @@ fun sw -> 3 + let addr = 4 + Ipaddr.V4.of_string_exn broadcast 5 + |> Ipaddr.V4.to_octets |> Eio.Net.Ipaddr.of_raw 6 + in 7 + let sock = 8 + let proto = 9 + Eio.Net.Ipaddr.fold ~v4:(fun _v4 -> `UdpV4) ~v6:(fun _v6 -> `UdpV6) addr 10 + in 11 + Eio.Net.datagram_socket ~sw net proto 12 + in 13 + let packet = Wol.magic_packet (Macaddr.of_string_exn mac_str) in 14 + Eio.Net.send sock ~dst:(`Udp (addr, port)) [ packet ]
+4
src/lib/dune
··· 1 + (library 2 + (name wol) 3 + (public_name wol) 4 + (libraries ipaddr macaddr cstruct))
+12
src/lib/wol.ml
··· 1 + let magic_packet (mac : Macaddr.t) = 2 + let mac = Macaddr.to_octets mac in 3 + let buf = Cstruct.create 102 in 4 + for i = 0 to 5 do 5 + Cstruct.set_uint8 buf i 0xFF 6 + done; 7 + for i = 0 to 15 do 8 + for j = 0 to 5 do 9 + Cstruct.set_char buf (6 + (i * 6) + j) mac.[j] 10 + done 11 + done; 12 + buf
+1
src/lib/wol.mli
··· 1 + val magic_packet : Macaddr.t -> Cstruct.t
+4
src/mirage/dune
··· 1 + (library 2 + (name wol_mirage) 3 + (public_name wol-mirage) 4 + (libraries wol tcpip))
+6
src/mirage/wol_mirage.ml
··· 1 + module Make (D : Tcpip.Udp.S with type ipaddr = Ipaddr.V4.t) = struct 2 + let send ?(port = 9) ?(broadcast="255.255.255.255") sock mac = 3 + let addr = Ipaddr.V4.of_string_exn broadcast in 4 + let packet = Wol.magic_packet mac in 5 + D.write sock ~dst:addr ~dst_port:port packet 6 + end
+33
wol-eio.opam
··· 1 + # This file is generated by dune, edit dune-project instead 2 + opam-version: "2.0" 3 + synopsis: "A short synopsis" 4 + description: "A longer description" 5 + maintainer: ["Maintainer Name"] 6 + authors: ["Author Name"] 7 + license: "LICENSE" 8 + tags: ["topics" "to describe" "your" "project"] 9 + homepage: "https://github.com/username/reponame" 10 + doc: "https://url/to/documentation" 11 + bug-reports: "https://github.com/username/reponame/issues" 12 + depends: [ 13 + "dune" {>= "3.10"} 14 + "wol" 15 + "eio" 16 + "eio_main" 17 + "odoc" {with-doc} 18 + ] 19 + build: [ 20 + ["dune" "subst"] {dev} 21 + [ 22 + "dune" 23 + "build" 24 + "-p" 25 + name 26 + "-j" 27 + jobs 28 + "@install" 29 + "@runtest" {with-test} 30 + "@doc" {with-doc} 31 + ] 32 + ] 33 + dev-repo: "git+https://github.com/username/reponame.git"
+32
wol-mirage.opam
··· 1 + # This file is generated by dune, edit dune-project instead 2 + opam-version: "2.0" 3 + synopsis: "A short synopsis" 4 + description: "A longer description" 5 + maintainer: ["Maintainer Name"] 6 + authors: ["Author Name"] 7 + license: "LICENSE" 8 + tags: ["topics" "to describe" "your" "project"] 9 + homepage: "https://github.com/username/reponame" 10 + doc: "https://url/to/documentation" 11 + bug-reports: "https://github.com/username/reponame/issues" 12 + depends: [ 13 + "dune" {>= "3.10"} 14 + "wol" 15 + "tcpip" 16 + "odoc" {with-doc} 17 + ] 18 + build: [ 19 + ["dune" "subst"] {dev} 20 + [ 21 + "dune" 22 + "build" 23 + "-p" 24 + name 25 + "-j" 26 + jobs 27 + "@install" 28 + "@runtest" {with-test} 29 + "@doc" {with-doc} 30 + ] 31 + ] 32 + dev-repo: "git+https://github.com/username/reponame.git"
-2
wol.opam
··· 10 10 doc: "https://url/to/documentation" 11 11 bug-reports: "https://github.com/username/reponame/issues" 12 12 depends: [ 13 - "ocaml" 14 13 "dune" {>= "3.10"} 15 - "eio_main" 16 14 "ipaddr" 17 15 "odoc" {with-doc} 18 16 ]