diff options
author | Omar Polo <op@omarpolo.com> | 2023-06-26 09:44:46 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2023-06-26 09:44:46 +0000 |
commit | ed164e7221f75d3d7f48351e9427f2ce53ab284a (patch) | |
tree | 02b5682b5b239673ace2add072f4ea6d836e3194 /server.c | |
parent | da0821b6cb54a85bcbe76cdf0a9a16f8f1a14619 (diff) |
call getnameinfo() only once per request
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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); |