From 7af7598086e5a3f9a75507cd6f9907a98faf3d9d Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 02:41:48 +0200 Subject: Add sub system to abstract low level multi platform socket handling ourselves --- ot_socket.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ot_socket.h (limited to 'ot_socket.h') diff --git a/ot_socket.h b/ot_socket.h new file mode 100644 index 0000000..20fd839 --- /dev/null +++ b/ot_socket.h @@ -0,0 +1,45 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +#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 */ + +/* Ask the kernel to let several processes bind the same address */ +extern int g_socket_reuseport; + +/* 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); +int socket_udp_bind(const ot_ip6 ip, uint16_t port); + +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); + +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