Add local address information to edges.
[tinc] / src / protocol_auth.c
index b8d4ee8..778c607 100644 (file)
@@ -822,6 +822,16 @@ bool ack_h(connection_t *c, const char *request) {
        sockaddr2str(&c->address, &hisaddress, NULL);
        c->edge->address = str2sockaddr(hisaddress, hisport);
        free(hisaddress);
+       sockaddr_t local_sa;
+       socklen_t local_salen = sizeof local_sa;
+       if (getsockname(c->socket, &local_sa.sa, &local_salen) < 0)
+               logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name);
+       else {
+               char *local_address;
+               sockaddr2str(&local_sa, &local_address, NULL);
+               c->edge->local_address = str2sockaddr(local_address, myport);
+               free(local_address);
+       }
        c->edge->weight = (weight + c->estimated_weight) / 2;
        c->edge->connection = c;
        c->edge->options = c->options;