diff --git a/Cargo.lock b/Cargo.lock index 94230f7..534dc9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -130,7 +130,7 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "dhcpm" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "argh", @@ -149,9 +149,9 @@ dependencies = [ [[package]] name = "dhcproto" -version = "0.9.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcee045385d5f7819022821f41209b9945d17550760b0b2349aaef4ecfa14bc3" +checksum = "f6794294f2c4665aae452e950c2803a1e487c5672dc8448f0bfa3f52ff67e270" dependencies = [ "dhcproto-macros", "hex", @@ -399,9 +399,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "percent-encoding" diff --git a/Cargo.toml b/Cargo.toml index b6f3053..fa6ed62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,26 +1,30 @@ [package] name = "dhcpm" -version = "0.2.3" +version = "0.2.4" edition = "2021" authors = ["Evan Cameron , - /// add opts to the message - /// [ex: these are equivalent- "118,hex,C0A80001" or "118,ip,192.168.0.1"] + /// add opts to the message ("code,type,value") + /// [ex: "118,hex,C0A80001" or "118,ip,192.168.0.1" or "60,str,foobar"] #[argh(option, short = 'o', from_str_fn(parse_opts))] pub opt: Vec, } diff --git a/src/main.rs b/src/main.rs index e3775a0..f10b39e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,11 +267,11 @@ fn ctrl_channel() -> Result> { #[argh(description = "dhcpm is a cli tool for sending dhcpv4/v6 messages ex dhcpv4: - dhcpm 255.255.255.255 discover (broadcast discover to default dhcp port) - dhcpm 192.168.0.255 discover (broadcast discover on interface bound to 192.168.0.x) - dhcpm 0.0.0.0 -p 9901 discover (unicast discover to 0.0.0.0:9901) - dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1) - dhcpm 192.168.0.1 dora -o 118,C0A80001 (unicast DORA, incl opt 118:192.168.0.1) + dhcpm 255.255.255.255 discover (broadcast discover to default dhcp port) + dhcpm 192.168.0.255 discover (broadcast discover on interface bound to 192.168.0.x) + dhcpm 0.0.0.0 -p 9901 discover (unicast discover to 0.0.0.0:9901) + dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1) + dhcpm 192.168.0.1 dora -o 118,hex,C0A80001 (unicast DORA, incl opt 118:192.168.0.1) bootp: dhcpm 255.255.255.255 bootreq (broadcast BOOTREQ) dhcpv6: diff --git a/src/opts.rs b/src/opts.rs index 3f1ff9b..3fdc65f 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -87,12 +87,13 @@ pub fn parse_opts(input: &str) -> Result { let code = code.parse::().map_err(|_| "error parsing OptionCode")?; let opt = match *ty { "hex" => Ok(hex::decode(val).map_err(|_| "decoding hex failed")?), + "str" => Ok(val.as_bytes().to_vec()), "ip" => Ok(val .parse::() .map_err(|_| "decoding IP failed")? .octets() .to_vec()), - _ => Err("failed to decode with a type we understand \"hex\" or \"ip\""), + _ => Err("failed to decode with a type we understand \"hex\" or \"ip\" or \"str\""), }?; Ok(write_opt(code, opt).map_err(|e| { eprintln!("{e}");