library: Implement f_inet6_addr function
It can be used to parse IPv6 functions, since inet_addr supports IPv4
only.
Change-Id: Icb6dd38462501895d1b4409a3c530793917bd803
diff --git a/library/Native_FunctionDefs.cc b/library/Native_FunctionDefs.cc
index 5dda08c..8aa31b4 100644
--- a/library/Native_FunctionDefs.cc
+++ b/library/Native_FunctionDefs.cc
@@ -7,12 +7,28 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
#include <Charstring.hh>
#include <Octetstring.hh>
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 31bc767..d59670a 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 */