Skip to content

Commit

Permalink
Fix trim usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Jul 21, 2017
1 parent 638578a commit 9d3b8da
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/dhcpd/main.rs
Expand Up @@ -23,14 +23,14 @@ macro_rules! try_fmt {
fn dhcp(quiet: bool) -> Result<(), String> {
let current_mac = MacAddr::from_str(try_fmt!(getcfg("mac"), "failed to get current mac").trim());

let current_ip = getcfg("ip").unwrap_or("0.0.0.0".to_string()).trim();
let current_ip = getcfg("ip").unwrap_or("0.0.0.0".to_string());
if ! quiet {
println!("DHCP: MAC: {} Current IP: {}", current_mac.to_string(), current_ip);
println!("DHCP: MAC: {} Current IP: {}", current_mac.to_string(), current_ip.trim());
}

let tid = try_fmt!(time::SystemTime::now().duration_since(time::UNIX_EPOCH), "failed to get time").subsec_nanos();

let socket = try_fmt!(UdpSocket::bind((current_ip.as_str(), 68)), "failed to bind udp");
let socket = try_fmt!(UdpSocket::bind((current_ip.trim(), 68)), "failed to bind udp");
try_fmt!(socket.connect("255.255.255.255:67"), "failed to connect udp");
try_fmt!(socket.set_read_timeout(Some(Duration::new(5, 0))), "failed to set read timeout");
try_fmt!(socket.set_write_timeout(Some(Duration::new(5, 0))), "failed to set write timeout");
Expand Down Expand Up @@ -147,26 +147,26 @@ fn dhcp(quiet: bool) -> Result<(), String> {
try_fmt!(setcfg("ip", &format!("{}.{}.{}.{}\n", offer.yiaddr[0], offer.yiaddr[1], offer.yiaddr[2], offer.yiaddr[3])), "failed to set ip");

if ! quiet {
let new_ip = try_fmt!(getcfg("ip"), "failed to get ip").trim();
println!("DHCP: New IP: {}", new_ip);
let new_ip = try_fmt!(getcfg("ip"), "failed to get ip");
println!("DHCP: New IP: {}", new_ip.trim());
}
}

if let Some(subnet) = subnet_option {
try_fmt!(setcfg("ip_subnet", &format!("{}.{}.{}.{}\n", subnet[0], subnet[1], subnet[2], subnet[3])), "failed to set ip subnet");

if ! quiet {
let new_subnet = try_fmt!(getcfg("ip_subnet"), "failed to get ip subnet").trim();
println!("DHCP: New Subnet: {}", new_subnet);
let new_subnet = try_fmt!(getcfg("ip_subnet"), "failed to get ip subnet");
println!("DHCP: New Subnet: {}", new_subnet.trim());
}
}

if let Some(router) = router_option {
try_fmt!(setcfg("ip_router", &format!("{}.{}.{}.{}\n", router[0], router[1], router[2], router[3])), "failed to set ip router");

if ! quiet {
let new_router = try_fmt!(getcfg("ip_router"), "failed to get ip router").trim();
println!("DHCP: New Router: {}", new_router);
let new_router = try_fmt!(getcfg("ip_router"), "failed to get ip router");
println!("DHCP: New Router: {}", new_router.trim());
}
}

Expand All @@ -183,8 +183,8 @@ fn dhcp(quiet: bool) -> Result<(), String> {
try_fmt!(setcfg("dns", &format!("{}.{}.{}.{}\n", dns[0], dns[1], dns[2], dns[3])), "failed to set dns");

if ! quiet {
let new_dns = try_fmt!(getcfg("dns"), "failed to get dns").trim();
println!("DHCP: New DNS: {}", new_dns);
let new_dns = try_fmt!(getcfg("dns"), "failed to get dns");
println!("DHCP: New DNS: {}", new_dns.trim());
}
}
}
Expand Down

0 comments on commit 9d3b8da

Please sign in to comment.