delete dump-stream on clean
[record-dvb] / mcast.c
1 #include <strings.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netdb.h>
8
9 #include "common.h"
10 #include "mcast.h"
11
12 int is_mcast(char *url)
13 {
14 if (strlen(url) < 7)
15 return 0;
16
17 if (!strncasecmp("udp://",url,6))
18 return 1;
19
20 return 0;
21 }
22
23 int open_mcast(char *url)
24 {
25 struct dvb_host *dvbhost = NULL;
26 struct sockaddr_in server;
27 struct ip_mreq mreq;
28 int val;
29 int fd;
30
31 if(!is_mcast(url))
32 return -1;
33
34 dvbhost = parse(&(url[6]), "2000");
35 dvbhost->socktype = SOCK_DGRAM;
36
37 if (resolve(dvbhost, &server) < 0) {
38 return -1;
39 }
40
41 bzero(&mreq, sizeof(mreq));
42 mreq.imr_multiaddr = server.sin_addr;
43 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
44
45 if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
46 perror("socket");
47 return -1;
48 }
49
50 val = 1;
51 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
52 perror("setsockopt");
53 return -1;
54 }
55
56 if (bind(fd, (struct sockaddr*)&server, sizeof(server)) < 0) {
57 perror("bind");
58 return -1;
59 }
60
61 if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
62 perror("setsockopt");
63 return -1;
64 }
65
66 return fd;
67 }
Impressum, Datenschutz