summaryrefslogtreecommitdiff
path: root/src/ot_socket.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-29 00:34:40 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-29 00:34:40 +0100
commit952da5949f677e932f2a48a5474210df571472fb (patch)
treed33525d29ee18b65b9e5df39d2e2fb1f5a868ca2 /src/ot_socket.c
parentf08e7473ac51a024f49e5101fbc5e150fecef2d4 (diff)
Warn about udp addresses already taken by other tracker instancesHEADmaster
Diffstat (limited to 'src/ot_socket.c')
-rw-r--r--src/ot_socket.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ot_socket.c b/src/ot_socket.c
index b6a1803..8b17080 100644
--- a/src/ot_socket.c
+++ b/src/ot_socket.c
@@ -161,6 +161,20 @@ int socket_udp_bind(const ot_ip6 ip, uint16_t port, socket_sharing sharing) {
161 return s; 161 return s;
162} 162}
163 163
164int socket_udp_is_taken(const ot_ip6 ip, uint16_t port) {
165 struct sockaddr_in6 sa;
166 int s = socket_v6(SOCK_DGRAM), taken;
167
168 if (s == -1)
169 return 0;
170
171 /* Asking for no sharing at all is refused whatever the holder allowed */
172 sockaddr_from_ip(&sa, ip, port);
173 taken = bind(s, (struct sockaddr *)&sa, sizeof(sa)) == -1 && errno == EADDRINUSE;
174 close(s);
175 return taken;
176}
177
164int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport) { 178int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport) {
165 struct sockaddr_in6 sa; 179 struct sockaddr_in6 sa;
166 int s = socket_v6(SOCK_STREAM); 180 int s = socket_v6(SOCK_STREAM);