summaryrefslogtreecommitdiff
path: root/mcast/common/mcast.h
blob: 33a6ed5b66068c3a2381550a53964276d633be4f (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de
 *
 * See the COPYING file for copyright information and
 * how to reach the author.
 *
 * modified by Reel Multimedia, http://www.reel-multimedia.com, info@reel-multimedia.com
 * 01042010 DL: use a single thread for reading from network layer (uses less resources)
 *
 */

#ifndef __MCAST_H__
#define __MCAST_H__

typedef void (*client_udp_cb)(unsigned char *buf, int n, void *arg);

typedef struct _UDPContext
{
	struct _UDPContext *next;
	SOCKET udp_fd;
	int ttl;
	int idx;
	int is_multicast;
	int local_port;
	int reuse_socket;
	struct sockaddr_storage dest_addr;
	size_t dest_addr_len;

	client_udp_cb cb;
	void *arg;
	unsigned char *buff;
	int buffmax;
	int bufflen;
	pthread_mutex_t bufflock;
	struct pollfd *pfd;
} UDPContext;

#define	SA	struct sockaddr

#define UDP_TX_BUF_SIZE 131072
#define UDP_RX_BUF_SIZE 131072
#define UDP_PID_BUF_SIZE 1048576
#define MCAST_TTL 16

UDPContext *server_udp_open_host (const char *host, int port, const char *ifname);
UDPContext *server_udp_open (const struct in6_addr *mcg, int port, const char *ifname);
UDPContext *client_udp_open (const struct in6_addr *mcg, int port, const char *ifname);
UDPContext *client_udp_open_host (const char *host, int port, const char *ifname);

int udp_read (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from);
int udp_write (UDPContext * s, uint8_t * buf, int size);
int udp_close (UDPContext * s);

#ifndef MULTI_THREAD_RECEIVER
UDPContext *client_udp_open_host_buff (const char *host, int port, const char *ifname, int buff_size);
UDPContext *client_udp_open_cb   (const struct in6_addr *mcg, int port, const char *ifname, client_udp_cb cb, void *arg);
UDPContext *client_udp_open_buff (const struct in6_addr *mcg, int port, const char *ifname, int buff_size);
int udp_read_buff (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from);
int udp_close_buff (UDPContext * s);
#endif

int udp_ipv6_join_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr);
int udp_ipv6_leave_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr);
#endif