summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/host.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils/host.c')
-rw-r--r--src/libstrongswan/utils/host.c67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/libstrongswan/utils/host.c b/src/libstrongswan/utils/host.c
index 719c5a529..a40c42c49 100644
--- a/src/libstrongswan/utils/host.c
+++ b/src/libstrongswan/utils/host.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2007 Tobias Brunner
+ * Copyright (C) 2006-2009 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
@@ -15,13 +15,12 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: host.c 4856 2009-02-05 22:13:48Z andreas $
+ * $Id: host.c 4977 2009-03-19 09:16:03Z martin $
*/
#define _GNU_SOURCE
#include <netdb.h>
#include <string.h>
-#include <printf.h>
#include "host.h"
@@ -106,10 +105,10 @@ static bool is_anyaddr(private_host_t *this)
}
/**
- * output handler in printf()
+ * Described in header.
*/
-static int print(FILE *stream, const struct printf_info *info,
- const void *const *args)
+int host_printf_hook(char *dst, size_t dstlen, printf_hook_spec_t *spec,
+ const void *const *args)
{
private_host_t *this = *((private_host_t**)(args[0]));
char buffer[INET6_ADDRSTRLEN + 16];
@@ -120,7 +119,8 @@ static int print(FILE *stream, const struct printf_info *info,
}
else if (is_anyaddr(this))
{
- snprintf(buffer, sizeof(buffer), "%%any");
+ snprintf(buffer, sizeof(buffer), "%%any%s",
+ this->address.sa_family == AF_INET6 ? "6" : "");
}
else
{
@@ -145,7 +145,7 @@ static int print(FILE *stream, const struct printf_info *info,
snprintf(buffer, sizeof(buffer),
"(address conversion failed)");
}
- else if (info->alt)
+ else if (spec->hash)
{
len = strlen(buffer);
snprintf(buffer + len, sizeof(buffer) - len,
@@ -157,34 +157,11 @@ static int print(FILE *stream, const struct printf_info *info,
break;
}
}
- if (info->left)
+ if (spec->minus)
{
- return fprintf(stream, "%-*s", info->width, buffer);
+ return print_in_hook(dst, dstlen, "%-*s", spec->width, buffer);
}
- return fprintf(stream, "%*s", info->width, buffer);
-}
-
-
-/**
- * arginfo handler for printf() hosts
- */
-int arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (n > 0)
- {
- argtypes[0] = PA_POINTER;
- }
- return 1;
-}
-
-/**
- * return printf hook functions for a host
- */
-printf_hook_functions_t host_get_printf_hooks()
-{
- printf_hook_functions_t hooks = {print, arginfo};
-
- return hooks;
+ return print_in_hook(dst, dstlen, "%*s", spec->width, buffer);
}
/**
@@ -388,6 +365,18 @@ static private_host_t *host_create_empty(void)
}
/*
+ * Create a %any host with port
+ */
+static host_t *host_create_any_port(int family, u_int16_t port)
+{
+ host_t *this;
+
+ this = host_create_any(family);
+ this->set_port(this, port);
+ return this;
+}
+
+/*
* Described in header.
*/
host_t *host_create_from_string(char *string, u_int16_t port)
@@ -396,7 +385,11 @@ host_t *host_create_from_string(char *string, u_int16_t port)
if (streq(string, "%any"))
{
- return host_create_any(AF_INET);
+ return host_create_any_port(AF_INET, port);
+ }
+ if (streq(string, "%any6"))
+ {
+ return host_create_any_port(AF_INET6, port);
}
this = host_create_empty();
@@ -451,11 +444,11 @@ host_t *host_create_from_dns(char *string, int af, u_int16_t port)
if (streq(string, "%any"))
{
- return host_create_any(af ? af : AF_INET);
+ return host_create_any_port(af ? af : AF_INET, port);
}
if (streq(string, "%any6"))
{
- return host_create_any(af ? af : AF_INET6);
+ return host_create_any_port(af ? af : AF_INET6, port);
}
else if (strchr(string, ':'))
{