Skip to content

Commit 5e9bc54

Browse files
authored
Explain why not using inet_pton for IPv6 addresses (#39686)
Commit Message: Explain why not using inet_pton for IPv6 addresses Additional Description: It took me a while to figure out why we're using the much more complicated and less performant `getaddrinfo()` for `parseV6Address`, rather than `inet_pton`, which google searches generally recommend using. Even the discussion history on the responsible commits didn't really clarify, and `scope` as an explanation was insufficient because the word is way too overloaded. This PR adds a couple of lines of comments that make the reason for this choice clear for the next confused person. Risk Level: None, change is comment-only. Testing: n/a Docs Changes: n/a Release Notes: n/a Platform Specific Features: n/a Signed-off-by: Raven Black <ravenblack@dropbox.com>
1 parent cde9aeb commit 5e9bc54

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

source/common/network/utility.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ StatusOr<sockaddr_in> parseV4Address(const std::string& ip_address, uint16_t por
119119

120120
StatusOr<sockaddr_in6> parseV6Address(const std::string& ip_address, uint16_t port) {
121121
// Parse IPv6 with optional scope using getaddrinfo().
122+
// While inet_pton() would be faster and simpler, it does not support IPv6
123+
// addresses that specify a scope, e.g. `::%eth0` to listen on only one interface.
122124
struct addrinfo hints;
123125
memset(&hints, 0, sizeof(hints));
124126
struct addrinfo* res = nullptr;

0 commit comments

Comments
 (0)