# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1665679560 -7200
# Node ID f202a655f4c2cdff9a71a9841d4b2bb226a39f35
# Parent  77d81f2bb9f70223cf1667790f29bc2b9417bdf7
convert ipv6 addr to string

diff -r 77d81f2bb9f7 -r f202a655f4c2 src/server/daemon/httprequest.c
--- a/src/server/daemon/httprequest.c	Wed Oct 12 23:34:20 2022 +0200
+++ b/src/server/daemon/httprequest.c	Thu Oct 13 18:46:00 2022 +0200
@@ -164,9 +164,8 @@
     sn->config = request->connection->listener->cfg;
 
     // add ip to sn->client pblock
-    char ip_str[INET_ADDRSTRLEN];
-    // TODO: ipv6
     if(request->connection->addr_type == CONN_ADDR_IPV4) {
+        char ip_str[INET_ADDRSTRLEN];
         if(inet_ntop(
                 AF_INET,
                 &request->connection->address.address_v4.sin_addr,
@@ -175,6 +174,16 @@
         {
             pblock_kvinsert(pb_key_ip, ip_str, INET_ADDRSTRLEN, sn->sn.client);
         }
+    } else if(request->connection->addr_type == CONN_ADDR_IPV6) {
+        char ip_str[INET6_ADDRSTRLEN];
+        if(inet_ntop(
+                AF_INET6,
+                &request->connection->address.address_v6.sin6_addr,
+                ip_str,
+                INET6_ADDRSTRLEN) != NULL)
+        {
+            pblock_kvinsert(pb_key_ip, ip_str, INET6_ADDRSTRLEN, sn->sn.client);
+        }
     }
 
     // init NSAPI request structure
@@ -342,7 +351,16 @@
     char *hosthdr = pblock_findkeyval(pb_key_host, rq->rq.headers);
     if(hosthdr) {
         char *host = pool_strdup(pool, hosthdr);
-        char *portstr = strchr(host, ':');
+        char *portstr = NULL;
+        if(host[0] != '[') {
+            portstr = strchr(host, ':');
+        } else {
+            char *v6end = strchr(host, ']');
+            if(v6end) {
+                portstr = strchr(v6end, ':');
+            }
+        }
+        
         if(portstr) {
             *portstr = '\0';
         }