diff options
Diffstat (limited to 'src/ot_socket.h')
| -rw-r--r-- | src/ot_socket.h | 56 |
1 files changed, 56 insertions, 0 deletions
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 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ | ||
| 3 | |||
| 4 | #ifndef OT_SOCKET_H__ | ||
| 5 | #define OT_SOCKET_H__ | ||
| 6 | |||
| 7 | #include <stdint.h> | ||
| 8 | #include <sys/types.h> | ||
| 9 | |||
| 10 | #include "trackerlogic.h" | ||
| 11 | |||
| 12 | /* Every socket opentracker opens is an AF_INET6 socket with IPV6_V6ONLY | ||
| 13 | cleared, so one descriptor serves both families and an IPv4 peer arrives | ||
| 14 | as the v4 mapped address */ | ||
| 15 | |||
| 16 | /* How an address may be shared with other sockets. Which socket option says | ||
| 17 | so differs between kernels, which is socket_set_sharing's business. | ||
| 18 | |||
| 19 | SHARED lets another socket bind the same address. BALANCED asks the kernel | ||
| 20 | to spread arriving datagrams over the sockets that did, which is a | ||
| 21 | different thing and not everywhere available: ask socket_can_balance | ||
| 22 | before binding a group that depends on it. */ | ||
| 23 | typedef enum { SOCKET_EXCLUSIVE, SOCKET_SHARED, SOCKET_BALANCED } socket_sharing; | ||
| 24 | |||
| 25 | /* Whether this kernel spreads datagrams over a group of sockets bound to one | ||
| 26 | address. Where it does not, binding a group is worse than one socket with | ||
| 27 | several readers, so the caller wants to know first. */ | ||
| 28 | int socket_can_balance(void); | ||
| 29 | |||
| 30 | /* Create, bind and, for TCP, listen. The returned socket is non blocking | ||
| 31 | Returns -1 on failure with errno set */ | ||
| 32 | int socket_tcp_listen(const ot_ip6 ip, uint16_t port, socket_sharing sharing); | ||
| 33 | int socket_udp_bind(const ot_ip6 ip, uint16_t port, socket_sharing sharing); | ||
| 34 | |||
| 35 | int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport); | ||
| 36 | int socket_is_connected(int s); | ||
| 37 | int socket_accept(int s, ot_ip6 ip, uint16_t *port); | ||
| 38 | int socket_set_blocking(int s, int blocking); | ||
| 39 | int socket_defer_accept(int s); | ||
| 40 | |||
| 41 | ssize_t socket_recv(int s, void *buf, size_t len, ot_ip6 ip, uint16_t *port); | ||
| 42 | ssize_t socket_send(int s, const void *buf, size_t len, const ot_ip6 ip, uint16_t port); | ||
| 43 | |||
| 44 | #ifdef WANT_SYNC_LIVE | ||
| 45 | /* | ||
| 46 | socket_mcast_join takes the wildcard address and names the interface in the | ||
| 47 | join, and hands back a blocking socket, since the thread that reads it does | ||
| 48 | nothing else. socket_mcast_bind hands back a non blocking one, because the | ||
| 49 | thread that sends from it is also serving clients. Incoming datagrams are | ||
| 50 | read with socket_recv */ | ||
| 51 | int socket_mcast_join(const ot_ip6 group, const ot_ip6 interface, uint16_t port); | ||
| 52 | int socket_mcast_bind(const ot_ip6 interface, uint16_t port, int loopback); | ||
| 53 | ssize_t socket_mcast_send(int s, const void *buf, size_t len, const ot_ip6 group, uint16_t port); | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
