fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/27146 )


Change subject: library/Native_Functions: add f_inet6_ntoa()
......................................................................

library/Native_Functions: add f_inet6_ntoa()

We have f_inet_ntoa() for converting IPv4 addresses to strings,
but so far there was no similar function for IPv6 addresses.

Change-Id: I0858cf8cb44a6673e19f3496c362d68fcdd7b18d
---
M library/Native_FunctionDefs.cc
M library/Native_Functions.ttcn
2 files changed, 15 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/46/27146/1

diff --git a/library/Native_FunctionDefs.cc b/library/Native_FunctionDefs.cc
index 78ca4d1..7139a62 100644
--- a/library/Native_FunctionDefs.cc
+++ b/library/Native_FunctionDefs.cc
@@ -76,6 +76,19 @@
        return CHARSTRING(str);
 }

+CHARSTRING f__inet6__ntoa(const OCTETSTRING& in)
+{
+       char buf[INET6_ADDRSTRLEN] = { 0 };
+       TTCN_Buffer ttcn_buffer(in);
+
+       const void *src = (const void *)ttcn_buffer.get_data();
+       const char *str = inet_ntop(AF_INET6, src, buf, sizeof(buf));
+       if (str == NULL)
+               fprintf(stderr, "inet_ntop failed: %s\n", strerror(errno));
+
+       return CHARSTRING((const char *)buf);
+}
+
 CHARSTRING f__str__tolower(const CHARSTRING& in)
 {
        TTCN_Buffer ttcn_buffer(in);
diff --git a/library/Native_Functions.ttcn b/library/Native_Functions.ttcn
index c43004a..c9cc948 100644
--- a/library/Native_Functions.ttcn
+++ b/library/Native_Functions.ttcn
@@ -11,6 +11,8 @@
        external function f_inet_ntoa(in octetstring oct) return charstring;
        /* like inet_ntoa() but input is host byte order */
        external function f_inet_hntoa(in octetstring oct) return charstring;
+       /* direct import of inet_ntop(AF_INET6) C function, input net byte 
order */
+       external function f_inet6_ntoa(in octetstring oct) return charstring;

        /* convert content of charstring to lower-case using tolower(3) */
        external function f_str_tolower(in charstring input) return charstring;

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/27146
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I0858cf8cb44a6673e19f3496c362d68fcdd7b18d
Gerrit-Change-Number: 27146
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange

Reply via email to