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
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);