implement (probably working) multicast
[record-dvb] / common.c
index 97ec8073e93d681e7101abf6669f9dbb5af0a331..80327f5292ed0b711fefa261e485309087810916 100644 (file)
--- a/common.c
+++ b/common.c
@@ -2,6 +2,9 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 
 #include "common.h"
 
@@ -62,3 +65,28 @@ struct dvb_host *parse(char *urlpart, char *defport)
 
        return dvbhost;
 }
+
+int resolve(struct dvb_host *dvbhost, struct sockaddr_in *server)
+{
+       struct addrinfo *s_addrinfo, addrhints;
+       int res;
+
+       bzero(&addrhints, sizeof(struct addrinfo));
+       addrhints.ai_family = PF_INET;
+       addrhints.ai_socktype = dvbhost->socktype;
+
+       if ((res = getaddrinfo(dvbhost->hostname, dvbhost->port, &addrhints, &s_addrinfo))) {
+               fprintf(stderr,"getaddrinfo: %s\n",gai_strerror(res));
+               return -1;
+       }
+
+       bzero(server, sizeof(struct sockaddr_in));
+       server->sin_family = AF_INET;
+       server->sin_addr.s_addr = ((struct sockaddr_in*)(s_addrinfo->ai_addr))->sin_addr.s_addr;
+       server->sin_port = ((struct sockaddr_in*)(s_addrinfo->ai_addr))->sin_port;
+
+       freeaddrinfo(s_addrinfo);
+
+       return 0;
+}
+
Impressum, Datenschutz