Fixed IPv4+Port address parsing

This commit is contained in:
culyerr 2016-09-27 17:09:18 +01:00 committed by Felipe Zimmerle
parent b1ee051cee
commit b83c1109ad
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277

View File

@ -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;
}