Add Native_Functions module for inet_addr / inet_ntoa
This commit is contained in:
parent
ddeecbb4ed
commit
303c19ad63
|
@ -16,7 +16,7 @@ gen_links() {
|
|||
#gen_links $DIR $FILES
|
||||
|
||||
DIR=$BASEDIR/titan.Libraries.TCCUsefulFunctions/src
|
||||
FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCConversion.hh TCCInterface.cc TCCInterface_ip.h Native_Functions.ttcn Native_FunctionDefs.cc"
|
||||
FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCConversion.hh TCCInterface.cc TCCInterface_ip.h"
|
||||
gen_links $DIR $FILES
|
||||
|
||||
DIR=$BASEDIR/titan.TestPorts.Common_Components.Socket-API/src
|
||||
|
@ -40,5 +40,5 @@ FILES="GTPC_EncDec.cc GTPC_Types.ttcn GTPU_EncDec.cc GTPU_Types.ttcn"
|
|||
gen_links $DIR $FILES
|
||||
|
||||
DIR=../library
|
||||
FILES="General_Types.ttcn GSM_Types.ttcn Osmocom_Types.ttcn"
|
||||
FILES="General_Types.ttcn GSM_Types.ttcn Osmocom_Types.ttcn Native_Functions.ttcn Native_FunctionDefs.cc"
|
||||
gen_links $DIR $FILES
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/* Utility functions that I'm used to from C but for which I couldn't find TTCN-3 implementations
|
||||
*
|
||||
* (C) 2017 by Harald Welte <laforge@gnumonks.org>
|
||||
|
@ -22,4 +23,35 @@ OCTETSTRING f__inet__addr(const CHARSTRING& in)
|
|||
return OCTETSTRING(4, (const unsigned char *)&ia);
|
||||
}
|
||||
|
||||
OCTETSTRING f__inet__haddr(const CHARSTRING& in)
|
||||
{
|
||||
TTCN_Buffer ttcn_buffer(in);
|
||||
in_addr_t ia;
|
||||
|
||||
ia = inet_addr((const char *)ttcn_buffer.get_data());
|
||||
ia = ntohl(ia);
|
||||
|
||||
return OCTETSTRING(4, (const unsigned char *)&ia);
|
||||
}
|
||||
|
||||
CHARSTRING f__inet__ntoa(const OCTETSTRING& in)
|
||||
{
|
||||
TTCN_Buffer ttcn_buffer(in);
|
||||
const struct in_addr ia = *(const struct in_addr *)ttcn_buffer.get_data();
|
||||
const char *str = inet_ntoa(ia);
|
||||
|
||||
return CHARSTRING(str);
|
||||
}
|
||||
|
||||
CHARSTRING f__inet__hntoa(const OCTETSTRING& in)
|
||||
{
|
||||
TTCN_Buffer ttcn_buffer(in);
|
||||
struct in_addr ia = *(const in_addr *)ttcn_buffer.get_data();
|
||||
ia.s_addr = htonl(ia.s_addr);
|
||||
const char *str = inet_ntoa(ia);
|
||||
|
||||
return CHARSTRING(str);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
module Native_Functions {
|
||||
|
||||
/* 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 */
|
||||
external function f_inet_haddr(in charstring ch) return octetstring;
|
||||
|
||||
/* direct import of inet_ntoa() C function, input net byte order */
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue