diff options
author | Nick White <hg@njw.me.uk> | 2011-07-15 22:36:48 +0100 |
---|---|---|
committer | Nick White <hg@njw.me.uk> | 2011-07-15 22:36:48 +0100 |
commit | 2061b653da64bcb90c217144686f74ee734fb90c (patch) | |
tree | 460ad8aa2270f9d237f1a9fd8981dda69c0aaf84 /getgbook.c | |
parent | d2be24f0b636d93e1873e27207e841150e9f54bf (diff) |
Move parts over to util.c
Diffstat (limited to 'getgbook.c')
-rw-r--r-- | getgbook.c | 33 |
1 files changed, 1 insertions, 32 deletions
@@ -5,38 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> -#include <netdb.h> -#include <netinet/in.h> -#include <sys/socket.h> - -void die(char *msg) { - fputs(msg, stderr); - exit(EXIT_FAILURE); -} - -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; -} +#include "util.c" char * get(FILE *srv, char *host, char *path) { size_t l, res; |