Commit Graph

11 Commits (master)

Author SHA1 Message Date
Dustin 22c5fd4832 Add rustdoc comments
This commit adds documentation comments to the public API. In order for
`cargo doc` to build the documentation site, though, the crate must be a
library, so the `lib.rs` is needed to expose the necessary bits.
2018-09-29 12:11:10 -05:00
Dustin 60dd1f72dc main: Accept addresses as command-line arguments
Now that the `MacAddress` struct can handle parsing arbitrary input
without panicking, the main entry point can accept values from the user
in the form of command-line arguments. Users can pass one or more
addresses as positional arguments to the `wakeonlan` program, and a
magic packet will be sent to each one in series.
2018-09-29 11:42:34 -05:00
Dustin 823cfc2593 mac: Support parsing hyphen-separated addresses
Windows utilities typically display MAC addresses formatted with hyphens
separating the octets. Natively supporting parsing these representations
makes it easier for users to simply paste them, without having to
manually change the hyphens to colons.
2018-09-29 11:40:55 -05:00
Dustin 989a6eb0e6 mac: impl Debug and Display for MacAddress
Adding implementations of the `Debug` and `Display` traits to the
`MacAddress` struct allows creating string representations of these
objects.
2018-09-29 11:39:19 -05:00
Dustin ff8316895a mac: Handle improperly-formatted addresses
This commit introduces a new variant to the `ParseError` enumeration,
`ParseError::Format`. This error is returned by
`MacAddress::from_string()` when the input string is not correctly
formatted.
2018-09-29 11:38:35 -05:00
Dustin cc9f630dbc mac: Add ParseError enum
The `mac::ParseError` enumeration is intended to represent all of the
possible ways `MacAddress::from_string` could fail. For now, the only
known problem is an invalid hexadecimal integer found in one of the
octets, which causes a `ParseIntError`. The `ParseError` enum implements
the `Debug`, `Display`, and `Error` traits.
2018-09-20 20:56:37 -05:00
Dustin e3e4c39f21 mac: Add test for MacAddress::from_string 2018-09-19 22:38:55 -05:00
Dustin c0b462d8ac mac: Add MacAddress type
The `MacAddress` structure represents a 48-bit hardware address. Using a
dedicated type instead of an array will make it easier to validate
inputs and ensure type safety.
2018-08-17 20:12:52 -05:00
Dustin 8b0ce4c5be magic: Add MagicPacket.send_to method
On the off chance that the magic packet needs to be sent to a
destination other than port 9 on the subnet-directed broadcast address,
the `send_to` method is now available on the `MagicPacket` structure.
The `send` method is retained, and now simply delegates to the `send_to`
method with a hard-coded socket address.
2018-08-16 23:00:47 -05:00
Dustin 9b0fb35ed5 magic: Use an iterator to generate the byte stream
Instead of explicitly writing the byte array for the magic packet
content, the `MagicPacket.send` method now delegates to
`MagicPacketIterator`. It collects the values the iterator produces,
which are determined based on the number of times the `next` method has
been called, into a vector, and then passes a slice of that vector to
the `send` method of the UDP socket.

Using a vector of course requires allocating space on the heap, so while
this method is probably not as efficient as the previous stack-allocated
static array, it is certainly cleaner and easier to understand.
2018-08-16 22:59:55 -05:00
Dustin 84bf8c04cd Initial commit 2018-08-14 22:09:15 -05:00