X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/record-dvb/blobdiff_plain/5c2e3e4489486a30d8f14338277de093b4d94cf0..b973e875ef2e7f45e9eee04c04805fc817f0ff05:/common.c diff --git a/common.c b/common.c index 97ec807..80327f5 100644 --- a/common.c +++ b/common.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #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; +} +