diff options
| author | Joseph Henry <[email protected]> | 2021-05-19 00:52:52 -0700 |
|---|---|---|
| committer | Joseph Henry <[email protected]> | 2021-05-19 00:52:52 -0700 |
| commit | 08cf10278ebf0e099e9fb296b18d383597ec139a (patch) | |
| tree | be53f0f11b1b40b5bd586ef4927bfc939b913f16 /src | |
| parent | 840a5159b33d32ac7820c1ed926e83ba108e60ff (diff) | |
Correctly handle IPv6 unspecified address in C API
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sockets.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Sockets.cpp b/src/Sockets.cpp index 0049ba4..f4399c3 100644 --- a/src/Sockets.cpp +++ b/src/Sockets.cpp @@ -367,15 +367,20 @@ int zts_util_ipstr_to_saddr( *addrlen = sizeof(struct zts_sockaddr_in); return ZTS_ERR_OK; } + int any = 0; if (family == ZTS_AF_INET6) { struct zts_sockaddr_in6* in6 = (struct zts_sockaddr_in6*)dest_addr; in6->sin6_port = htons(port); in6->sin6_family = family; -#if defined(_WIN32) - zts_inet_pton(family, src_ipstr, &(in6->sin6_addr)); -#else - zts_inet_pton(family, src_ipstr, &(in6->sin6_addr)); -#endif + // Handle the unspecified address + any = ((strlen(src_ipstr) >= 2) && !strncmp(src_ipstr, "::", 2)) + || ((strlen(src_ipstr) >= 15) && !strncmp(src_ipstr, "0:0:0:0:0:0:0:0", 15)) ? 1 : 0; + if (!any) { + zts_inet_pton(family, src_ipstr, &(in6->sin6_addr)); + } + else { + memset((void*)&(in6->sin6_addr), 0, sizeof(zts_in6_addr)); + } *addrlen = sizeof(struct zts_sockaddr_in6); return ZTS_ERR_OK; } |
