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 static struct addrinfo hints;
23 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((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
33 if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
39 eprint("error: cannot connect to host '%s'\n", host);
43 #define strlcpy _strlcpy
45 strlcpy(char *to, const char *from, int l) {
46 memccpy(to, from, '\0', l);
51 eat(char **s, int (*p)(int), int r) {
54 for(q = *s; *q && p(*q) == r; q++)
72 ctok(char **s, int c) {
76 for(p = q; *p && *p != c; p++)