Documentation
¶
Overview ¶
Package wol builds and sends Wake-on-LAN magic packets. It imports only the standard library so both sqi-server and sqi-worker can use it.
Index ¶
- Constants
- func DirectedBroadcast(cidr string) (net.IP, bool)
- func MagicPacket(mac net.HardwareAddr) ([]byte, error)
- func Send(ctx context.Context, macs []net.HardwareAddr, targets []string, burst int, ...) (reached int, err error)
- func SendDefault(ctx context.Context, macs []net.HardwareAddr, targets []string) (reached int, err error)
Constants ¶
const ( // DefaultPort is the conventional Wake-on-LAN UDP port (discard). DefaultPort = 9 // DefaultBurst is how many copies of each packet are sent; UDP gives no // delivery guarantee, and a sleeping NIC only needs one to arrive. DefaultBurst = 3 // DefaultGap is the pause between bursts. DefaultGap = 100 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
func DirectedBroadcast ¶
DirectedBroadcast returns the IPv4 subnet-directed broadcast address of cidr ("192.168.1.20/24" gives 192.168.1.255). ok is false for IPv6, for /31 and /32 (which have no broadcast address), and for input that does not parse.
func MagicPacket ¶
func MagicPacket(mac net.HardwareAddr) ([]byte, error)
MagicPacket returns the 102-byte magic packet for mac: six 0xFF bytes followed by the 6-byte MAC repeated 16 times. It is an error unless mac is exactly 6 bytes.
func Send ¶
func Send(ctx context.Context, macs []net.HardwareAddr, targets []string, burst int, gap time.Duration) (reached int, err error)
Send sends burst copies of each MAC's magic packet to each target ("ip:port"), gap apart, over UDP with SO_BROADCAST set, and reports how many targets it reached: those at least one packet write to succeeded. A bad MAC, an unresolvable target or a failed write is recorded and Send keeps going; the returned error joins every one of them, so a caller can count a send that reached some targets as done and still log the rest. A canceled ctx stops Send early and its error is joined in too.
func SendDefault ¶
func SendDefault(ctx context.Context, macs []net.HardwareAddr, targets []string) (reached int, err error)
SendDefault is Send with DefaultBurst and DefaultGap.
Types ¶
This section is empty.