1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
It is considered beerware. Prost. Skol. Cheers or whatever.
$id$ */
#ifndef OT_SOCKET_H__
#define OT_SOCKET_H__
#include <stdint.h>
#include <sys/types.h>
#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 */
typedef enum { SOCKET_EXCLUSIVE, SOCKET_SHARED } socket_sharing;
/* 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);
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
|