diff options
Diffstat (limited to 'ot_socket.h')
| -rw-r--r-- | ot_socket.h | 45 |
1 files changed, 45 insertions, 0 deletions
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 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. | ||
| 3 | |||
| 4 | $id$ */ | ||
| 5 | |||
| 6 | #ifndef OT_SOCKET_H__ | ||
| 7 | #define OT_SOCKET_H__ | ||
| 8 | |||
| 9 | #include <stdint.h> | ||
| 10 | #include <sys/types.h> | ||
| 11 | |||
| 12 | #include "trackerlogic.h" | ||
| 13 | |||
| 14 | /* Every socket opentracker opens is an AF_INET6 socket with IPV6_V6ONLY | ||
| 15 | cleared, so one descriptor serves both families and an IPv4 peer arrives | ||
| 16 | as the v4 mapped address */ | ||
| 17 | |||
| 18 | /* Ask the kernel to let several processes bind the same address */ | ||
| 19 | extern int g_socket_reuseport; | ||
| 20 | |||
| 21 | /* Create, bind and, for TCP, listen. The returned socket is non blocking | ||
| 22 | Returns -1 on failure with errno set */ | ||
| 23 | int socket_tcp_listen(const ot_ip6 ip, uint16_t port); | ||
| 24 | int socket_udp_bind(const ot_ip6 ip, uint16_t port); | ||
| 25 | |||
| 26 | int socket_tcp_connect(const ot_ip6 srcip, uint16_t srcport, const ot_ip6 dstip, uint16_t dstport); | ||
| 27 | int socket_is_connected(int s); | ||
| 28 | int socket_accept(int s, ot_ip6 ip, uint16_t *port); | ||
| 29 | |||
| 30 | ssize_t socket_recv(int s, void *buf, size_t len, ot_ip6 ip, uint16_t *port); | ||
| 31 | ssize_t socket_send(int s, const void *buf, size_t len, const ot_ip6 ip, uint16_t port); | ||
| 32 | |||
| 33 | #ifdef WANT_SYNC_LIVE | ||
| 34 | /* | ||
| 35 | socket_mcast_join takes the wildcard address and names the interface in the | ||
| 36 | join, and hands back a blocking socket, since the thread that reads it does | ||
| 37 | nothing else. socket_mcast_bind hands back a non blocking one, because the | ||
| 38 | thread that sends from it is also serving clients. Incoming datagrams are | ||
| 39 | read with socket_recv */ | ||
| 40 | int socket_mcast_join(const ot_ip6 group, const ot_ip6 interface, uint16_t port); | ||
| 41 | int socket_mcast_bind(const ot_ip6 interface, uint16_t port, int loopback); | ||
| 42 | ssize_t socket_mcast_send(int s, const void *buf, size_t len, const ot_ip6 group, uint16_t port); | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #endif | ||
