library: Implement f_inet6_addr function

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

Change-Id: Icb6dd38462501895d1b4409a3c530793917bd803
This commit is contained in:
Pau Espin 2018-01-29 15:18:17 +01:00
parent f69a438010
commit aea381feca
2 changed files with 18 additions and 0 deletions

View File

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

View File

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