Skip to content

Commit 20dec1c

Browse files
author
culyerr
committed
Fixed IPv4+Port address parsing
1 parent 5f4a098 commit 20dec1c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

iis/mymodule.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext
8888

8989
char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
9090
{
91+
const char *format = "%15[0-9.]:%5[0-9]";
92+
char ip[16] = { 0 }; // ip4 addresses have max len 15
93+
char port[6] = { 0 }; // port numbers are 16bit, ie 5 digits max
94+
9195
DWORD len = 50;
9296
char *buf = (char *)apr_palloc(pool, len);
9397

@@ -98,6 +102,14 @@ char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
98102

99103
WSAAddressToString(pAddr, sizeof(SOCKADDR), NULL, buf, &len);
100104

105+
// test for IPV4 with port on the end
106+
if (sscanf(buf, format, ip, port) == 2) {
107+
// IPV4 but with port - remove the port
108+
char* input = ":";
109+
char* ipv4 = strtok(buf, input);
110+
return ipv4;
111+
}
112+
101113
return buf;
102114
}
103115

0 commit comments

Comments
 (0)