From d46f617b4a619bedbc7e703b3b68664f9e1179e2 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 29 Aug 2024 16:45:28 +0900 Subject: [PATCH] Print connecting peer's address --- src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.c b/src/main.c index 18aacfc..0f0730a 100644 --- a/src/main.c +++ b/src/main.c @@ -72,6 +72,14 @@ int main(int argc, char **argv) { printf("WARNING: accept: errno %d\n", errno); } else if (ret >= 0) { // Received connection, handle it. + printf("Peer connected: addr is "); + for (unsigned int idx = 0; idx < 16; ++idx) { + if (idx % 2 == 0 && idx > 0) { + printf(":"); + } + printf("%02x", peer_info.sin6_addr.s6_addr[idx]); + } + puts(""); int connection_fd = ret; read_ret = read(connection_fd, recv_buf, C_SIMPLE_HTTP_RECV_BUF_SIZE); // DEBUG print received buf.