]> git.zerfleddert.de Git - record-dvb/blobdiff - mcast.c
add dump-mcast for dumping multicast-streams to stdout
[record-dvb] / mcast.c
diff --git a/mcast.c b/mcast.c
index a8be22f6c3fa6bed81e5b02120db377df8020a0f..5f7dadc5d66bbbea98ef1a733e8695ebababb805 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,41 @@ int is_mcast(char *url)
 
 int open_mcast(char *url)
 {
-       fprintf(stderr,"multicast currently unimplemented!\n");
+       static struct dvb_host *dvbhost = NULL;
+       struct sockaddr_in server;
+       struct ip_mreq mreq;
+       int fd;
+
+       if(!is_mcast(url))
+               return -1;
+
+       if (!dvbhost) {
+               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;
+       }
+
+       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