]> cvs.zerfleddert.de Git - record-dvb/blame - mcast.c
fix in6_addr problems
[record-dvb] / mcast.c
CommitLineData
5c2e3e44 1#include <strings.h>
2#include <string.h>
3#include <stdio.h>
4#include <stdlib.h>
fbc24ab0 5#include <sys/types.h>
6#include <sys/socket.h>
7#include <netdb.h>
d5eca7f2 8
9#include "common.h"
5c2e3e44 10#include "mcast.h"
11
12int 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
23int open_mcast(char *url)
24{
90d8d87b 25 struct dvb_host *dvbhost = NULL;
fbc24ab0 26 struct sockaddr_in server;
27 struct ip_mreq mreq;
d1199471 28 int val;
d5eca7f2 29 int fd;
30
6bcf6c4c 31 if(!is_mcast(url))
32 return -1;
5c2e3e44 33
90d8d87b 34 dvbhost = parse(&(url[6]), "2000");
35 dvbhost->socktype = SOCK_DGRAM;
d5eca7f2 36
fbc24ab0 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
d1199471 50 val = 1;
51 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
52 perror("setsockopt");
53 return -1;
54 }
55
fbc24ab0 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 }
d5eca7f2 65
66 return fd;
5c2e3e44 67}
Impressum, Datenschutz