X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/record-dvb/blobdiff_plain/cda833b266970ebc861d5e84779f13571b05834e..b973e875ef2e7f45e9eee04c04805fc817f0ff05:/http.c diff --git a/http.c b/http.c index 65c1238..ca756bd 100644 --- a/http.c +++ b/http.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "common.h" #include "http.h" @@ -28,22 +27,19 @@ int open_http(char *url) { int fd; struct sockaddr_in server; - struct dvb_host *dvbhost; - struct addrinfo *s_addrinfo, addrhints; + static struct dvb_host *dvbhost = NULL; char buffer[BUFFSIZE]; int i; if(!is_http(url)) return -1; - dvbhost = parse(&(url[7]), "80"); - - bzero(&addrhints, sizeof(struct addrinfo)); - addrhints.ai_family = PF_INET; - addrhints.ai_socktype = SOCK_STREAM; + if (!dvbhost) { + dvbhost = parse(&(url[7]), "80"); + dvbhost->socktype = SOCK_STREAM; + } - if ((i = getaddrinfo(dvbhost->hostname, dvbhost->port, &addrhints, &s_addrinfo))) { - fprintf(stderr,"getaddrinfo: %s\n",gai_strerror(i)); + if (resolve(dvbhost, &server) < 0) { return -1; } @@ -52,19 +48,11 @@ int open_http(char *url) 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; - if (connect(fd, (struct sockaddr*) &server, sizeof(server)) < 0) { perror("connect"); return -1; } - freeaddrinfo(s_addrinfo); - - snprintf(buffer, BUFFSIZE-1, "GET /%s HTTP/1.0\n\n",dvbhost->location); buffer[BUFFSIZE-1] = 0; send(fd, buffer, strlen(buffer), 0);