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_port_num(int);
96 int check_prefork_num(int);
97 void advance_loc(void);
98 void advance_proxy(void);
99 void parsehp(char *, char **, const char **, const char *);
100 int fastcgi_conf(const char *, const char *);
101 void add_param(char *, char *);
102 int getservice(const char *);
103 void listen_on(const char *, const char *);
105 static struct vhost *host;
106 static struct location *loc;
107 static struct proxy *proxy;
108 static char *current_media;
119 #define YYSTYPE YYSTYPE
124 /* %define parse.error verbose */
126 %token ACCESS ALIAS AUTO
128 %token CA CERT CHROOT CLIENT
130 %token FACILITY FASTCGI FOR_HOST
131 %token INCLUDE INDEX IPV6
133 %token LANG LISTEN LOCATION LOG
135 %token PARAM PORT PREFORK PROTO PROTOCOLS PROXY
136 %token RELAY_TO REQUIRE RETURN ROOT
137 %token SERVER SNI SOCKET STRIP STYLE SYSLOG
138 %token TCP TOEXT TYPE TYPES
144 %token <v.string> STRING
145 %token <v.number> NUM
147 %type <v.number> bool proxy_port
148 %type <v.string> string numberstring listen_addr
158 | conf error nl { file->errors++; }
161 include : INCLUDE STRING {
164 if ((nfile = pushfile($2, 0)) == NULL) {
165 yyerror("failed to include file %s", $2);
176 bool : ON { $$ = 1; }
180 string : string STRING {
181 if (asprintf(&$$, "%s%s", $1, $2) == -1) {
184 yyerror("string: asprintf: %s", strerror(errno));
195 if (asprintf(&s, "%d", $1) == -1) {
196 yyerror("asprintf: number");
204 varset : STRING '=' string {
207 if (isspace((unsigned char)*s)) {
208 yyerror("macro name cannot contain "
221 option : CHROOT string {
222 if (strlcpy(conf->chroot, $2, sizeof(conf->chroot)) >=
223 sizeof(conf->chroot))
224 yyerror("chroot path too long");
228 yywarn("option `ipv6' is deprecated,"
229 " please use `listen on'");
233 default_host = "0.0.0.0";
237 yywarn("option `port' is deprecated,"
238 " please use `listen on'");
241 | PREFORK NUM { conf->prefork = check_prefork_num($2); }
243 if (tls_config_parse_protocols(&conf->protos, $2) == -1)
244 yyerror("invalid protocols string \"%s\"", $2);
248 if (strlcpy(conf->user, $2, sizeof(conf->user)) >=
250 yyerror("user name too long");
255 log : LOG '{' optnl logopts '}'
259 logopts : /* empty */
260 | logopts logopt optnl
263 logopt : ACCESS string {
264 free(conf->log_access);
265 conf->log_access = $2;
268 if (!strcmp("combined", $2))
269 conf->log_format = LOG_FORMAT_COMBINED;
270 else if (!strcmp("common", $2))
271 conf->log_format = LOG_FORMAT_COMMON;
272 else if (!strcmp("condensed", $2))
273 conf->log_format = LOG_FORMAT_CONDENSED;
274 else if (!strcmp("legacy", $2))
275 conf->log_format = LOG_FORMAT_LEGACY;
277 yyerror("unknown log style: %s", $2);
280 | SYSLOG FACILITY string {
281 const char *str = $3;
283 conf->log_syslog = 1;
285 if (!strncasecmp(str, "LOG_", 4))
288 if (!strcasecmp(str, "daemon"))
289 conf->log_facility = LOG_DAEMON;
291 else if (!strcasecmp(str, "ftp"))
292 conf->log_facility = LOG_FTP;
294 else if (!strcasecmp(str, "local1"))
295 conf->log_facility = LOG_LOCAL1;
296 else if (!strcasecmp(str, "local2"))
297 conf->log_facility = LOG_LOCAL2;
298 else if (!strcasecmp(str, "local3"))
299 conf->log_facility = LOG_LOCAL3;
300 else if (!strcasecmp(str, "local4"))
301 conf->log_facility = LOG_LOCAL4;
302 else if (!strcasecmp(str, "local5"))
303 conf->log_facility = LOG_LOCAL5;
304 else if (!strcasecmp(str, "local6"))
305 conf->log_facility = LOG_LOCAL6;
306 else if (!strcasecmp(str, "local7"))
307 conf->log_facility = LOG_LOCAL7;
308 else if (!strcasecmp(str, "user"))
309 conf->log_facility = LOG_USER;
311 yywarn("unknown syslog facility `%s'",
317 conf->log_syslog = 0;
320 conf->log_syslog = 1;
324 vhost : SERVER string {
326 TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
328 loc = new_location();
329 TAILQ_INSERT_HEAD(&host->locations, loc, locations);
331 TAILQ_INIT(&host->proxies);
333 (void) strlcpy(loc->match, "*", sizeof(loc->match));
334 (void) strlcpy(host->domain, $2, sizeof(host->domain));
336 if (strstr($2, "xn--") != NULL) {
337 yywarn("\"%s\" looks like punycode: you "
338 "should use the decoded hostname", $2);
342 } '{' optnl servbody '}' {
343 if (host->cert_path == NULL ||
344 host->key_path == NULL)
345 yyerror("invalid vhost definition: %s",
347 if (TAILQ_EMPTY(&host->addrs)) {
351 r = snprintf(portno, sizeof(portno), "%d",
353 if (r < 0 || (size_t)r >= sizeof(portno))
356 yywarn("missing `listen on' in server %s,"
357 " assuming %s port %d", host->domain,
358 default_host ? default_host : "*",
360 listen_on(default_host, portno);
363 | error '}' { yyerror("bad server directive"); }
366 servbody : /* empty */
367 | servbody servopt optnl
368 | servbody location optnl
369 | servbody proxy optnl
372 listen_addr : '*' { $$ = NULL; }
376 servopt : ALIAS string {
379 a = xcalloc(1, sizeof(*a));
380 (void) strlcpy(a->alias, $2, sizeof(a->alias));
382 TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
385 ensure_absolute_path($2);
386 free(host->cert_path);
387 host->cert_path = $2;
390 ensure_absolute_path($2);
391 free(host->key_path);
395 ensure_absolute_path($2);
396 free(host->ocsp_path);
397 host->ocsp_path = $2;
399 | PARAM string '=' string {
400 yywarn("the top-level `param' directive is deprecated."
401 " Please use `fastcgi { param ... }`");
404 | LISTEN ON listen_addr {
405 listen_on($3, "1965");
408 | LISTEN ON listen_addr PORT STRING {
413 | LISTEN ON listen_addr PORT NUM {
417 r = snprintf(portno, sizeof(portno), "%d", $5);
418 if (r < 0 || (size_t)r >= sizeof(portno))
421 listen_on($3, portno);
427 proxy : PROXY { advance_proxy(); }
428 proxy_matches '{' optnl proxy_opts '}' {
429 if (*proxy->host == '\0')
430 yyerror("invalid proxy block: missing `relay-to' option");
432 if ((proxy->cert_path == NULL && proxy->key_path != NULL) ||
433 (proxy->cert_path != NULL && proxy->key_path == NULL))
434 yyerror("invalid proxy block: missing cert or key");
438 proxy_matches : /* empty */
439 | proxy_matches proxy_match
442 proxy_port : /* empty */ { $$ = 1965; }
444 if (($$ = getservice($2)) == -1)
445 yyerror("invalid port number %s", $2);
448 | PORT NUM { $$ = $2; }
451 proxy_match : PROTO string {
452 (void) strlcpy(proxy->match_proto, $2, sizeof(proxy->match_proto));
455 | FOR_HOST string proxy_port {
456 (void) strlcpy(proxy->match_host, $2, sizeof(proxy->match_host));
457 (void) snprintf(proxy->match_port, sizeof(proxy->match_port),
463 proxy_opts : /* empty */
464 | proxy_opts proxy_opt optnl
467 proxy_opt : CERT string {
469 ensure_absolute_path($2);
470 proxy->cert_path = $2;
474 ensure_absolute_path($2);
475 proxy->key_path = $2;
478 if (tls_config_parse_protocols(&proxy->protocols, $2) == -1)
479 yyerror("invalid protocols string \"%s\"", $2);
482 | RELAY_TO string proxy_port {
483 (void) strlcpy(proxy->host, $2, sizeof(proxy->host));
484 (void) snprintf(proxy->port, sizeof(proxy->port),
488 | REQUIRE CLIENT CA string {
489 ensure_absolute_path($4);
490 proxy->reqca_path = $4;
493 (void) strlcpy(proxy->sni, $2, sizeof(proxy->sni));
500 proxy->noverifyname = !$2;
504 location : LOCATION { advance_loc(); } string '{' optnl locopts '}' {
505 /* drop the starting '/' if any */
507 memmove($3, $3+1, strlen($3));
508 (void) strlcpy(loc->match, $3, sizeof(loc->match));
514 locopts : /* empty */
515 | locopts locopt optnl
518 locopt : AUTO INDEX bool { loc->auto_index = $3 ? 1 : -1; }
519 | BLOCK RETURN NUM string {
521 (void) strlcpy(loc->block_fmt, $4, sizeof(loc->block_fmt));
522 loc->block_code = check_block_code($3);
526 (void) strlcpy(loc->block_fmt, "temporary failure",
527 sizeof(loc->block_fmt));
528 loc->block_code = check_block_code($3);
529 if ($3 >= 30 && $3 < 40)
530 yyerror("missing `meta' for block return %d", $3);
533 (void) strlcpy(loc->block_fmt, "temporary failure",
534 sizeof(loc->block_fmt));
535 loc->block_code = 40;
537 | DEFAULT TYPE string {
538 (void) strlcpy(loc->default_mime, $3,
539 sizeof(loc->default_mime));
544 (void) strlcpy(loc->index, $2, sizeof(loc->index));
548 (void) strlcpy(loc->lang, $2,
552 | LOG bool { loc->disable_log = !$2; }
553 | REQUIRE CLIENT CA string {
554 ensure_absolute_path($4);
555 loc->reqca_path = $4;
558 (void) strlcpy(loc->dir, $2, sizeof(loc->dir));
561 | STRIP NUM { loc->strip = check_strip_no($2); }
564 fastcgi : FASTCGI '{' optnl fastcgiopts '}'
571 yywarn("`fastcgi path' is deprecated. "
572 "Please use `fastcgi socket path' instead.");
573 loc->fcgi = fastcgi_conf($2, NULL);
578 fastcgiopts : /* empty */
579 | fastcgiopts fastcgiopt optnl
582 fastcgiopt : PARAM string '=' string {
586 loc->fcgi = fastcgi_conf($2, NULL);
589 | SOCKET TCP string PORT NUM {
592 if (asprintf(&c, "%d", $5) == -1)
594 loc->fcgi = fastcgi_conf($3, c);
598 | SOCKET TCP string {
599 loc->fcgi = fastcgi_conf($3, "9000");
601 | SOCKET TCP string PORT string {
602 loc->fcgi = fastcgi_conf($3, $5);
607 loc->fcgi_strip = $2;
611 types : TYPES '{' optnl mediaopts_l '}' ;
613 mediaopts_l : mediaopts_l mediaoptsl nl
617 mediaoptsl : STRING {
624 medianames_l : medianames_l medianamesl
628 medianamesl : numberstring {
629 if (add_mime(&conf->mime, current_media, $1) == -1)
645 static const struct keyword {
649 /* these MUST be sorted */
658 {"default", DEFAULT},
659 {"facility", FACILITY},
660 {"fastcgi", FASTCGI},
661 {"for-host", FOR_HOST},
662 {"include", INCLUDE},
668 {"location", LOCATION},
675 {"prefork", PREFORK},
677 {"protocols", PROTOCOLS},
679 {"relay-to", RELAY_TO},
680 {"require", REQUIRE},
693 {"use-tls", USE_TLS},
695 {"verifyname", VERIFYNAME},
699 yyerror(const char *msg, ...)
706 fprintf(stderr, "%s:%d error: ", config_path, yylval.lineno);
707 vfprintf(stderr, msg, ap);
708 fprintf(stderr, "\n");
713 yywarn(const char *msg, ...)
718 fprintf(stderr, "%s:%d warning: ", config_path, yylval.lineno);
719 vfprintf(stderr, msg, ap);
720 fprintf(stderr, "\n");
725 kw_cmp(const void *k, const void *e)
727 return strcmp(k, ((struct keyword *)e)->word);
733 const struct keyword *p;
735 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
736 sizeof(keywords[0]), kw_cmp);
744 #define START_EXPAND 1
745 #define DONE_EXPAND 2
747 static int expanding;
755 if (file->ungetpos > 0)
756 c = file->ungetbuf[--file->ungetpos];
758 c = getc(file->stream);
760 if (c == START_EXPAND)
762 else if (c == DONE_EXPAND)
776 if ((c = igetc()) == EOF) {
777 yyerror("reached end of file while parsing "
779 if (file == topfile || popfile() == EOF)
786 while ((c = igetc()) == '\\') {
792 yylval.lineno = file->lineno;
798 * Fake EOL when hit EOF for the first time. This gets line
799 * count right if last line in included file is syntactically
800 * invalid and has no newline.
802 if (file->eof_reached == 0) {
803 file->eof_reached = 1;
807 if (file == topfile || popfile() == EOF)
821 if (file->ungetpos >= file->ungetsize) {
822 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
826 file->ungetsize *= 2;
828 file->ungetbuf[file->ungetpos++] = c;
836 /* Skip to either EOF or the first real EOL. */
859 while ((c = lgetc(0)) == ' ' || c == '\t')
862 yylval.lineno = file->lineno;
864 while ((c = lgetc(0)) != '\n' && c != EOF)
866 if (c == '$' && !expanding) {
868 if ((c = lgetc(0)) == EOF)
870 if (p + 1 >= buf + sizeof(buf) -1) {
871 yyerror("string too long");
874 if (isalnum(c) || c == '_') {
884 yyerror("macro `%s' not defined", buf);
887 yylval.v.string = xstrdup(val);
890 if (c == '@' && !expanding) {
892 if ((c = lgetc(0)) == EOF)
895 if (p + 1 >= buf + sizeof(buf) - 1) {
896 yyerror("string too long");
899 if (isalnum(c) || c == '_') {
909 yyerror("macro '%s' not defined", buf);
912 p = val + strlen(val) - 1;
913 lungetc(DONE_EXPAND);
918 lungetc(START_EXPAND);
927 if ((c = lgetc(quotec)) == EOF)
932 } else if (c == '\\') {
933 if ((next = lgetc(quotec)) == EOF)
935 if (next == quotec || next == ' ' ||
938 else if (next == '\n') {
943 } else if (c == quotec) {
946 } else if (c == '\0') {
947 yyerror("invalid syntax");
950 if (p + 1 >= buf + sizeof(buf) - 1) {
951 yyerror("string too long");
956 yylval.v.string = strdup(buf);
957 if (yylval.v.string == NULL)
958 fatal("yylex: strdup");
962 #define allowed_to_end_number(x) \
963 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
965 if (c == '-' || isdigit(c)) {
968 if ((size_t)(p-buf) >= sizeof(buf)) {
969 yyerror("string too long");
972 } while ((c = lgetc(0)) != EOF && isdigit(c));
974 if (p == buf + 1 && buf[0] == '-')
976 if (c == EOF || allowed_to_end_number(c)) {
977 const char *errstr = NULL;
980 yylval.v.number = strtonum(buf, LLONG_MIN,
983 yyerror("\"%s\" invalid number: %s",
998 #define allowed_in_string(x) \
999 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
1000 x != '{' && x != '}' && \
1001 x != '!' && x != '=' && x != '#' && \
1002 x != ',' && x != ';'))
1004 if (isalnum(c) || c == ':' || c == '_') {
1007 if ((size_t)(p-buf) >= sizeof(buf)) {
1008 yyerror("string too long");
1011 } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
1014 if ((token = lookup(buf)) == STRING)
1015 yylval.v.string = xstrdup(buf);
1019 yylval.lineno = file->lineno;
1028 pushfile(const char *name, int secret)
1032 nfile = xcalloc(1, sizeof(*nfile));
1033 nfile->name = xstrdup(name);
1034 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
1035 log_warn("can't open %s", nfile->name);
1040 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
1041 nfile->ungetsize = 16;
1042 nfile->ungetbuf = xcalloc(1, nfile->ungetsize);
1043 TAILQ_INSERT_TAIL(&files, nfile, entry);
1052 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
1053 prev->errors += file->errors;
1055 TAILQ_REMOVE(&files, file, entry);
1056 fclose(file->stream);
1058 free(file->ungetbuf);
1061 return file ? 0 : EOF;
1065 parse_conf(struct conf *c, const char *filename)
1067 struct sym *sym, *next;
1069 default_host = NULL;
1070 default_port = 1965;
1074 file = pushfile(filename, 0);
1080 errors = file->errors;
1083 /* Free macros and check which have not been used. */
1084 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
1085 /* TODO: warn if !sym->used */
1086 if (!sym->persist) {
1089 TAILQ_REMOVE(&symhead, sym, entry);
1100 symset(const char *name, const char *val, int persist)
1104 TAILQ_FOREACH(sym, &symhead, entry) {
1105 if (!strcmp(name, sym->name))
1115 TAILQ_REMOVE(&symhead, sym, entry);
1120 sym = xcalloc(1, sizeof(*sym));
1121 sym->name = xstrdup(name);
1122 sym->val = xstrdup(val);
1124 sym->persist = persist;
1126 TAILQ_INSERT_TAIL(&symhead, sym, entry);
1131 cmdline_symset(char *s)
1136 if ((val = strrchr(s, '=')) == NULL)
1138 sym = xcalloc(1, val - s + 1);
1139 memcpy(sym, s, val - s);
1140 ret = symset(sym, val + 1, 1);
1146 symget(const char *nam)
1150 TAILQ_FOREACH(sym, &symhead, entry) {
1151 if (strcmp(nam, sym->name) == 0) {
1160 ensure_absolute_path(char *path)
1162 if (path == NULL || *path != '/')
1163 yyerror("not an absolute path: %s", path);
1168 check_block_code(int n)
1170 if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
1171 yyerror("invalid block code %d", n);
1176 check_block_fmt(char *fmt)
1180 for (s = fmt; *s; ++s) {
1191 yyerror("invalid format specifier %%%c", *s);
1199 check_strip_no(int n)
1202 yyerror("invalid strip number %d", n);
1207 check_port_num(int n)
1209 if (n <= 0 || n >= UINT16_MAX)
1210 yyerror("port number is %s: %d",
1211 n <= 0 ? "too small" : "too large",
1217 check_prefork_num(int n)
1219 if (n <= 0 || n >= PROC_MAX_INSTANCES)
1220 yyerror("invalid prefork number %d", n);
1227 loc = new_location();
1228 TAILQ_INSERT_TAIL(&host->locations, loc, locations);
1234 proxy = new_proxy();
1235 TAILQ_INSERT_TAIL(&host->proxies, proxy, proxies);
1239 parsehp(char *str, char **host, const char **port, const char *def)
1246 if ((at = strchr(str, ':')) != NULL) {
1252 strtonum(*port, 1, UINT16_MAX, &errstr);
1254 yyerror("port is %s: %s", errstr, *port);
1258 fastcgi_conf(const char *path, const char *port)
1263 TAILQ_FOREACH(f, &conf->fcgi, fcgi) {
1264 if (!strcmp(f->path, path) &&
1265 ((port == NULL && *f->port == '\0') ||
1266 !strcmp(f->port, port)))
1271 f = xcalloc(1, sizeof(*f));
1273 (void)strlcpy(f->path, path, sizeof(f->path));
1275 (void)strlcpy(f->port, port, sizeof(f->port));
1276 TAILQ_INSERT_TAIL(&conf->fcgi, f, fcgi);
1282 add_param(char *name, char *val)
1285 struct envhead *h = &loc->params;
1287 e = xcalloc(1, sizeof(*e));
1288 (void) strlcpy(e->name, name, sizeof(e->name));
1289 (void) strlcpy(e->value, val, sizeof(e->value));
1290 TAILQ_INSERT_TAIL(h, e, envs);
1294 getservice(const char *n)
1300 llval = strtonum(n, 0, UINT16_MAX, &errstr);
1302 s = getservbyname(n, "tcp");
1304 s = getservbyname(n, "udp");
1307 return (ntohs(s->s_port));
1310 return ((unsigned short)llval);
1314 add_to_addr_queue(struct addrhead *a, struct addrinfo *ai)
1316 struct address *addr;
1317 struct sockaddr_in *sin;
1318 struct sockaddr_in6 *sin6;
1320 if (ai->ai_addrlen > sizeof(addr->ss))
1321 fatalx("ai_addrlen larger than a sockaddr_storage");
1323 TAILQ_FOREACH(addr, a, addrs) {
1324 if (addr->ai_flags == ai->ai_flags &&
1325 addr->ai_family == ai->ai_family &&
1326 addr->ai_socktype == ai->ai_socktype &&
1327 addr->ai_protocol == ai->ai_protocol &&
1328 addr->slen == ai->ai_addrlen &&
1329 !memcmp(&addr->ss, ai->ai_addr, addr->slen))
1333 addr = xcalloc(1, sizeof(*addr));
1334 addr->ai_flags = ai->ai_flags;
1335 addr->ai_family = ai->ai_family;
1336 addr->ai_socktype = ai->ai_socktype;
1337 addr->ai_protocol = ai->ai_protocol;
1338 addr->slen = ai->ai_addrlen;
1339 memcpy(&addr->ss, ai->ai_addr, ai->ai_addrlen);
1342 switch (addr->ai_family) {
1344 sin = (struct sockaddr_in *)&addr->ss;
1345 addr->port = ntohs(sin->sin_port);
1348 sin6 = (struct sockaddr_in6 *)&addr->ss;
1349 addr->port = ntohs(sin6->sin6_port);
1352 fatalx("unknown socket family %d", addr->ai_family);
1357 TAILQ_INSERT_HEAD(a, addr, addrs);
1361 listen_on(const char *hostname, const char *servname)
1363 struct addrinfo hints, *res, *res0;
1366 memset(&hints, 0, sizeof(hints));
1367 hints.ai_family = AF_UNSPEC;
1368 hints.ai_socktype = SOCK_STREAM;
1369 hints.ai_flags = AI_PASSIVE;
1370 error = getaddrinfo(hostname, servname, &hints, &res0);
1372 yyerror("listen on \"%s\" port %s: %s", hostname, servname,
1373 gai_strerror(errno));
1377 for (res = res0; res; res = res->ai_next) {
1378 add_to_addr_queue(&host->addrs, res);
1379 add_to_addr_queue(&conf->addrs, res);