From b83c1109adb709b7e93089805aa7e5647c39c0ee Mon Sep 17 00:00:00 2001 From: culyerr Date: Tue, 27 Sep 2016 17:09:18 +0100 Subject: [PATCH] Fixed IPv4+Port address parsing --- iis/mymodule.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/iis/mymodule.cpp b/iis/mymodule.cpp index 464968cb..607fdf0a 100644 --- a/iis/mymodule.cpp +++ b/iis/mymodule.cpp @@ -88,6 +88,10 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr) { + const char *format = "%15[0-9.]:%5[0-9]"; + char ip[16] = { 0 }; // ip4 addresses have max len 15 + char port[6] = { 0 }; // port numbers are 16bit, ie 5 digits max + DWORD len = 50; char *buf = (char *)apr_palloc(pool, len); @@ -98,6 +102,14 @@ char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr) WSAAddressToString(pAddr, sizeof(SOCKADDR), NULL, buf, &len); + // test for IPV4 with port on the end + if (sscanf(buf, format, ip, port) == 2) { + // IPV4 but with port - remove the port + char* input = ":"; + char* ipv4 = strtok(buf, input); + return ipv4; + } + return buf; }