char port_buf[16];
snprintf(port_buf, sizeof(port_buf), "%d", socket.local_endpoint().port());
env.set("SERVER_PORT", port_buf);
+ env.set("REMOTE_ADDR", socket.remote_endpoint().address().to_string());
// TODO: set SERVER_PORT_SECURE if using ssl
// TODO: set REMOTE_USER if authenticated
}
return none;
}
- m.v6 = s.find(':');
+ m.v6 = (s.find(':') == string::npos) ? false : true;
+
auto slash = s.find('/');
if (slash == string::npos) {
m.prefix = m.v6 ? 128 : 32;
if (m.v6) {
struct sockaddr_in6 a;
- if (inet_pton(AF_INET6, p->c_str(), static_cast<void*>(&a)) != 1) {
+ if (inet_pton(AF_INET6, p->c_str(), static_cast<void*>(&a.sin6_addr)) != 1) {
return none;
}
m.addr |= Address(a.sin6_addr.s6_addr[15]) << 120;
} else {
struct sockaddr_in a;
- if (inet_pton(AF_INET, p->c_str(), static_cast<void*>(&a)) != 1) {
+ if (inet_pton(AF_INET, p->c_str(), static_cast<void*>(&a.sin_addr)) != 1) {
return none;
}
m.addr = ntohl(a.sin_addr.s_addr);
}
- return none;
+ return m;
}
namespace {
e.emplace("aws:SecureTransport", "true");
}
- i = m.find("HTTP_HOST");
+ i = m.find("REMOTE_ADDR");
if (i != m.end()) {
e.emplace("aws:SourceIp", i->second);
}