1 /* See LICENSE file for license details. */
3 #include <netinet/in.h>
4 #include <sys/socket.h>
7 eprint(const char *fmt, ...) {
11 vsnprintf(bufout, sizeof bufout, fmt, ap);
13 fprintf(stderr, "%s", bufout);
14 if(fmt[0] && fmt[strlen(fmt) - 1] == ':')
15 fprintf(stderr, " %s\n", strerror(errno));
20 dial(char *host, char *port) {
21 struct addrinfo hints;
22 struct addrinfo *res, *r;
25 memset(&hints, 0, sizeof hints);
26 hints.ai_family = AF_UNSPEC;
27 hints.ai_socktype = SOCK_STREAM;
28 if(getaddrinfo(host, port, &hints, &res) != 0)
29 eprint("error: cannot resolve hostname '%s':", host);
30 for(r = res; r; r = r->ai_next) {
31 if((fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
33 if(connect(fd, r->ai_addr, r->ai_addrlen) == 0)
39 eprint("error: cannot connect to host '%s'\n", host);
44 eat(char *s, int (*p)(int), int r) {
45 while(*s != '\0' && p((unsigned char)*s) == r)
51 skip(char *s, char c) {
52 while(*s != c && *s != '\0')
63 e = s + strlen(s) - 1;
64 while(e > s && isspace((unsigned char)*e))