summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Buehler <account@buehler.rocks>2020-03-31 14:52:34 +0200
committerFelix Buehler <account@buehler.rocks>2020-03-31 15:03:18 +0200
commitebaeb8fb2340ace64565a8e56c9ab9010e8dd6d9 (patch)
tree8502a13224ed0b01140cebb96ee16cb1c5786cfa /src
parent101215bbc83b97de30b6b535bbe2e93d2e913804 (diff)
use format_placeholder for ipv6_addr
Diffstat (limited to 'src')
-rw-r--r--src/print_ipv6_addr.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/print_ipv6_addr.c b/src/print_ipv6_addr.c
index 5a0c38d..8fd8669 100644
--- a/src/print_ipv6_addr.c
+++ b/src/print_ipv6_addr.c
@@ -118,7 +118,6 @@ static char *get_ipv6_addr(void) {
}
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down) {
- const char *walk;
char *addr_string = get_ipv6_addr();
char *outwalk = buffer;
@@ -131,18 +130,13 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
}
START_COLOR("color_good");
- for (walk = format_up; *walk != '\0'; walk++) {
- if (*walk != '%') {
- *(outwalk++) = *walk;
- } else if (BEGINS_WITH(walk + 1, "ip")) {
- outwalk += sprintf(outwalk, "%s", addr_string);
- walk += strlen("ip");
+ placeholder_t placeholders[] = {
+ {.name = "%ip", .value = addr_string}};
- } else {
- *(outwalk++) = '%';
- }
- }
+ const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
+ buffer = format_placeholders(format_up, &placeholders[0], num);
END_COLOR;
OUTPUT_FULL_TEXT(buffer);
+ free(buffer);
}