diff --git a/library/Native_FunctionDefs.cc b/library/Native_FunctionDefs.cc index 5dda08ce9..8aa31b445 100644 --- a/library/Native_FunctionDefs.cc +++ b/library/Native_FunctionDefs.cc @@ -7,12 +7,28 @@ #include #include #include +#include +#include +#include #include #include namespace Native__Functions { +OCTETSTRING f__inet6__addr(const CHARSTRING& in) +{ + char buf[INET6_ADDRSTRLEN]; + TTCN_Buffer ttcn_buffer(in); + int ret; + + ret = inet_pton(AF_INET6, (const char *)ttcn_buffer.get_data(), buf); + if(ret < 1) + fprintf(stderr, "inet_pton failed: %d %s\n", ret, strerror(errno)); + + return OCTETSTRING(16, (const unsigned char *)&buf[0]); +} + OCTETSTRING f__inet__addr(const CHARSTRING& in) { TTCN_Buffer ttcn_buffer(in); diff --git a/library/Native_Functions.ttcn b/library/Native_Functions.ttcn index 31bc767dc..d59670a0e 100644 --- a/library/Native_Functions.ttcn +++ b/library/Native_Functions.ttcn @@ -1,5 +1,7 @@ module Native_Functions { + /* direct import of inet_pton(AF_INET6) C function, returns net byte order */ + external function f_inet6_addr(in charstring ch) return octetstring; /* direct import of inet_addr() C function, returns net byte order */ external function f_inet_addr(in charstring ch) return octetstring; /* like inet_addr() but return is host byte order */