]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ROSE: Add rose_ntop implementation.
authorRalf Baechle <ralf@linux-mips.org>
Sun, 19 Sep 2021 13:30:26 +0000 (15:30 +0200)
committerDavid Ahern <dsahern@kernel.org>
Fri, 24 Sep 2021 02:02:45 +0000 (20:02 -0600)
ROSE addresses are ten digit numbers, basically like North American
telephone numbers.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
Makefile
include/utils.h
lib/rose_ntop.c [new file with mode: 0644]

index df894d549fb1cc5b11f6517cfe1611d13ca392f2..5eddd5049919f21d149b6fce7f818fe508eab0f0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,9 @@ DEFINES+=-DCONFDIR=\"$(CONFDIR)\" \
 #options for AX.25
 ADDLIB+=ax25_ntop.o
 
+#options for AX.25
+ADDLIB+=rose_ntop.o
+
 #options for mpls
 ADDLIB+=mpls_ntop.o mpls_pton.o
 
index 6ab2fa74147c0bb2438fbd44490923c88187400b..b6c468e9cc862f13e80d2e8cf706a72788316529 100644 (file)
@@ -200,6 +200,8 @@ int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta);
 
 const char *ax25_ntop(int af, const void *addr, char *str, socklen_t len);
 
+const char *rose_ntop(int af, const void *addr, char *buf, socklen_t buflen);
+
 const char *mpls_ntop(int af, const void *addr, char *str, size_t len);
 int mpls_pton(int af, const char *src, void *addr, size_t alen);
 
diff --git a/lib/rose_ntop.c b/lib/rose_ntop.c
new file mode 100644 (file)
index 0000000..c9ba712
--- /dev/null
@@ -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;
+}