summaryrefslogtreecommitdiffstats
path: root/lib/rose_ntop.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 14:18:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 14:18:53 +0000
commita0e0018c9a7ef5ce7f6d2c3ae16aecbbd16a8f67 (patch)
tree8feaf1a1932871b139b3b30be4c09c66489918be /lib/rose_ntop.c
parentInitial commit. (diff)
downloadiproute2-a0e0018c9a7ef5ce7f6d2c3ae16aecbbd16a8f67.tar.xz
iproute2-a0e0018c9a7ef5ce7f6d2c3ae16aecbbd16a8f67.zip
Adding upstream version 6.1.0.upstream/6.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--lib/rose_ntop.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/rose_ntop.c b/lib/rose_ntop.c
new file mode 100644
index 0000000..c9ba712
--- /dev/null
+++ b/lib/rose_ntop.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <string.h>
+#include <errno.h>
+
+#include <linux/netdevice.h>
+#include <linux/if_arp.h>
+#include <linux/sockios.h>
+#include <linux/rose.h>
+
+#include "rt_names.h"
+#include "utils.h"
+
+static const char *rose_ntop1(const rose_address *src, char *dst,
+ socklen_t size)
+{
+ char *p = dst;
+ int i;
+
+ if (size < 10)
+ return NULL;
+
+ for (i = 0; i < 5; i++) {
+ *p++ = '0' + ((src->rose_addr[i] >> 4) & 0xf);
+ *p++ = '0' + ((src->rose_addr[i] ) & 0xf);
+ }
+
+ if (size == 10)
+ return dst;
+
+ *p = '\0';
+
+ return dst;
+}
+
+const char *rose_ntop(int af, const void *addr, char *buf, socklen_t buflen)
+{
+ switch (af) {
+ case AF_ROSE:
+ errno = 0;
+ return rose_ntop1((rose_address *)addr, buf, buflen);
+
+ default:
+ errno = EAFNOSUPPORT;
+ }
+
+ return NULL;
+}