implement (probably working) multicast
[record-dvb] / mcast.c
diff --git a/mcast.c b/mcast.c
index 242fac09f807e64b62bac9acf11027c1d32719d2..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,9 +22,41 @@ int is_mcast(char *url)
 
 int open_mcast(char *url)
 {
+       static struct dvb_host *dvbhost = NULL;
+       struct sockaddr_in server;
+       struct ip_mreq mreq;
+       int fd;
+
        if(!is_mcast(url))
                return -1;
 
-       fprintf(stderr,"multicast currently unimplemented!\n");
-       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;
+       }
+
+       return fd;
 }
Impressum, Datenschutz