#include <arpa/inet.h>
#include <netinet/in.h>
-#include <stdio.h>
+#include <stdint.h>
#include <sys/socket.h>
#include "client.h"
if (getpeername(sock, reinterpret_cast<sockaddr *>(&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 = "";
if (fwmark != 0) {
log_perror("setsockopt(SO_MARK)");
}
+ fwmark = 0;
}
}
ClientStats Client::get_stats() const
{
ClientStats stats;
- stats.stream_id = stream_id;
+ if (stream_id.empty()) {
+ stats.stream_id = "-";
+ } else {
+ stats.stream_id = stream_id;
+ }
+ stats.sock = sock;
+ stats.fwmark = fwmark;
stats.remote_addr = remote_addr;
stats.connect_time = connect_time;
stats.bytes_sent = bytes_sent;