diff --git a/library/Native_FunctionDefs.cc b/library/Native_FunctionDefs.cc index 78ca4d1fe..7139a6240 100644 --- a/library/Native_FunctionDefs.cc +++ b/library/Native_FunctionDefs.cc @@ -76,6 +76,19 @@ CHARSTRING f__inet__hntoa(const OCTETSTRING& in) 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 c43004a9b..c9cc94866 100644 --- a/library/Native_Functions.ttcn +++ b/library/Native_Functions.ttcn @@ -11,6 +11,8 @@ module Native_Functions { 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;