Skip to content

Commit 9734e4e

Browse files
committed
Fix IP addresses printing on Unix
The IP-to-text functions were producing different formats, resulting in lw_addr_pretty_string() aborting with "". Standardized them to Windows, partially because they're actually following the standard, and partially because I won't have to patch lw_addr_pretty_string(). It wouldn't surprise me if inet_ntop()'s output varied in different flavours and versions of Unix-based OSes, but hopefully not. Cross that when we come to it.
1 parent 0d031fb commit 9734e4e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Lacewing/src/address.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ const char * lw_addr_tostring (lw_addr ctx)
256256

257257
case AF_INET6:
258258
{
259-
int length = sizeof (ctx->buffer) - 1;
260259

260+
// WIN32 maps to "[ipv6]", Unix maps to "ipv6". We merge to Windows' IPv6 format, as it's the standard.
261+
// If you do change this to Unix style, then update lw_addr_prettystring().
261262
#ifdef _WIN32
262263

264+
int length = sizeof(ctx->buffer) - 1;
263265
WSAAddressToStringA ((LPSOCKADDR) ctx->info->ai_addr,
264266
(DWORD) ctx->info->ai_addrlen,
265267
0,
@@ -268,11 +270,14 @@ const char * lw_addr_tostring (lw_addr ctx)
268270

269271
#else
270272

273+
int length = sizeof(ctx->buffer) - 2;
274+
ctx->buffer[0] = '[';
271275
inet_ntop (AF_INET6,
272276
&((struct sockaddr_in6 *)
273277
ctx->info->ai_addr)->sin6_addr,
274-
ctx->buffer,
278+
&ctx->buffer[1],
275279
length);
280+
strcat(&ctx->buffer[1], "]");
276281

277282
#endif
278283

bluewing-cpp-server-linux.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@
192192
<Filter Include="Header Files\Lacewing\src\unix\eventqueue">
193193
<UniqueIdentifier>{385abb9a-7b1f-4d40-b648-aeb462ca7633}</UniqueIdentifier>
194194
</Filter>
195-
<Filter Include="Source Files\Lacewing\include">
196-
<UniqueIdentifier>{0dbd5d21-cc72-4194-a71e-50282b079038}</UniqueIdentifier>
197-
</Filter>
198195
<Filter Include="Header Files\Lacewing\src\deps\uthash">
199196
<UniqueIdentifier>{c6baa449-9ca3-4e95-a526-0a38f47c6951}</UniqueIdentifier>
200197
</Filter>

0 commit comments

Comments
 (0)