[PATCH] osmo-ttcn3-hacks[master]: library: Implement f_inet6_addr function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Jan 29 14:19:39 UTC 2018


Review at  https://gerrit.osmocom.org/6156

library: Implement f_inet6_addr function

It can be used to parse IPv6 functions, since inet_addr supports IPv4
only.

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


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

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 */

-- 
To view, visit https://gerrit.osmocom.org/6156
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb6dd38462501895d1b4409a3c530793917bd803
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list