diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-05-15 19:22:05 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-05-15 19:22:05 +0200 |
commit | d14d97f1a0f3155540548c4b0e37af3f7eb54c0d (patch) | |
tree | 75ca4cf75ff565d82517d4d05cd08f10061e10d0 | |
parent | 29f12ceacfb6ddb28fd89301819f2bea27cbf37a (diff) | |
download | hittpd-d14d97f1a0f3155540548c4b0e37af3f7eb54c0d.tar.gz hittpd-d14d97f1a0f3155540548c4b0e37af3f7eb54c0d.tar.xz hittpd-d14d97f1a0f3155540548c4b0e37af3f7eb54c0d.zip |
display address hittpd listens on
-rw-r--r-- | hittpd.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/hittpd.c b/hittpd.c index 574d0f1..270f81b 100644 --- a/hittpd.c +++ b/hittpd.c @@ -221,15 +221,13 @@ parse_http_date(char *s) const char * -peername(http_parser *p) +peername(int fd) { - struct conn_data *data = p->data; - struct sockaddr_storage ss; socklen_t slen = sizeof ss; static char addrbuf[NI_MAXHOST]; - if (getpeername(data->fd, (struct sockaddr *)(void *)&ss, &slen) < 0) + if (getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) return "0.0.0.0"; if (getnameinfo((struct sockaddr *)(void *)&ss, slen, addrbuf, sizeof addrbuf, 0, 0, NI_NUMERICHOST) < 0) @@ -264,7 +262,7 @@ accesslog(http_parser *p, int status) // REMOTEHOST - - [DD/MON/YYYY:HH:MM:SS -TZ] "METHOD PATH" STATUS BYTES // ? REFERER USER_AGENT printf("%s - - %s \"%s ", - peername(p), + peername(data->fd), buf, http_method_str(p->method)); @@ -998,6 +996,24 @@ main(int argc, char *argv[]) exit(111); } + if (!quiet) { + char addrbuf[NI_MAXHOST] = "(unknown)"; + char *addr = addrbuf; + char portbuf[PATH_MAX] = "(unknown)"; + struct sockaddr_storage ss; + socklen_t slen = sizeof ss; + if (getsockname(listenfd, + (struct sockaddr *)(void *)&ss, &slen) == 0 && + getnameinfo((struct sockaddr *)(void *)&ss, slen, + addrbuf, sizeof addrbuf, portbuf, sizeof portbuf, + NI_NUMERICHOST | NI_NUMERICSERV) == 0) + addr = addrbuf; + if (strncmp("::ffff:", addr, 7) == 0) + addr += 7; + + printf("hittpd listening on %s:%s\n", addr, portbuf); + } + client[0].fd = listenfd; client[0].events = POLLRDNORM; |