aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fcgi.c14
-rw-r--r--ge.c12
-rw-r--r--gmid.c11
-rw-r--r--gmid.h2
-rw-r--r--server.c11
5 files changed, 19 insertions, 31 deletions
diff --git a/fcgi.c b/fcgi.c
index eb22d38..e29c713 100644
--- a/fcgi.c
+++ b/fcgi.c
@@ -343,26 +343,18 @@ fcgi_error(struct bufferevent *bev, short err, void *d)
void
fcgi_req(struct client *c)
{
- char addr[NI_MAXHOST], buf[22];
+ char buf[22];
char *qs;
- int e;
time_t tim;
struct tm tminfo;
struct envlist *p;
- e = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen,
- addr, sizeof(addr),
- NULL, 0,
- NI_NUMERICHOST);
- if (e != 0)
- fatalx("getnameinfo failed: %s", gai_strerror(e));
-
fcgi_begin_request(c->cgibev);
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
fcgi_send_param(c->cgibev, "QUERY_STRING", c->iri.query);
- fcgi_send_param(c->cgibev, "REMOTE_ADDR", addr);
- fcgi_send_param(c->cgibev, "REMOTE_HOST", addr);
+ fcgi_send_param(c->cgibev, "REMOTE_ADDR", c->rhost);
+ fcgi_send_param(c->cgibev, "REMOTE_HOST", c->rhost);
fcgi_send_param(c->cgibev, "REQUEST_METHOD", "");
fcgi_send_param(c->cgibev, "SERVER_NAME", c->iri.host);
fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI");
diff --git a/ge.c b/ge.c
index dff3105..57a02af 100644
--- a/ge.c
+++ b/ge.c
@@ -42,16 +42,8 @@ static const struct option opts[] = {
void
log_request(struct client *c, char *meta, size_t l)
{
- char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
+ char b[GEMINI_URL_LEN];
const char *t;
- int ec;
-
- ec = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen,
- hbuf, sizeof(hbuf),
- sbuf, sizeof(sbuf),
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (ec != 0)
- fatalx("getnameinfo: %s", gai_strerror(ec));
if (c->iri.schema != NULL) {
/* serialize the IRI */
@@ -81,7 +73,7 @@ log_request(struct client *c, char *meta, size_t l)
if ((t = memchr(meta, '\r', l)) == NULL)
t = meta + l;
- fprintf(stderr, "%s:%s GET %s %.*s\n", hbuf, sbuf, b,
+ fprintf(stderr, "%s:%s GET %s %.*s\n", c->rhost, c->rserv, b,
(int)(t-meta), meta);
}
diff --git a/gmid.c b/gmid.c
index 7d8f2c8..b59c5a9 100644
--- a/gmid.c
+++ b/gmid.c
@@ -84,18 +84,11 @@ void
log_request(struct client *c, char *meta, size_t l)
{
struct conf *conf = c->conf;
- char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
+ char b[GEMINI_URL_LEN];
char *fmted;
const char *t;
int ec;
- ec = getnameinfo((struct sockaddr*)&c->raddr, c->raddrlen,
- hbuf, sizeof(hbuf),
- sbuf, sizeof(sbuf),
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (ec != 0)
- fatalx("getnameinfo: %s", gai_strerror(ec));
-
if (c->iri.schema != NULL) {
/* serialize the IRI */
strlcpy(b, c->iri.schema, sizeof(b));
@@ -124,7 +117,7 @@ log_request(struct client *c, char *meta, size_t l)
if ((t = memchr(meta, '\r', l)) == NULL)
t = meta + l;
- ec = asprintf(&fmted, "%s:%s GET %s %.*s", hbuf, sbuf, b,
+ ec = asprintf(&fmted, "%s:%s GET %s %.*s", c->rhost, c->rserv, b,
(int)(t-meta), meta);
if (ec == -1)
fatal("asprintf");
diff --git a/gmid.h b/gmid.h
index 71c9815..8cad485 100644
--- a/gmid.h
+++ b/gmid.h
@@ -281,6 +281,8 @@ struct client {
size_t reqlen;
struct iri iri;
char domain[DOMAIN_NAME_LEN];
+ char rhost[NI_MAXHOST];
+ char rserv[NI_MAXSERV];
struct bufferevent *bev;
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);