Skip to content

Commit c1bdf8c

Browse files
committed
check the prefix convert ip6 back to ip4 if ip is ip4
1 parent 1933c71 commit c1bdf8c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/AsyncSocket.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <cstring>
2828
#include <iostream>
29+
#include <string.h>
2930

3031
#include "libusockets.h"
3132

@@ -212,6 +213,12 @@ struct AsyncSocket {
212213
ipLength = snprintf(buf, 64, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
213214
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11],
214215
b[12], b[13], b[14], b[15]);
216+
// ip4 127.0.0.1 be converted to ip6 0000:0000:0000:0000:0000:ffff:7f00:0001
217+
// following code will check the prefix convert ip6 back to ip4 if ip is ip4
218+
const char* IPV6_IPV4_MAPPED_PREFIX="0000:0000:0000:0000:0000:ffff:";
219+
if (0 == memcmp(buf, IPV6_IPV4_MAPPED_PREFIX, strlen(IPV6_IPV4_MAPPED_PREFIX))) {
220+
ipLength = snprintf(buf, 64, "%u.%u.%u.%u", b[12], b[13], b[14], b[15]);
221+
}
215222
}
216223

217224
return {buf, (unsigned int) ipLength};

0 commit comments

Comments
 (0)