From 6ada3f4364395fac6c9a64e73492d8826a000127 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 7 Mar 2012 23:17:50 +0100 Subject: New debug print function --- src/method_null.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/method_null.c') diff --git a/src/method_null.c b/src/method_null.c index 6ed7144..8c144e8 100644 --- a/src/method_null.c +++ b/src/method_null.c @@ -24,10 +24,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include "fastd.h" #include "task.h" #include "peer.h" +#include + + static bool null_check_config(fastd_context *ctx, const fastd_config *conf) { if (conf->n_floating > 1) { @@ -42,6 +47,35 @@ static size_t null_max_packet_size(fastd_context *ctx) { return fastd_max_packet_size(ctx); } +static char* null_peer_str(const fastd_context *ctx, const fastd_peer *peer) { + char addr_buf[INET6_ADDRSTRLEN] = ""; + char *ret; + + switch (peer->address.sa.sa_family) { + case AF_UNSPEC: + return strdup(""); + + case AF_INET: + if (inet_ntop(AF_INET, &peer->address.in.sin_addr, addr_buf, sizeof(addr_buf))) { + if (asprintf(&ret, "%s:%u", addr_buf, ntohs(peer->address.in.sin_port)) > 0) + return ret; + } + break; + + case AF_INET6: + if (inet_ntop(AF_INET6, &peer->address.in6.sin6_addr, addr_buf, sizeof(addr_buf))) { + if (asprintf(&ret, "[%s]:%u", addr_buf, ntohs(peer->address.in6.sin6_port)) > 0) + return ret; + } + break; + + default: + exit_bug(ctx, "unsupported address family"); + } + + return NULL; +} + static void null_init(fastd_context *ctx, fastd_peer *peer) { fastd_task_put_send(ctx, peer, fastd_buffer_alloc(0, 0, 0)); } @@ -85,6 +119,8 @@ const fastd_method fastd_method_null = { .max_packet_size = null_max_packet_size, + .peer_str = null_peer_str, + .init = null_init, .handle_recv = null_handle_recv, .send = null_send, -- cgit v1.2.3