Skip to content

Commit c0dc37f

Browse files
committed
mujiansu
1 parent e67f3a4 commit c0dc37f

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

.github/workflows/test-ci-windows.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ jobs:
224224
225225
$crsRules = @(
226226
"Include coreruleset/crs-setup.conf",
227-
"Include coreruleset/rules/*.conf",
228227
"Include coreruleset/plugins/*-config.conf",
229228
"Include coreruleset/plugins/*-before.conf",
230229
"Include coreruleset/rules/*.conf",

iis/mymodule.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,22 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext
9191

9292
char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
9393
{
94-
if (pAddr == NULL) {
95-
return "";
96-
}
97-
98-
char ipbuf[INET6_ADDRSTRLEN] = {0};
99-
const char *res = "";
100-
101-
switch (pAddr->sa_family) {
102-
case AF_INET:
103-
{
104-
SOCKADDR_IN *sin = (SOCKADDR_IN *)pAddr;
105-
if (InetNtopA(AF_INET, &sin->sin_addr, ipbuf, sizeof(ipbuf)) != NULL) {
106-
res = (const char *)apr_pstrdup(pool, ipbuf);
107-
} else {
108-
res = "";
109-
}
110-
}
111-
break;
112-
case AF_INET6:
113-
{
114-
SOCKADDR_IN6 *sin6 = (SOCKADDR_IN6 *)pAddr;
115-
if (InetNtopA(AF_INET6, &sin6->sin6_addr, ipbuf, sizeof(ipbuf)) != NULL) {
116-
res = (const char *)apr_pstrdup(pool, ipbuf);
117-
} else {
118-
res = "";
119-
}
120-
}
121-
break;
122-
default:
123-
res = "";
124-
break;
125-
}
126-
127-
return (char *)res;
94+
if (pAddr == NULL) {
95+
return "";
96+
}
97+
98+
DWORD addrSize = pAddr->sa_family == AF_INET ? sizeof(SOCKADDR_IN) : sizeof(SOCKADDR_IN6);
99+
char* buf = (char*)apr_palloc(pool, NI_MAXHOST);
100+
if (buf == NULL) {
101+
return "";
102+
}
103+
buf[0] = '\0';
104+
105+
if (GetNameInfo(pAddr, addrSize, buf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0) {
106+
return "";
107+
}
108+
109+
return buf;
128110
}
129111

130112
apr_sockaddr_t *CopySockAddr(apr_pool_t *pool, PSOCKADDR pAddr)

0 commit comments

Comments
 (0)