From 14f2069f02e86c54209e03f284aebd81ce8b85e4 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 15 Jul 2011 22:40:48 +0100 Subject: Move everything back to getgbook.c --- getgbook.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'getgbook.c') diff --git a/getgbook.c b/getgbook.c index a98ef79..6cf75df 100644 --- a/getgbook.c +++ b/getgbook.c @@ -1,3 +1,5 @@ +#define VERSION "prealpha" + #define usage "getgbook bookid" #define hostname "books.google.com" @@ -5,14 +7,45 @@ #include #include #include -#include "util.c" +#include +#include +#include + +void die(char *msg) { + fputs(msg, stderr); + exit(EXIT_FAILURE); +} + +/* plundered from suckless' sic */ +static int dial(char *host, char *port) { + static struct addrinfo hints; + int srv; + struct addrinfo *res, *r; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if(getaddrinfo(host, port, &hints, &res) != 0) + die("error: cannot resolve hostname\n"); + for(r = res; r; r = r->ai_next) { + if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1) + continue; + if(connect(srv, r->ai_addr, r->ai_addrlen) == 0) + break; + close(srv); + } + freeaddrinfo(res); + if(!r) + die("error: cannot connect to host\n"); + return srv; +} -char * get(FILE *srv, char *host, char *path) { +char *get(FILE *srv, char *host, char *path) { size_t l, res; int fd, i; char *buf, *c, *p; - fprintf(srv, "GET %s HTTP/1.0\r\nUser-Agent: getgbook-prealpha (not mozilla)\r\nHost: %s\r\n\r\n", path, host); + fprintf(srv, "GET %s HTTP/1.0\r\nUser-Agent: getgbook-"VERSION" (not mozilla)\r\nHost: %s\r\n\r\n", path, host); fflush(srv); -- cgit v1.2.3