Skip to content

Commit

Permalink
Merge pull request #9 from leshow/add_str
Browse files Browse the repository at this point in the history
add str type to options arg
  • Loading branch information
leshow authored Jan 7, 2025
2 parents 0c81c88 + 4106b5f commit b33e0ef
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
[package]
name = "dhcpm"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
authors = ["Evan Cameron <[email protected]"]
description = """
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.
"""
categories = ["network-programming", "development-tools","command-line-utilities"]
categories = [
"network-programming",
"development-tools",
"command-line-utilities",
]
repository = "https://github.com/leshow/dhcpm"
keywords = ["dhcp","dhcpv4","dhcpv6", "cli"]
keywords = ["dhcp", "dhcpv4", "dhcpv6", "cli"]
license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dhcproto = "0.9.0"
dhcproto = "0.12.0"
anyhow = "1.0"
argh = "0.1.7"
crossbeam-channel = "0.5.1"
ctrlc = "3.1"
mac_address = "1.1.1"
tracing = "0.1"
tracing-subscriber = { version = "0.3.14", features = ["env-filter","json"] }
tracing-subscriber = { version = "0.3.14", features = ["env-filter", "json"] }
rand = "0.8"
hex = "0.4"
rhai = { version = "1.5.0", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions src/bootreq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct BootReqArgs {
/// sname [default: None]
#[argh(option)]
pub sname: Option<String>,
/// 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<v4::DhcpOption>,
}
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ fn ctrl_channel() -> Result<Receiver<()>> {
#[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:
Expand Down
3 changes: 2 additions & 1 deletion src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ pub fn parse_opts(input: &str) -> Result<v4::DhcpOption, String> {
let code = code.parse::<u8>().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::<Ipv4Addr>()
.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}");
Expand Down

0 comments on commit b33e0ef

Please sign in to comment.