2 #include <netinet/in.h>
3 #include <sys/socket.h>
5 #define va_buf(buf, fmt) {\
8 vsnprintf(buf, sizeof buf, fmt, ap); \
13 eprint(const char *fmt, ...) {
16 fprintf(stderr, "%s", bufout);
18 if(fmt[0] && fmt[strlen(fmt)-1] == ':')
19 fprintf(stderr, " %s\n", strerror(errno));
24 dial(char *host, char *port) {
25 static struct addrinfo hints;
26 struct addrinfo *res, *r;
29 memset(&hints, 0, sizeof hints);
30 hints.ai_family = AF_UNSPEC;
31 hints.ai_socktype = SOCK_STREAM;
32 if(getaddrinfo(host, port, &hints, &res) != 0)
33 eprint("error: cannot resolve hostname '%s':", host);
34 for(r = res; r; r = r->ai_next) {
35 if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
37 if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
43 eprint("error: cannot connect to host '%s'\n", host);
47 #define strlcpy _strlcpy
49 strlcpy(char *to, const char *from, int l) {
50 memccpy(to, from, '\0', l);
55 eat(char **s, int (*p)(int), int r) {
58 for(q=*s; *q && p(*q) == r; q++)
70 if(**s) *(*s)++ = '\0';
75 ctok(char **s, int c) {
79 for(p=q; *p && *p != c; p++)