X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=client.cpp;h=f6361f34ab47e62dc30ec1ebd6844ae73462d21a;hp=28e1f068550e30e8da2492599401d135e2db109b;hb=74cd48ffef90d7d0752e37a4515e4ecfb68f7c9d;hpb=136469d722a9986be6bbad68788619284919d876 diff --git a/client.cpp b/client.cpp index 28e1f06..f6361f3 100644 --- a/client.cpp +++ b/client.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include "client.h" @@ -32,8 +32,19 @@ Client::Client(int sock) if (getpeername(sock, reinterpret_cast(&addr), &addr_len) == -1) { log_perror("getpeername"); remote_addr = ""; + return; + } + + char buf[INET6_ADDRSTRLEN]; + if (IN6_IS_ADDR_V4MAPPED(&addr.sin6_addr)) { + // IPv4 address, really. + if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == NULL) { + log_perror("inet_ntop"); + remote_addr = ""; + } else { + remote_addr = buf; + } } else { - char buf[INET6_ADDRSTRLEN]; if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == NULL) { log_perror("inet_ntop"); remote_addr = ""; @@ -49,7 +60,7 @@ Client::Client(const ClientProto &serialized, Stream *stream) connect_time(serialized.connect_time()), state(State(serialized.state())), request(serialized.request()), - stream_id(serialized.stream_id()), + url(serialized.url()), stream(stream), header_or_error(serialized.header_or_error()), header_or_error_bytes_sent(serialized.header_or_error_bytes_sent()), @@ -79,7 +90,7 @@ ClientProto Client::serialize() const serialized.set_connect_time(connect_time); serialized.set_state(state); serialized.set_request(request); - serialized.set_stream_id(stream_id); + serialized.set_url(url); serialized.set_header_or_error(header_or_error); serialized.set_header_or_error_bytes_sent(serialized.header_or_error_bytes_sent()); serialized.set_stream_pos(stream_pos); @@ -92,10 +103,10 @@ ClientProto Client::serialize() const ClientStats Client::get_stats() const { ClientStats stats; - if (stream_id.empty()) { - stats.stream_id = "-"; + if (url.empty()) { + stats.url = "-"; } else { - stats.stream_id = stream_id; + stats.url = url; } stats.sock = sock; stats.fwmark = fwmark;