summaryrefslogtreecommitdiffhomepage
path: root/src/sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sock.c')
-rw-r--r--src/sock.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sock.c b/src/sock.c
index f74a588..8513ba8 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -33,6 +33,7 @@
#include "sock.h"
#include "text.h"
#include "conf.h"
+#include "loop.h"
/*
* Return a human readable error for getaddrinfo() and getnameinfo().
@@ -141,8 +142,17 @@ int opensock (const char *host, int port, const char *bind_to)
}
}
- if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0)
+ if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0) {
+ union sockaddr_union *p = (void*) res->ai_addr, u;
+ int af = res->ai_addr->sa_family;
+ unsigned dport = ntohs(af == AF_INET ? p->v4.sin_port : p->v6.sin6_port);
+ socklen_t slen = sizeof u;
+ if (dport == config.port) {
+ getsockname(sockfd, (void*)&u, &slen);
+ loop_records_add(&u);
+ }
break; /* success */
+ }
close (sockfd);
} while ((res = res->ai_next) != NULL);