diff options
Diffstat (limited to 'src/ot_socket.c')
| -rw-r--r-- | src/ot_socket.c | 14 |
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 | ||
| 164 | int 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 | |||
| 164 | int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport) { | 178 | int 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); |
