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 3/6] NETROM: Add netrom_ntop implementation.
Date: Sat, 13 Apr 2019 18:17:36 +0200	[thread overview]
Message-ID: <e6060adc15ab772814303260f8591dbf730fcfc3.1627295848.git.ralf@linux-mips.org> (raw)
In-Reply-To: <cover.1627295848.git.ralf@linux-mips.org>

NETROM uses AX.25 addresses so this is a simple wrapper around ax25_ntop1.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
---
 Makefile          |  3 +++
 include/utils.h   |  2 ++
 lib/ax25_ntop.c   | 22 +++++++++++++++-------
 lib/netrom_ntop.c | 23 +++++++++++++++++++++++
 4 files changed, 43 insertions(+), 7 deletions(-)
 create mode 100644 lib/netrom_ntop.c

diff --git a/Makefile b/Makefile
index 551f528b..df894d54 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,9 @@ ADDLIB+=ax25_ntop.o
 #options for mpls
 ADDLIB+=mpls_ntop.o mpls_pton.o
 
+#options for NETROM
+ADDLIB+=netrom_ntop.o
+
 CC := gcc
 HOSTCC ?= $(CC)
 DEFINES += -D_GNU_SOURCE
diff --git a/include/utils.h b/include/utils.h
index 31c1e442..c685a392 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -214,6 +214,8 @@ const char *ax25_ntop(int af, const void *addr, char *str, socklen_t len);
 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);
 
+const char *netrom_ntop(int af, const void *addr, char *str, socklen_t len);
+
 extern int __iproute2_hz_internal;
 int __get_hz(void);
 
diff --git a/lib/ax25_ntop.c b/lib/ax25_ntop.c
index 48098581..cfd0e04b 100644
--- a/lib/ax25_ntop.c
+++ b/lib/ax25_ntop.c
@@ -6,13 +6,22 @@
 
 #include "utils.h"
 
+const char *ax25_ntop1(const ax25_address *src, char *dst, socklen_t size);
+
 /*
  * AX.25 addresses are based on Amateur radio callsigns followed by an SSID
- * like XXXXXX-SS where the callsign is up to 6 characters which are either
- * letters or digits and the SSID is a decimal number in the range 0..15.
+ * like XXXXXX-SS where the callsign consists of up to 6 ASCII characters
+ * which are either letters or digits and the SSID is a decimal number in the
+ * range 0..15.
  * Amateur radio callsigns are assigned by a country's relevant authorities
  * and are 3..6 characters though a few countries have assigned callsigns
  * longer than that.  AX.25 is not able to handle such longer callsigns.
+ * There are further restrictions on the format of valid callsigns by
+ * applicable national and international law.  Linux doesn't need to care and
+ * will happily accept anything that consists of 6 ASCII characters in the
+ * range of A-Z and 0-9 for a callsign such as the default AX.25 MAC address
+ * LINUX-1 and the default broadcast address QST-0.
+ * The SSID is just a number and not encoded in ASCII digits.
  *
  * Being based on HDLC AX.25 encodes addresses by shifting them one bit left
  * thus zeroing bit 0, the HDLC extension bit for all but the last bit of
@@ -22,14 +31,13 @@
  * Linux' internal representation of AX.25 addresses in Linux is very similar
  * to this on the on-air or on-the-wire format.  The callsign is padded to
  * 6 octets by adding spaces, followed by the SSID octet then all 7 octets
- * are left-shifted by one byte.
+ * are left-shifted by one bit.
  *
- * This for example turns "LINUX-1" where the callsign is LINUX and SSID is 1
- * into 98:92:9c:aa:b0:40:02.
+ * For example, for the address "LINUX-1" the callsign is LINUX and SSID is 1
+ * the internal format is 98:92:9c:aa:b0:40:02.
  */
 
-static const char *ax25_ntop1(const ax25_address *src, char *dst,
-			      socklen_t size)
+const char *ax25_ntop1(const ax25_address *src, char *dst, socklen_t size)
 {
 	char c, *s;
 	int n;
diff --git a/lib/netrom_ntop.c b/lib/netrom_ntop.c
new file mode 100644
index 00000000..3dd6cb0b
--- /dev/null
+++ b/lib/netrom_ntop.c
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <sys/socket.h>
+#include <errno.h>
+#include <linux/ax25.h>
+
+#include "utils.h"
+
+const char *ax25_ntop1(const ax25_address *src, char *dst, socklen_t size);
+
+const char *netrom_ntop(int af, const void *addr, char *buf, socklen_t buflen)
+{
+	switch (af) {
+	case AF_NETROM:
+		errno = 0;
+		return ax25_ntop1((ax25_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 ` [PATCH 5/6] ROSE: Add rose_ntop implementation Ralf Baechle
2019-04-13 16:17 ` Ralf Baechle [this message]

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=e6060adc15ab772814303260f8591dbf730fcfc3.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.