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 6ab2fa74..b6c468e9 100644 --- a/include/utils.h +++ b/include/utils.h @@ -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 index 00000000..c9ba712c --- /dev/null +++ b/lib/rose_ntop.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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; +}