summaryrefslogtreecommitdiffstats
path: root/src/method_null.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/method_null.c')
-rw-r--r--src/method_null.c36
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,