4 * Copyright (c) 2021-2024 Omar Polo <op@omarpolo.com>
5 * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
6 * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
8 * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
9 * Copyright (c) 2001 Markus Friedl. All rights reserved.
10 * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
11 * Copyright (c) 2001 Theo de Raadt. All rights reserved.
13 * Permission to use, copy, modify, and distribute this software for any
14 * purpose with or without fee is hereby granted, provided that the above
15 * copyright notice and this permission notice appear in all copies.
17 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41 static const char *default_host = NULL;
42 static uint16_t default_port = 1965;
44 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
46 TAILQ_ENTRY(file) entry;
57 struct file *pushfile(const char *, int);
61 void yyerror(const char *, ...)
62 __attribute__((__format__ (printf, 1, 2)))
63 __attribute__((__nonnull__ (1)));
64 void yywarn(const char *, ...)
65 __attribute__((__format__ (printf, 1, 2)))
66 __attribute__((__nonnull__ (1)));
67 int kw_cmp(const void *, const void *);
79 TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
81 TAILQ_ENTRY(sym) entry;
88 int symset(const char *, const char *, int);
89 char *symget(const char *);
91 char *ensure_absolute_path(char*);
92 int check_block_code(int);
93 char *check_block_fmt(char*);
94 int check_strip_no(int);
95 int check_prefork_num(int);
96 void advance_loc(void);
97 void advance_proxy(void);
98 int fastcgi_conf(const char *, const char *);
99 void add_param(char *, char *);
100 int getservice(const char *);
101 void listen_on(const char *, const char *);
103 static struct vhost *host;
104 static struct location *loc;
105 static struct proxy *proxy;
106 static char *current_media;
117 #define YYSTYPE YYSTYPE
122 /* %define parse.error verbose */
124 %token ACCESS ALIAS AUTO
126 %token CA CERT CHROOT CLIENT
128 %token FACILITY FASTCGI FOR_HOST
129 %token INCLUDE INDEX IPV6
131 %token LANG LISTEN LOCATION LOG
133 %token PARAM PORT PREFORK PROTO PROTOCOLS PROXY
134 %token RELAY_TO REQUIRE RETURN ROOT
135 %token SERVER SNI SOCKET STRIP STYLE SYSLOG
136 %token TCP TOEXT TYPE TYPES
142 %token <v.string> STRING
143 %token <v.number> NUM
145 %type <v.number> bool proxy_port
146 %type <v.string> string numberstring listen_addr
156 | conf error nl { file->errors++; }
159 include : INCLUDE STRING {
162 if ((nfile = pushfile($2, 0)) == NULL) {
163 yyerror("failed to include file %s", $2);
174 bool : ON { $$ = 1; }
178 string : string STRING {
179 if (asprintf(&$$, "%s%s", $1, $2) == -1) {
182 yyerror("string: asprintf: %s", strerror(errno));
193 if (asprintf(&s, "%d", $1) == -1) {
194 yyerror("asprintf: number");
202 varset : STRING '=' string {
205 if (isspace((unsigned char)*s)) {
206 yyerror("macro name cannot contain "
219 option : CHROOT string {
220 if (strlcpy(conf->chroot, $2, sizeof(conf->chroot)) >=
221 sizeof(conf->chroot))
222 yyerror("chroot path too long");
226 yywarn("option `ipv6' is deprecated,"
227 " please use `listen on'");
231 default_host = "0.0.0.0";
235 yywarn("option `port' is deprecated,"
236 " please use `listen on'");
239 | PREFORK NUM { conf->prefork = check_prefork_num($2); }
241 if (tls_config_parse_protocols(&conf->protos, $2) == -1)
242 yyerror("invalid protocols string \"%s\"", $2);
246 if (strlcpy(conf->user, $2, sizeof(conf->user)) >=
248 yyerror("user name too long");
253 log : LOG '{' optnl logopts '}'
257 logopts : /* empty */
258 | logopts logopt optnl
261 logopt : ACCESS string {
262 free(conf->log_access);
263 conf->log_access = $2;
266 if (!strcmp("combined", $2))
267 conf->log_format = LOG_FORMAT_COMBINED;
268 else if (!strcmp("common", $2))
269 conf->log_format = LOG_FORMAT_COMMON;
270 else if (!strcmp("condensed", $2))
271 conf->log_format = LOG_FORMAT_CONDENSED;
272 else if (!strcmp("legacy", $2))
273 conf->log_format = LOG_FORMAT_LEGACY;
275 yyerror("unknown log style: %s", $2);
278 | SYSLOG FACILITY string {
279 const char *str = $3;
281 conf->log_syslog = 1;
283 if (!strncasecmp(str, "LOG_", 4))
286 if (!strcasecmp(str, "daemon"))
287 conf->log_facility = LOG_DAEMON;
289 else if (!strcasecmp(str, "ftp"))
290 conf->log_facility = LOG_FTP;
292 else if (!strcasecmp(str, "local1"))
293 conf->log_facility = LOG_LOCAL1;
294 else if (!strcasecmp(str, "local2"))
295 conf->log_facility = LOG_LOCAL2;
296 else if (!strcasecmp(str, "local3"))
297 conf->log_facility = LOG_LOCAL3;
298 else if (!strcasecmp(str, "local4"))
299 conf->log_facility = LOG_LOCAL4;
300 else if (!strcasecmp(str, "local5"))
301 conf->log_facility = LOG_LOCAL5;
302 else if (!strcasecmp(str, "local6"))
303 conf->log_facility = LOG_LOCAL6;
304 else if (!strcasecmp(str, "local7"))
305 conf->log_facility = LOG_LOCAL7;
306 else if (!strcasecmp(str, "user"))
307 conf->log_facility = LOG_USER;
309 yywarn("unknown syslog facility `%s'",
315 conf->log_syslog = 0;
318 conf->log_syslog = 1;
322 vhost : SERVER string {
324 TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
326 loc = new_location();
327 TAILQ_INSERT_HEAD(&host->locations, loc, locations);
329 TAILQ_INIT(&host->proxies);
331 (void) strlcpy(loc->match, "*", sizeof(loc->match));
332 (void) strlcpy(host->domain, $2, sizeof(host->domain));
334 if (strstr($2, "xn--") != NULL) {
335 yywarn("\"%s\" looks like punycode: you "
336 "should use the decoded hostname", $2);
340 } '{' optnl servbody '}' {
341 if (host->cert_path == NULL ||
342 host->key_path == NULL)
343 yyerror("invalid vhost definition: %s",
345 if (TAILQ_EMPTY(&host->addrs)) {
349 r = snprintf(portno, sizeof(portno), "%d",
351 if (r < 0 || (size_t)r >= sizeof(portno))
354 yywarn("missing `listen on' in server %s,"
355 " assuming %s port %d", host->domain,
356 default_host ? default_host : "*",
358 listen_on(default_host, portno);
361 | error '}' { yyerror("bad server directive"); }
364 servbody : /* empty */
365 | servbody servopt optnl
366 | servbody location optnl
367 | servbody proxy optnl
370 listen_addr : '*' { $$ = NULL; }
374 servopt : ALIAS string {
377 a = xcalloc(1, sizeof(*a));
378 (void) strlcpy(a->alias, $2, sizeof(a->alias));
380 TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
383 ensure_absolute_path($2);
384 free(host->cert_path);
385 host->cert_path = $2;
388 ensure_absolute_path($2);
389 free(host->key_path);
393 ensure_absolute_path($2);
394 free(host->ocsp_path);
395 host->ocsp_path = $2;
397 | PARAM string '=' string {
398 yywarn("the top-level `param' directive is deprecated."
399 " Please use `fastcgi { param ... }`");
402 | LISTEN ON listen_addr {
403 listen_on($3, "1965");
406 | LISTEN ON listen_addr PORT STRING {
411 | LISTEN ON listen_addr PORT NUM {
415 r = snprintf(portno, sizeof(portno), "%d", $5);
416 if (r < 0 || (size_t)r >= sizeof(portno))
419 listen_on($3, portno);
425 proxy : PROXY { advance_proxy(); }
426 proxy_matches '{' optnl proxy_opts '}' {
427 if (*proxy->host == '\0')
428 yyerror("invalid proxy block: missing `relay-to' option");
430 if ((proxy->cert_path == NULL && proxy->key_path != NULL) ||
431 (proxy->cert_path != NULL && proxy->key_path == NULL))
432 yyerror("invalid proxy block: missing cert or key");
436 proxy_matches : /* empty */
437 | proxy_matches proxy_match
440 proxy_port : /* empty */ { $$ = 1965; }
442 if (($$ = getservice($2)) == -1)
443 yyerror("invalid port number %s", $2);
446 | PORT NUM { $$ = $2; }
449 proxy_match : PROTO string {
450 (void) strlcpy(proxy->match_proto, $2, sizeof(proxy->match_proto));
453 | FOR_HOST string proxy_port {
454 (void) strlcpy(proxy->match_host, $2, sizeof(proxy->match_host));
455 (void) snprintf(proxy->match_port, sizeof(proxy->match_port),
461 proxy_opts : /* empty */
462 | proxy_opts proxy_opt optnl
465 proxy_opt : CERT string {
467 ensure_absolute_path($2);
468 proxy->cert_path = $2;
472 ensure_absolute_path($2);
473 proxy->key_path = $2;
476 if (tls_config_parse_protocols(&proxy->protocols, $2) == -1)
477 yyerror("invalid protocols string \"%s\"", $2);
480 | RELAY_TO string proxy_port {
481 (void) strlcpy(proxy->host, $2, sizeof(proxy->host));
482 (void) snprintf(proxy->port, sizeof(proxy->port),
486 | REQUIRE CLIENT CA string {
487 ensure_absolute_path($4);
488 proxy->reqca_path = $4;
491 (void) strlcpy(proxy->sni, $2, sizeof(proxy->sni));
498 proxy->noverifyname = !$2;
502 location : LOCATION { advance_loc(); } string '{' optnl locopts '}' {
503 /* drop the starting '/' if any */
505 memmove($3, $3+1, strlen($3));
506 (void) strlcpy(loc->match, $3, sizeof(loc->match));
512 locopts : /* empty */
513 | locopts locopt optnl
516 locopt : AUTO INDEX bool { loc->auto_index = $3 ? 1 : -1; }
517 | BLOCK RETURN NUM string {
519 (void) strlcpy(loc->block_fmt, $4, sizeof(loc->block_fmt));
520 loc->block_code = check_block_code($3);
524 (void) strlcpy(loc->block_fmt, "temporary failure",
525 sizeof(loc->block_fmt));
526 loc->block_code = check_block_code($3);
527 if ($3 >= 30 && $3 < 40)
528 yyerror("missing `meta' for block return %d", $3);
531 (void) strlcpy(loc->block_fmt, "temporary failure",
532 sizeof(loc->block_fmt));
533 loc->block_code = 40;
535 | DEFAULT TYPE string {
536 (void) strlcpy(loc->default_mime, $3,
537 sizeof(loc->default_mime));
542 (void) strlcpy(loc->index, $2, sizeof(loc->index));
546 (void) strlcpy(loc->lang, $2,
550 | LOG bool { loc->disable_log = !$2; }
551 | REQUIRE CLIENT CA string {
552 ensure_absolute_path($4);
553 loc->reqca_path = $4;
556 (void) strlcpy(loc->dir, $2, sizeof(loc->dir));
559 | STRIP NUM { loc->strip = check_strip_no($2); }
562 fastcgi : FASTCGI '{' optnl fastcgiopts '}'
569 yywarn("`fastcgi path' is deprecated. "
570 "Please use `fastcgi socket path' instead.");
571 loc->fcgi = fastcgi_conf($2, NULL);
576 fastcgiopts : /* empty */
577 | fastcgiopts fastcgiopt optnl
580 fastcgiopt : PARAM string '=' string {
584 loc->fcgi = fastcgi_conf($2, NULL);
587 | SOCKET TCP string PORT NUM {
590 if (asprintf(&c, "%d", $5) == -1)
592 loc->fcgi = fastcgi_conf($3, c);
596 | SOCKET TCP string {
597 loc->fcgi = fastcgi_conf($3, "9000");
599 | SOCKET TCP string PORT string {
600 loc->fcgi = fastcgi_conf($3, $5);
605 loc->fcgi_strip = $2;
609 types : TYPES '{' optnl mediaopts_l '}' ;
611 mediaopts_l : mediaopts_l mediaoptsl nl
615 mediaoptsl : STRING {
622 medianames_l : medianames_l medianamesl
626 medianamesl : numberstring {
627 if (add_mime(&conf->mime, current_media, $1) == -1)
643 static const struct keyword {
647 /* these MUST be sorted */
656 {"default", DEFAULT},
657 {"facility", FACILITY},
658 {"fastcgi", FASTCGI},
659 {"for-host", FOR_HOST},
660 {"include", INCLUDE},
666 {"location", LOCATION},
673 {"prefork", PREFORK},
675 {"protocols", PROTOCOLS},
677 {"relay-to", RELAY_TO},
678 {"require", REQUIRE},
691 {"use-tls", USE_TLS},
693 {"verifyname", VERIFYNAME},
697 yyerror(const char *msg, ...)
704 fprintf(stderr, "%s:%d error: ", config_path, yylval.lineno);
705 vfprintf(stderr, msg, ap);
706 fprintf(stderr, "\n");
711 yywarn(const char *msg, ...)
716 fprintf(stderr, "%s:%d warning: ", config_path, yylval.lineno);
717 vfprintf(stderr, msg, ap);
718 fprintf(stderr, "\n");
723 kw_cmp(const void *k, const void *e)
725 return strcmp(k, ((struct keyword *)e)->word);
731 const struct keyword *p;
733 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
734 sizeof(keywords[0]), kw_cmp);
742 #define START_EXPAND 1
743 #define DONE_EXPAND 2
745 static int expanding;
753 if (file->ungetpos > 0)
754 c = file->ungetbuf[--file->ungetpos];
756 c = getc(file->stream);
758 if (c == START_EXPAND)
760 else if (c == DONE_EXPAND)
774 if ((c = igetc()) == EOF) {
775 yyerror("reached end of file while parsing "
777 if (file == topfile || popfile() == EOF)
784 while ((c = igetc()) == '\\') {
790 yylval.lineno = file->lineno;
796 * Fake EOL when hit EOF for the first time. This gets line
797 * count right if last line in included file is syntactically
798 * invalid and has no newline.
800 if (file->eof_reached == 0) {
801 file->eof_reached = 1;
805 if (file == topfile || popfile() == EOF)
819 if (file->ungetpos >= file->ungetsize) {
820 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
824 file->ungetsize *= 2;
826 file->ungetbuf[file->ungetpos++] = c;
834 /* Skip to either EOF or the first real EOL. */
857 while ((c = lgetc(0)) == ' ' || c == '\t')
860 yylval.lineno = file->lineno;
862 while ((c = lgetc(0)) != '\n' && c != EOF)
864 if (c == '$' && !expanding) {
866 if ((c = lgetc(0)) == EOF)
868 if (p + 1 >= buf + sizeof(buf) -1) {
869 yyerror("string too long");
872 if (isalnum(c) || c == '_') {
882 yyerror("macro `%s' not defined", buf);
885 yylval.v.string = xstrdup(val);
888 if (c == '@' && !expanding) {
890 if ((c = lgetc(0)) == EOF)
893 if (p + 1 >= buf + sizeof(buf) - 1) {
894 yyerror("string too long");
897 if (isalnum(c) || c == '_') {
907 yyerror("macro '%s' not defined", buf);
910 p = val + strlen(val) - 1;
911 lungetc(DONE_EXPAND);
916 lungetc(START_EXPAND);
925 if ((c = lgetc(quotec)) == EOF)
930 } else if (c == '\\') {
931 if ((next = lgetc(quotec)) == EOF)
933 if (next == quotec || next == ' ' ||
936 else if (next == '\n') {
941 } else if (c == quotec) {
944 } else if (c == '\0') {
945 yyerror("invalid syntax");
948 if (p + 1 >= buf + sizeof(buf) - 1) {
949 yyerror("string too long");
954 yylval.v.string = strdup(buf);
955 if (yylval.v.string == NULL)
956 fatal("yylex: strdup");
960 #define allowed_to_end_number(x) \
961 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
963 if (c == '-' || isdigit(c)) {
966 if ((size_t)(p-buf) >= sizeof(buf)) {
967 yyerror("string too long");
970 } while ((c = lgetc(0)) != EOF && isdigit(c));
972 if (p == buf + 1 && buf[0] == '-')
974 if (c == EOF || allowed_to_end_number(c)) {
975 const char *errstr = NULL;
978 yylval.v.number = strtonum(buf, LLONG_MIN,
981 yyerror("\"%s\" invalid number: %s",
996 #define allowed_in_string(x) \
997 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
998 x != '{' && x != '}' && \
999 x != '!' && x != '=' && x != '#' && \
1000 x != ',' && x != ';'))
1002 if (isalnum(c) || c == ':' || c == '_') {
1005 if ((size_t)(p-buf) >= sizeof(buf)) {
1006 yyerror("string too long");
1009 } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
1012 if ((token = lookup(buf)) == STRING)
1013 yylval.v.string = xstrdup(buf);
1017 yylval.lineno = file->lineno;
1026 pushfile(const char *name, int secret)
1030 nfile = xcalloc(1, sizeof(*nfile));
1031 nfile->name = xstrdup(name);
1032 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
1033 log_warn("can't open %s", nfile->name);
1038 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
1039 nfile->ungetsize = 16;
1040 nfile->ungetbuf = xcalloc(1, nfile->ungetsize);
1041 TAILQ_INSERT_TAIL(&files, nfile, entry);
1050 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
1051 prev->errors += file->errors;
1053 TAILQ_REMOVE(&files, file, entry);
1054 fclose(file->stream);
1056 free(file->ungetbuf);
1059 return file ? 0 : EOF;
1063 parse_conf(struct conf *c, const char *filename)
1065 struct sym *sym, *next;
1067 default_host = NULL;
1068 default_port = 1965;
1072 file = pushfile(filename, 0);
1078 errors = file->errors;
1081 /* Free macros and check which have not been used. */
1082 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
1083 /* TODO: warn if !sym->used */
1084 if (!sym->persist) {
1087 TAILQ_REMOVE(&symhead, sym, entry);
1098 symset(const char *name, const char *val, int persist)
1102 TAILQ_FOREACH(sym, &symhead, entry) {
1103 if (!strcmp(name, sym->name))
1113 TAILQ_REMOVE(&symhead, sym, entry);
1118 sym = xcalloc(1, sizeof(*sym));
1119 sym->name = xstrdup(name);
1120 sym->val = xstrdup(val);
1122 sym->persist = persist;
1124 TAILQ_INSERT_TAIL(&symhead, sym, entry);
1129 cmdline_symset(char *s)
1134 if ((val = strrchr(s, '=')) == NULL)
1136 sym = xcalloc(1, val - s + 1);
1137 memcpy(sym, s, val - s);
1138 ret = symset(sym, val + 1, 1);
1144 symget(const char *nam)
1148 TAILQ_FOREACH(sym, &symhead, entry) {
1149 if (strcmp(nam, sym->name) == 0) {
1158 ensure_absolute_path(char *path)
1160 if (path == NULL || *path != '/')
1161 yyerror("not an absolute path: %s", path);
1166 check_block_code(int n)
1168 if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
1169 yyerror("invalid block code %d", n);
1174 check_block_fmt(char *fmt)
1178 for (s = fmt; *s; ++s) {
1189 yyerror("invalid format specifier %%%c", *s);
1197 check_strip_no(int n)
1200 yyerror("invalid strip number %d", n);
1205 check_prefork_num(int n)
1207 if (n <= 0 || n >= PROC_MAX_INSTANCES)
1208 yyerror("invalid prefork number %d", n);
1215 loc = new_location();
1216 TAILQ_INSERT_TAIL(&host->locations, loc, locations);
1222 proxy = new_proxy();
1223 TAILQ_INSERT_TAIL(&host->proxies, proxy, proxies);
1227 fastcgi_conf(const char *path, const char *port)
1232 TAILQ_FOREACH(f, &conf->fcgi, fcgi) {
1233 if (!strcmp(f->path, path) &&
1234 ((port == NULL && *f->port == '\0') ||
1235 !strcmp(f->port, port)))
1240 f = xcalloc(1, sizeof(*f));
1242 (void)strlcpy(f->path, path, sizeof(f->path));
1244 (void)strlcpy(f->port, port, sizeof(f->port));
1245 TAILQ_INSERT_TAIL(&conf->fcgi, f, fcgi);
1251 add_param(char *name, char *val)
1254 struct envhead *h = &loc->params;
1256 e = xcalloc(1, sizeof(*e));
1257 (void) strlcpy(e->name, name, sizeof(e->name));
1258 (void) strlcpy(e->value, val, sizeof(e->value));
1259 TAILQ_INSERT_TAIL(h, e, envs);
1263 getservice(const char *n)
1269 llval = strtonum(n, 0, UINT16_MAX, &errstr);
1271 s = getservbyname(n, "tcp");
1273 s = getservbyname(n, "udp");
1276 return (ntohs(s->s_port));
1279 return ((unsigned short)llval);
1283 add_to_addr_queue(struct addrhead *a, struct addrinfo *ai)
1285 struct address *addr;
1286 struct sockaddr_in *sin;
1287 struct sockaddr_in6 *sin6;
1289 if (ai->ai_addrlen > sizeof(addr->ss))
1290 fatalx("ai_addrlen larger than a sockaddr_storage");
1292 TAILQ_FOREACH(addr, a, addrs) {
1293 if (addr->ai_flags == ai->ai_flags &&
1294 addr->ai_family == ai->ai_family &&
1295 addr->ai_socktype == ai->ai_socktype &&
1296 addr->ai_protocol == ai->ai_protocol &&
1297 addr->slen == ai->ai_addrlen &&
1298 !memcmp(&addr->ss, ai->ai_addr, addr->slen))
1302 addr = xcalloc(1, sizeof(*addr));
1303 addr->ai_flags = ai->ai_flags;
1304 addr->ai_family = ai->ai_family;
1305 addr->ai_socktype = ai->ai_socktype;
1306 addr->ai_protocol = ai->ai_protocol;
1307 addr->slen = ai->ai_addrlen;
1308 memcpy(&addr->ss, ai->ai_addr, ai->ai_addrlen);
1311 switch (addr->ai_family) {
1313 sin = (struct sockaddr_in *)&addr->ss;
1314 addr->port = ntohs(sin->sin_port);
1317 sin6 = (struct sockaddr_in6 *)&addr->ss;
1318 addr->port = ntohs(sin6->sin6_port);
1321 fatalx("unknown socket family %d", addr->ai_family);
1326 TAILQ_INSERT_HEAD(a, addr, addrs);
1330 listen_on(const char *hostname, const char *servname)
1332 struct addrinfo hints, *res, *res0;
1335 memset(&hints, 0, sizeof(hints));
1336 hints.ai_family = AF_UNSPEC;
1337 hints.ai_socktype = SOCK_STREAM;
1338 hints.ai_flags = AI_PASSIVE;
1339 error = getaddrinfo(hostname, servname, &hints, &res0);
1341 yyerror("listen on \"%s\" port %s: %s", hostname, servname,
1342 gai_strerror(errno));
1346 for (res = res0; res; res = res->ai_next) {
1347 add_to_addr_queue(&host->addrs, res);
1348 add_to_addr_queue(&conf->addrs, res);