Skip to content

Commit b33e0ef

Browse files
authored
Merge pull request #9 from leshow/add_str
add str type to options arg
2 parents 0c81c88 + 4106b5f commit b33e0ef

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
[package]
22
name = "dhcpm"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
edition = "2021"
55
authors = ["Evan Cameron <[email protected]"]
66
description = """
77
A cli for mocking DHCP messages and running rhai scripts to test DHCP servers. Aims to support v4 & v6, thought v6 is as of yet unfinished.
88
"""
9-
categories = ["network-programming", "development-tools","command-line-utilities"]
9+
categories = [
10+
"network-programming",
11+
"development-tools",
12+
"command-line-utilities",
13+
]
1014
repository = "https://github.com/leshow/dhcpm"
11-
keywords = ["dhcp","dhcpv4","dhcpv6", "cli"]
15+
keywords = ["dhcp", "dhcpv4", "dhcpv6", "cli"]
1216
license = "MIT"
1317
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1418

1519
[dependencies]
16-
dhcproto = "0.9.0"
20+
dhcproto = "0.12.0"
1721
anyhow = "1.0"
1822
argh = "0.1.7"
1923
crossbeam-channel = "0.5.1"
2024
ctrlc = "3.1"
2125
mac_address = "1.1.1"
2226
tracing = "0.1"
23-
tracing-subscriber = { version = "0.3.14", features = ["env-filter","json"] }
27+
tracing-subscriber = { version = "0.3.14", features = ["env-filter", "json"] }
2428
rand = "0.8"
2529
hex = "0.4"
2630
rhai = { version = "1.5.0", optional = true }

src/bootreq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub struct BootReqArgs {
3030
/// sname [default: None]
3131
#[argh(option)]
3232
pub sname: Option<String>,
33-
/// add opts to the message
34-
/// [ex: these are equivalent- "118,hex,C0A80001" or "118,ip,192.168.0.1"]
33+
/// add opts to the message ("code,type,value")
34+
/// [ex: "118,hex,C0A80001" or "118,ip,192.168.0.1" or "60,str,foobar"]
3535
#[argh(option, short = 'o', from_str_fn(parse_opts))]
3636
pub opt: Vec<v4::DhcpOption>,
3737
}

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ fn ctrl_channel() -> Result<Receiver<()>> {
267267
#[argh(description = "dhcpm is a cli tool for sending dhcpv4/v6 messages
268268
269269
ex dhcpv4:
270-
dhcpm 255.255.255.255 discover (broadcast discover to default dhcp port)
271-
dhcpm 192.168.0.255 discover (broadcast discover on interface bound to 192.168.0.x)
272-
dhcpm 0.0.0.0 -p 9901 discover (unicast discover to 0.0.0.0:9901)
273-
dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1)
274-
dhcpm 192.168.0.1 dora -o 118,C0A80001 (unicast DORA, incl opt 118:192.168.0.1)
270+
dhcpm 255.255.255.255 discover (broadcast discover to default dhcp port)
271+
dhcpm 192.168.0.255 discover (broadcast discover on interface bound to 192.168.0.x)
272+
dhcpm 0.0.0.0 -p 9901 discover (unicast discover to 0.0.0.0:9901)
273+
dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1)
274+
dhcpm 192.168.0.1 dora -o 118,hex,C0A80001 (unicast DORA, incl opt 118:192.168.0.1)
275275
bootp:
276276
dhcpm 255.255.255.255 bootreq (broadcast BOOTREQ)
277277
dhcpv6:

src/opts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ pub fn parse_opts(input: &str) -> Result<v4::DhcpOption, String> {
8787
let code = code.parse::<u8>().map_err(|_| "error parsing OptionCode")?;
8888
let opt = match *ty {
8989
"hex" => Ok(hex::decode(val).map_err(|_| "decoding hex failed")?),
90+
"str" => Ok(val.as_bytes().to_vec()),
9091
"ip" => Ok(val
9192
.parse::<Ipv4Addr>()
9293
.map_err(|_| "decoding IP failed")?
9394
.octets()
9495
.to_vec()),
95-
_ => Err("failed to decode with a type we understand \"hex\" or \"ip\""),
96+
_ => Err("failed to decode with a type we understand \"hex\" or \"ip\" or \"str\""),
9697
}?;
9798
Ok(write_opt(code, opt).map_err(|e| {
9899
eprintln!("{e}");

0 commit comments

Comments
 (0)