library/Native_Functions: add f_inet6_ntoa()

We have f_inet_ntoa() for converting IPv4 addresses to strings,
but so far there was no similar function for IPv6 addresses.

Change-Id: I0858cf8cb44a6673e19f3496c362d68fcdd7b18d
This commit is contained in:
Vadim Yanitskiy 2022-02-11 19:11:46 +06:00 committed by fixeria
parent 1e3bbbeac2
commit 04ef7d82ab
2 changed files with 15 additions and 0 deletions

View File

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

View File

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