diff --git a/http_server.h b/http_server.h
index a7bf6a63..a647c30e 100644
--- a/http_server.h
+++ b/http_server.h
@@ -123,7 +123,7 @@ struct http_request {
bool_t *disable_tx_flag;
time_ms_t initiate_time; // time connection was initiated
time_ms_t idle_timeout; // disconnect if no bytes received for this long
- struct sockaddr_in client_in_addr;
+ struct sockaddr_in client_sockaddr_in;
HTTP_REQUEST_PARSER parser; // current parser function
HTTP_REQUEST_PARSER handle_first_line; // called after first line is parsed
HTTP_REQUEST_PARSER handle_headers; // called after all headers are parsed
diff --git a/rhizome_direct_http.c b/rhizome_direct_http.c
index 9f0875d2..2ffd9875 100644
--- a/rhizome_direct_http.c
+++ b/rhizome_direct_http.c
@@ -381,13 +381,12 @@ int rhizome_direct_addfile(rhizome_http_request *r, const char *remainder)
http_request_simple_response(&r->http, 405, NULL);
return 0;
}
- if (cmp_sockaddr((struct sockaddr *)&r->http.client_in_addr, sizeof r->http.client_in_addr,
- (struct sockaddr *)&config.rhizome.api.addfile.allow_host, sizeof config.rhizome.api.addfile.allow_host
- ) != 0
+ if ( r->http.client_sockaddr_in.sin_family != AF_INET
+ || r->http.client_sockaddr_in.sin_addr.s_addr != config.rhizome.api.addfile.allow_host.s_addr
) {
- INFOF("rhizome.api.addfile request received from %s, but is only allowed from %s",
- alloca_sockaddr(&r->http.client_in_addr, sizeof r->http.client_in_addr),
- alloca_sockaddr(&config.rhizome.api.addfile.allow_host, sizeof config.rhizome.api.addfile.allow_host)
+ INFOF("rhizome.api.addfile request received from %s, but is only allowed from AF_INET %s",
+ alloca_sockaddr(&r->http.client_sockaddr_in, sizeof r->http.client_sockaddr_in),
+ alloca_in_addr(&config.rhizome.api.addfile.allow_host)
);
rhizome_direct_clear_temporary_files(r);
http_request_simple_response(&r->http, 404, "
Not available from here
");
diff --git a/rhizome_http.c b/rhizome_http.c
index dc83d203..d08180eb 100644
--- a/rhizome_http.c
+++ b/rhizome_http.c
@@ -270,7 +270,7 @@ void rhizome_server_poll(struct sched_ent *alarm)
request->read_state.blob_fd = -1;
request->read_state.blob_rowid = -1;
if (peerip)
- request->http.client_in_addr = *peerip;
+ request->http.client_sockaddr_in = *peerip;
request->http.handle_headers = rhizome_dispatch;
request->http.debug_flag = &config.debug.rhizome_httpd;
request->http.disable_tx_flag = &config.debug.rhizome_nohttptx;
diff --git a/strbuf_helpers.c b/strbuf_helpers.c
index 4bb19474..de8446d6 100644
--- a/strbuf_helpers.c
+++ b/strbuf_helpers.c
@@ -313,6 +313,16 @@ strbuf strbuf_append_socket_type(strbuf sb, int type)
return sb;
}
+strbuf strbuf_append_in_addr(strbuf sb, const struct in_addr *addr)
+{
+ strbuf_sprintf(sb, " %u.%u.%u.%u",
+ ((unsigned char *) &addr->s_addr)[0],
+ ((unsigned char *) &addr->s_addr)[1],
+ ((unsigned char *) &addr->s_addr)[2],
+ ((unsigned char *) &addr->s_addr)[3]);
+ return sb;
+}
+
strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t addrlen)
{
strbuf_append_socket_domain(sb, addr->sa_family);
@@ -336,13 +346,9 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
break;
case AF_INET: {
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
- strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
- ((unsigned char *) &addr_in->sin_addr.s_addr)[0],
- ((unsigned char *) &addr_in->sin_addr.s_addr)[1],
- ((unsigned char *) &addr_in->sin_addr.s_addr)[2],
- ((unsigned char *) &addr_in->sin_addr.s_addr)[3],
- ntohs(addr_in->sin_port)
- );
+ strbuf_putc(sb, ' ');
+ strbuf_append_in_addr(sb, &addr_in->sin_addr);
+ strbuf_sprintf(sb, ":%u", ntohs(addr_in->sin_port));
if (addrlen != sizeof(struct sockaddr_in))
strbuf_sprintf(sb, " (addrlen=%d should be %zd)", (int)addrlen, sizeof(struct sockaddr_in));
}
diff --git a/strbuf_helpers.h b/strbuf_helpers.h
index 8bc45de5..289c7ddf 100644
--- a/strbuf_helpers.h
+++ b/strbuf_helpers.h
@@ -117,6 +117,14 @@ strbuf strbuf_append_socket_domain(strbuf sb, int domain);
strbuf strbuf_append_socket_type(strbuf sb, int type);
#define alloca_socket_type(type) strbuf_str(strbuf_append_socket_type(strbuf_alloca(15), type))
+/* Append a textual description of a struct in_addr (in network order) as IPv4
+ * quartet "N.N.N.N".
+ * @author Andrew Bettison
+ */
+struct in_addr;
+strbuf strbuf_append_in_addr(strbuf sb, const struct in_addr *addr);
+#define alloca_in_addr(addr) strbuf_str(strbuf_append_in_addr(strbuf_alloca(16), (const struct in_addr *)(addr)))
+
/* Append a textual description of a struct sockaddr_in.
* @author Andrew Bettison
*/