From ad541c67761b8aa6da1566802c347cac4018d0c2 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 20:50:24 +0100 Subject: Move the build sources into src/ --- src/ot_socket.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/ot_socket.h (limited to 'src/ot_socket.h') diff --git a/src/ot_socket.h b/src/ot_socket.h new file mode 100644 index 0000000..5c1d840 --- /dev/null +++ b/src/ot_socket.h @@ -0,0 +1,56 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. */ + +#ifndef OT_SOCKET_H__ +#define OT_SOCKET_H__ + +#include +#include + +#include "trackerlogic.h" + +/* Every socket opentracker opens is an AF_INET6 socket with IPV6_V6ONLY + cleared, so one descriptor serves both families and an IPv4 peer arrives + as the v4 mapped address */ + +/* How an address may be shared with other sockets. Which socket option says + so differs between kernels, which is socket_set_sharing's business. + + SHARED lets another socket bind the same address. BALANCED asks the kernel + to spread arriving datagrams over the sockets that did, which is a + different thing and not everywhere available: ask socket_can_balance + before binding a group that depends on it. */ +typedef enum { SOCKET_EXCLUSIVE, SOCKET_SHARED, SOCKET_BALANCED } socket_sharing; + +/* Whether this kernel spreads datagrams over a group of sockets bound to one + address. Where it does not, binding a group is worse than one socket with + several readers, so the caller wants to know first. */ +int socket_can_balance(void); + +/* Create, bind and, for TCP, listen. The returned socket is non blocking + Returns -1 on failure with errno set */ +int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing); +int socket_udp_bind(const ot_ip6 ip, uint16_t port, socket_sharing sharing); + +int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport); +int socket_is_connected(int s); +int socket_accept(int s, ot_ip6 ip, uint16_t *port); +int socket_set_blocking(int s, int blocking); +int socket_defer_accept(int s); + +ssize_t socket_recv(int s, void *buf, size_t len, ot_ip6 ip, uint16_t *port); +ssize_t socket_send(int s, const void *buf, size_t len, const ot_ip6 ip, uint16_t port); + +#ifdef WANT_SYNC_LIVE +/* + socket_mcast_join takes the wildcard address and names the interface in the + join, and hands back a blocking socket, since the thread that reads it does + nothing else. socket_mcast_bind hands back a non blocking one, because the + thread that sends from it is also serving clients. Incoming datagrams are + read with socket_recv */ +int socket_mcast_join(const ot_ip6 group, const ot_ip6 interface, uint16_t port); +int socket_mcast_bind(const ot_ip6 interface, uint16_t port, int loopback); +ssize_t socket_mcast_send(int s, const void *buf, size_t len, const ot_ip6 group, uint16_t port); +#endif + +#endif -- cgit v1.3