wake

package
v1.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wake is the RemoHop Wake-on-LAN service: the magic packet itself, a host handler that sends it on the host's LAN, a client API, and the `remohop wake` / `remohop <ID> wol` commands.

The useful form is the remote one. A sleeping PC cannot be reached over the internet, but a small always-on machine on the same LAN can broadcast the magic packet for it.

Index

Constants

View Source
const DefaultPort = 9

DefaultPort is the UDP "discard" port most network cards listen on.

Variables

This section is empty.

Functions

func Packet

func Packet(mac net.HardwareAddr) []byte

Packet builds the magic packet: six 0xFF bytes then the MAC sixteen times.

func ParseMAC

func ParseMAC(s string) (net.HardwareAddr, error)

ParseMAC accepts aa:bb:cc:dd:ee:ff, aa-bb-cc-dd-ee-ff, aabb.ccdd.eeff and bare aabbccddeeff, in either case. The all-zero and all-ones addresses are refused: neither is a machine.

func ValidName

func ValidName(name string) error

ValidName reports whether name can be saved. Names that parse as MAC addresses are refused so `remohop wake X` is never ambiguous.

Types

type Entry

type Entry struct {
	Name string `json:"name"`
	MAC  string `json:"mac"`
}

Entry is one saved name.

type Options

type Options struct {
	// Broadcast is the destination IPv4 address, usually a subnet broadcast
	// address such as 192.168.1.255. Empty means every broadcast-capable
	// interface of this machine. Only the local (CLI) path honours it: a host
	// never lets a remote peer pick where it sends packets.
	Broadcast string `json:"-"`
	// Port is the UDP destination port; 0 means DefaultPort.
	Port int `json:"port,omitempty"`
}

Options tune a send. The zero value broadcasts on every IPv4 interface to port 9.

type Result

type Result struct {
	MAC     string   `json:"mac"`
	Port    int      `json:"port"`
	Targets []string `json:"targets"` // destinations the packet was sent to
}

Result reports what was sent.

func Remote

func Remote(ctx context.Context, conn *peer.Conn, mac string, opts Options) (*Result, error)

Remote asks the host behind conn to send the magic packet on its LAN. Only opts.Port is used; the host decides the destinations.

func Send

func Send(ctx context.Context, mac string, opts Options) (*Result, error)

Send broadcasts the magic packet for mac from this machine.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store remembers MAC addresses under short names, in a 0600 JSON file in the config directory.

func OpenStore

func OpenStore() (*Store, error)

OpenStore returns the store in the config directory.

func (*Store) Forget

func (s *Store) Forget(name string) (bool, error)

Forget removes name; it reports whether it existed.

func (*Store) List

func (s *Store) List() ([]Entry, error)

List returns the saved names in alphabetical order.

func (*Store) Lookup

func (s *Store) Lookup(name string) (string, bool, error)

Lookup returns the MAC saved under name.

func (*Store) Save

func (s *Store) Save(name, mac string) error

Save stores mac (normalised) under name, replacing any earlier entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL