Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

connect: start fixing IPv6 addresses #1100

Merged
merged 1 commit into from Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/net/connect.md
Expand Up @@ -114,6 +114,9 @@ were successful.
Most MeasurementKit functions receive the `reactor` argument before the `logger`
argument, but `connect()` uses the opposite convention.

As of MeasurementKit v0.4, `connect()` does not correctly deal with scoped
link-local IPv6 addresses (e.g. `fe80::1%lo0`).

# HISTORY

The `connect` submodule appeared in MeasurementKit 0.2.0.
16 changes: 13 additions & 3 deletions src/libmeasurement_kit/net/connect_impl.hpp
Expand Up @@ -32,14 +32,22 @@ void connect_base(std::string address, int port,
Var<Logger> logger = Logger::global()) {
logger->debug("connect_base %s:%d", address.c_str(), port);

std::stringstream ss;
ss << address << ":" << port;
std::string endpoint = ss.str();
std::string endpoint = [&]() {
Endpoint endpoint;
endpoint.hostname = address;
endpoint.port = port;
return serialize_endpoint(endpoint);
}();

sockaddr_storage storage;
sockaddr *saddr = (sockaddr *)&storage;
int salen = sizeof storage;

// XXX: as we have seen in #915, the following function does not deal with
// IPv6 scoped link local addresses. We can fix this by copying from the
// way in which such problem is solved in libevent/dns_utils.hpp.
if (evutil_parse_sockaddr_port(endpoint.c_str(), saddr, &salen) != 0) {
logger->warn("cannot parse endpoint: '%s'", endpoint.c_str());
cb(GenericError(), nullptr, 0.0);
return;
}
Expand Down Expand Up @@ -75,6 +83,7 @@ void connect_base(std::string address, int port,
double begin = mk::time_now();

if (bufferevent_socket_connect(bev, saddr, salen) != 0) {
logger->warn("connect() failed immediately");
bufferevent_free(bev);
cb(GenericError(), nullptr, 0.0);
return;
Expand All @@ -86,6 +95,7 @@ void connect_base(std::string address, int port,
bev, nullptr, nullptr, mk_bufferevent_on_event,
new Callback<Error, bufferevent *>([=](Error err, bufferevent *bev) {
if (err) {
logger->warn("connect() failed in its callback");
bufferevent_free(bev);
cb(err, nullptr, 0.0);
return;
Expand Down