diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.71 2009/02/21 19:32:04 tobias Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.75 2010/01/09 23:04:13 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -560,11 +560,11 @@ char * | |||
560 | percent_expand(const char *string, ...) | 560 | percent_expand(const char *string, ...) |
561 | { | 561 | { |
562 | #define EXPAND_MAX_KEYS 16 | 562 | #define EXPAND_MAX_KEYS 16 |
563 | u_int num_keys, i, j; | ||
563 | struct { | 564 | struct { |
564 | const char *key; | 565 | const char *key; |
565 | const char *repl; | 566 | const char *repl; |
566 | } keys[EXPAND_MAX_KEYS]; | 567 | } keys[EXPAND_MAX_KEYS]; |
567 | u_int num_keys, i, j; | ||
568 | char buf[4096]; | 568 | char buf[4096]; |
569 | va_list ap; | 569 | va_list ap; |
570 | 570 | ||
@@ -576,13 +576,12 @@ percent_expand(const char *string, ...) | |||
576 | break; | 576 | break; |
577 | keys[num_keys].repl = va_arg(ap, char *); | 577 | keys[num_keys].repl = va_arg(ap, char *); |
578 | if (keys[num_keys].repl == NULL) | 578 | if (keys[num_keys].repl == NULL) |
579 | fatal("percent_expand: NULL replacement"); | 579 | fatal("%s: NULL replacement", __func__); |
580 | } | 580 | } |
581 | if (num_keys == EXPAND_MAX_KEYS && va_arg(ap, char *) != NULL) | ||
582 | fatal("%s: too many keys", __func__); | ||
581 | va_end(ap); | 583 | va_end(ap); |
582 | 584 | ||
583 | if (num_keys >= EXPAND_MAX_KEYS) | ||
584 | fatal("percent_expand: too many keys"); | ||
585 | |||
586 | /* Expand string */ | 585 | /* Expand string */ |
587 | *buf = '\0'; | 586 | *buf = '\0'; |
588 | for (i = 0; *string != '\0'; string++) { | 587 | for (i = 0; *string != '\0'; string++) { |
@@ -590,23 +589,24 @@ percent_expand(const char *string, ...) | |||
590 | append: | 589 | append: |
591 | buf[i++] = *string; | 590 | buf[i++] = *string; |
592 | if (i >= sizeof(buf)) | 591 | if (i >= sizeof(buf)) |
593 | fatal("percent_expand: string too long"); | 592 | fatal("%s: string too long", __func__); |
594 | buf[i] = '\0'; | 593 | buf[i] = '\0'; |
595 | continue; | 594 | continue; |
596 | } | 595 | } |
597 | string++; | 596 | string++; |
597 | /* %% case */ | ||
598 | if (*string == '%') | 598 | if (*string == '%') |
599 | goto append; | 599 | goto append; |
600 | for (j = 0; j < num_keys; j++) { | 600 | for (j = 0; j < num_keys; j++) { |
601 | if (strchr(keys[j].key, *string) != NULL) { | 601 | if (strchr(keys[j].key, *string) != NULL) { |
602 | i = strlcat(buf, keys[j].repl, sizeof(buf)); | 602 | i = strlcat(buf, keys[j].repl, sizeof(buf)); |
603 | if (i >= sizeof(buf)) | 603 | if (i >= sizeof(buf)) |
604 | fatal("percent_expand: string too long"); | 604 | fatal("%s: string too long", __func__); |
605 | break; | 605 | break; |
606 | } | 606 | } |
607 | } | 607 | } |
608 | if (j >= num_keys) | 608 | if (j >= num_keys) |
609 | fatal("percent_expand: unknown key %%%c", *string); | 609 | fatal("%s: unknown key %%%c", __func__, *string); |
610 | } | 610 | } |
611 | return (xstrdup(buf)); | 611 | return (xstrdup(buf)); |
612 | #undef EXPAND_MAX_KEYS | 612 | #undef EXPAND_MAX_KEYS |
@@ -849,3 +849,14 @@ ms_to_timeval(struct timeval *tv, int ms) | |||
849 | tv->tv_usec = (ms % 1000) * 1000; | 849 | tv->tv_usec = (ms % 1000) * 1000; |
850 | } | 850 | } |
851 | 851 | ||
852 | void | ||
853 | sock_set_v6only(int s) | ||
854 | { | ||
855 | #ifdef IPV6_V6ONLY | ||
856 | int on = 1; | ||
857 | |||
858 | debug3("%s: set socket %d IPV6_V6ONLY", __func__, s); | ||
859 | if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) | ||
860 | error("setsockopt IPV6_V6ONLY: %s", strerror(errno)); | ||
861 | #endif | ||
862 | } | ||