]>
cvs.zerfleddert.de Git - record-dvb/blob - http.c
6 #include <sys/socket.h>
7 #include <netinet/in.h>
16 int is_http(char *url
)
21 if (!strncasecmp("http://",url
,7))
27 int open_http(char *url
)
30 struct sockaddr_in server
;
31 struct dvb_host
*dvbhost
;
32 struct addrinfo
*s_addrinfo
, addrhints
;
33 char buffer
[BUFFSIZE
];
39 dvbhost
= parse(&(url
[7]), "80");
41 bzero(&addrhints
, sizeof(struct addrinfo
));
42 addrhints
.ai_family
= PF_INET
;
43 addrhints
.ai_socktype
= SOCK_STREAM
;
45 if ((i
=getaddrinfo(dvbhost
->hostname
, dvbhost
->port
, &addrhints
, &s_addrinfo
))) {
46 fprintf(stderr
,"getaddrinfo: %s\n",gai_strerror(i
));
50 if ((fd
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
)) < 0) {
55 bzero(&server
, sizeof(struct sockaddr_in
));
56 server
.sin_family
= AF_INET
;
57 server
.sin_addr
.s_addr
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_addr
.s_addr
;
58 server
.sin_port
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_port
;
60 if (connect(fd
, (struct sockaddr
*) &server
, sizeof(server
)) < 0) {
65 freeaddrinfo(s_addrinfo
);
68 snprintf(buffer
, BUFFSIZE
-1, "GET /%s HTTP/1.0\n\n",dvbhost
->location
);
69 buffer
[BUFFSIZE
-1] = 0;
70 send(fd
, buffer
, strlen(buffer
), 0);
73 if (recv(fd
, buffer
, 1, 0) < 1) {
77 printf("%c",buffer
[0]);
78 if (buffer
[0] == 0x0a)
81 if (buffer
[0] != 0x0d)