From d14529ec2800b92f90e3b0a2b2919151e4163ae3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Aug 2021 17:59:31 +0100 Subject: [PATCH] server: wip, identify cliient Signed-off-by: Ian Jackson --- src/bin/server.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 9bba6dd..cb24b2a 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -78,8 +78,15 @@ async fn handle( r#"first multipart component must be name="m""# )) } - eprintln!("boundary={:?} initial={:?} start={} comp={:?}", - boundary, initial, start, &comp); + let nl = memchr::memchr2(b'\r', b'\n', comp.payload_start) + .ok_or_else(|| anyhow!("no newline in first metadata line?"))?; + + let client = &comp.payload_start[0..nl]; + let client = str::from_utf8(client).context("client addr utf-8")?; + let client: IpAddr = client.parse().context("client address")?; + + eprintln!("boundary={:?} start={} name={:?} client={}", + boundary, start, &comp.name, client); Ok::<_,AE>(()) }.await { -- 2.30.2