aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2023-06-26 09:44:46 +0000
committerOmar Polo <op@omarpolo.com>2023-06-26 09:44:46 +0000
commited164e7221f75d3d7f48351e9427f2ce53ab284a (patch)
tree02b5682b5b239673ace2add072f4ea6d836e3194 /server.c
parentda0821b6cb54a85bcbe76cdf0a9a16f8f1a14619 (diff)
call getnameinfo() only once per request
Diffstat (limited to 'server.c')
-rw-r--r--server.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/server.c b/server.c
index 0a0b3e3..09b2645 100644
--- a/server.c
+++ b/server.c
@@ -1343,7 +1343,7 @@ do_accept(int sock, short et, void *d)
struct sockaddr_storage raddr;
struct sockaddr *sraddr;
socklen_t len;
- int fd;
+ int e, fd;
sraddr = (struct sockaddr *)&raddr;
len = sizeof(raddr);
@@ -1365,6 +1365,15 @@ do_accept(int sock, short et, void *d)
memcpy(&c->raddr, &raddr, sizeof(raddr));
c->raddrlen = len;
+ e = getnameinfo(sraddr, len, c->rhost, sizeof(c->rhost),
+ c->rserv, sizeof(c->rserv), NI_NUMERICHOST | NI_NUMERICSERV);
+ if (e != 0) {
+ log_warnx("getnameinfo failed: %s", gai_strerror(e));
+ close(c->fd);
+ free(c);
+ return;
+ }
+
if (tls_accept_socket(addr->ctx, &c->ctx, fd) == -1) {
log_warnx("failed to accept socket: %s", tls_error(c->ctx));
close(c->fd);