diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-07 23:17:50 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-07 23:17:50 +0100 |
commit | 6ada3f4364395fac6c9a64e73492d8826a000127 (patch) | |
tree | 0bd6b80ade74973bf8568b5ae15f78aa74b7d7da /src/method_null.c | |
parent | c6e6c751546124134ed0087bd30a1905a8d4a99d (diff) | |
download | fastd-6ada3f4364395fac6c9a64e73492d8826a000127.tar fastd-6ada3f4364395fac6c9a64e73492d8826a000127.zip |
New debug print function
Diffstat (limited to 'src/method_null.c')
-rw-r--r-- | src/method_null.c | 36 |
1 files changed, 36 insertions, 0 deletions
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 <arpa/inet.h> + + 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("<floating>"); + + 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, |