diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-27 19:01:31 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-27 19:01:31 +0200 |
commit | 21e4ada4bb0321250702c3af32d10f6a1bc65931 (patch) | |
tree | 65d55e026a0a682f2c789968b20657940db1e0f7 /src/printf.c | |
parent | cfadfce5484418ed88d235df8d82c14ebfe70d4c (diff) | |
download | fastd-21e4ada4bb0321250702c3af32d10f6a1bc65931.tar fastd-21e4ada4bb0321250702c3af32d10f6a1bc65931.zip |
Use configured peer names
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/printf.c b/src/printf.c index bef598c..15ca844 100644 --- a/src/printf.c +++ b/src/printf.c @@ -26,10 +26,40 @@ #include "fastd.h" +#include "peer.h" #include <arpa/inet.h> +static void print_default_peer_str(const fastd_context *ctx, const fastd_peer *peer) { + char addr_buf[INET6_ADDRSTRLEN] = ""; + char pl = '<', pr = '>'; + + if (fastd_peer_is_temporary(peer)) { + pl = '{'; + pr = '}'; + } + + switch (peer->address.sa.sa_family) { + case AF_UNSPEC: + fprintf(stderr, "%cfloating%c", pl, pr); + return; + + case AF_INET: + if (inet_ntop(AF_INET, &peer->address.in.sin_addr, addr_buf, sizeof(addr_buf))) + fprintf(stderr, "%c%s:%u%c", pl, addr_buf, ntohs(peer->address.in.sin_port), pr); + return; + + case AF_INET6: + if (inet_ntop(AF_INET6, &peer->address.in6.sin6_addr, addr_buf, sizeof(addr_buf))) + fprintf(stderr, "%c[%s]:%u%c", pl, addr_buf, ntohs(peer->address.in6.sin6_port), pr); + break; + + default: + exit_bug(ctx, "unsupported address family"); + } +} + #pragma GCC diagnostic ignored "-Wformat-security" void fastd_printf(const fastd_context *ctx, const char *format, ...) { @@ -51,6 +81,7 @@ void fastd_printf(const fastd_context *ctx, const char *format, ...) { bool finished = true; char addr_buf[INET6_ADDRSTRLEN]; void *p; + fastd_peer *peer; fastd_eth_addr *eth_addr; switch (str[len]) { @@ -180,12 +211,13 @@ void fastd_printf(const fastd_context *ctx, const char *format, ...) { break; case 'P': - p = va_arg(ap, void*); + peer = va_arg(ap, void*); - if (p) { - char* str = ctx->conf->protocol->peer_str(ctx, (fastd_peer*)p); - fprintf(stderr, "%s", str); - free(str); + if (peer) { + if (peer->config && peer->config->name) + fprintf(stderr, "%s", peer->config->name); + else + print_default_peer_str(ctx, peer); } else { fprintf(stderr, "(null)"); |