]> git.zerfleddert.de Git - record-dvb/blobdiff - mcast.c
fix in6_addr problems
[record-dvb] / mcast.c
diff --git a/mcast.c b/mcast.c
index a8be22f6c3fa6bed81e5b02120db377df8020a0f..fd88569f2b09521026644934892b1864092c1a74 100644 (file)
--- a/mcast.c
+++ b/mcast.c
@@ -2,6 +2,11 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include "common.h"
 #include "mcast.h"
 
 int is_mcast(char *url)
@@ -17,7 +22,46 @@ int is_mcast(char *url)
 
 int open_mcast(char *url)
 {
-       fprintf(stderr,"multicast currently unimplemented!\n");
+       struct dvb_host *dvbhost = NULL;
+       struct sockaddr_in server;
+       struct ip_mreq mreq;
+       int val;
+       int fd;
+
+       if(!is_mcast(url))
+               return -1;
+
+       dvbhost = parse(&(url[6]), "2000");
+       dvbhost->socktype = SOCK_DGRAM;
+
+       if (resolve(dvbhost, &server) < 0) {
+               return -1;
+       }
+
+       bzero(&mreq, sizeof(mreq));
+       mreq.imr_multiaddr = server.sin_addr;
+       mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+
+       if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+               perror("socket");
+               return -1;
+       }
+
+       val = 1;
+       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
+               perror("setsockopt");
+               return -1;
+       }
+
+       if (bind(fd, (struct sockaddr*)&server, sizeof(server)) < 0) {
+               perror("bind");
+               return -1;
+       }
+
+       if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
+               perror("setsockopt");
+               return -1;
+       }
 
-       exit(EXIT_FAILURE);
+       return fd;
 }
Impressum, Datenschutz