From 2bdc483e152f83ebe49b362a0fa8b30c07ef947e Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 27 Mar 2018 09:32:37 +0000 Subject: [PATCH] Unbreak network configuration page. --- firmware/src/pages.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/firmware/src/pages.rs b/firmware/src/pages.rs index 4b0736c..4e15313 100644 --- a/firmware/src/pages.rs +++ b/firmware/src/pages.rs @@ -4,6 +4,7 @@ use core::cell::RefCell; use core::str; use cortex_m; use cortex_m::interrupt::Mutex; +use smoltcp::wire::IpCidr; use smoltcp::socket::TcpSocket; use http; @@ -96,14 +97,17 @@ pub fn serve(output: &mut TcpSocket, request: &http::Request, if ip_arg.is_ok() { let ip_arg = str::from_utf8(ip_arg.unwrap()); if ip_arg.is_ok() { - let ip = ip_arg.unwrap().parse(); - if ip.is_ok() { - let ip = ip.unwrap(); - status = "IP address has been updated and will be active after a reboot."; - config.ip = ip; - config.save(); - } else { - status = "failed to parse IP address"; + let mut ip_arg = ip_arg.unwrap().split("%2F"); + let ip = ip_arg.next().map(|x| x.parse()); + let cidr = ip_arg.next().map(|x| x.parse()); + match (ip, cidr) { + (Some(Ok(ip)), Some(Ok(cidr))) => { + status = "IP address has been updated and will be active after a reboot."; + config.ip = IpCidr::new(ip, cidr); + config.save(); + } + _ => + status = "failed to parse IP address" } } else { status = "IP address contains an invalid UTF-8 character";