All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org
Subject: [PATCH 5/6] ROSE: Add rose_ntop implementation.
Date: Fri, 12 Apr 2019 14:27:07 +0200	[thread overview]
Message-ID: <d6830e69587964150cb51fe54f5a1d8459373ff5.1627295848.git.ralf@linux-mips.org> (raw)
In-Reply-To: <cover.1627295848.git.ralf@linux-mips.org>

ROSE addresses are ten digit numbers, basically like North American
telephone numbers.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
---
 Makefile        |  3 +++
 include/utils.h |  2 ++
 lib/rose_ntop.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 lib/rose_ntop.c

diff --git a/Makefile b/Makefile
index df894d54..5eddd504 100644
--- 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
 
diff --git a/include/utils.h b/include/utils.h
index c685a392..ba981186 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -211,6 +211,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
index 00000000..c9ba712c
--- /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;
+}
-- 
2.31.1



  parent reply	other threads:[~2021-07-26 19:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1627295848.git.ralf@linux-mips.org>
2017-01-18 21:34 ` [PATCH 6/6] ROSE: Print decoded addresses rather than hex numbers Ralf Baechle
2017-01-18 22:08 ` [PATCH 1/6] AX.25: Add ax25_ntop implementation Ralf Baechle
2017-01-18 22:08 ` [PATCH 2/6] AX.25: Print decoded addresses rather than hex numbers Ralf Baechle
2017-01-18 22:19 ` [PATCH 4/6] NETROM: " Ralf Baechle
2019-04-12 12:27 ` Ralf Baechle [this message]
2019-04-13 16:17 ` [PATCH 3/6] NETROM: Add netrom_ntop implementation Ralf Baechle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d6830e69587964150cb51fe54f5a1d8459373ff5.1627295848.git.ralf@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.