From bcadc424a4ff240ef1dd09334ec73b47c6784416 Mon Sep 17 00:00:00 2001 From: Lukas Stabe Date: Wed, 29 Jan 2014 17:32:47 +0100 Subject: [PATCH] display actual port and address --- darkhttpd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/darkhttpd.c b/darkhttpd.c index cf37013..215fc67 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -790,6 +790,10 @@ static const char *url_content_type(const char *url) { static void init_sockin(void) { struct sockaddr_in addrin; int sockopt; + struct sockaddr_in addrout; + socklen_t addrout_len; + + addrout_len = sizeof(addrout); /* create incoming socket */ sockin = socket(PF_INET, SOCK_STREAM, 0); @@ -829,8 +833,12 @@ static void init_sockin(void) { sizeof(struct sockaddr)) == -1) err(1, "bind(port %u)", bindport); + if (getsockname(sockin, (struct sockaddr *)&addrout, + &addrout_len) == -1) + err(1, "getsocketname(sockin)"); + printf("listening on: http://%s:%u/\n", - inet_ntoa(addrin.sin_addr), bindport); + inet_ntoa(addrout.sin_addr), addrout.sin_port); /* listen on socket */ if (listen(sockin, max_connections) == -1)