From: Michael Wallner Date: Wed, 8 Feb 2017 15:00:49 +0000 (+0100) Subject: posix: arpa_inet X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5b17e760a71eaa07bc91e0bc0b463f2ecfec245a;p=m6w6%2Fext-psi posix: arpa_inet --- diff --git a/config.m4 b/config.m4 index b4107c8..3ced949 100644 --- a/config.m4 +++ b/config.m4 @@ -16,6 +16,7 @@ m4_foreach(incfile, [ [psi/psi_decl.m4], [psi/psi_macro.m4], [psi/psi_composite.m4], + [posix/arpa_inet.m4], [posix/errno.m4], [posix/fcntl.m4], [posix/glob.m4], @@ -126,7 +127,9 @@ if test "$PHP_PSI" != no; then PSI_CONFIG_POSIX(stdlib, stdlib.h) PSI_CONFIG_POSIX(unistd, unistd.h) PSI_CONFIG_POSIX(sys/socket, sys/socket.h, [ - PSI_CONFIG_POSIX(netinet/in, netinet/in.h) + PSI_CONFIG_POSIX(netinet/in, netinet/in.h, [ + PSI_CONFIG_POSIX(arpa/inet, arpa/inet.h) + ]) PSI_CONFIG_POSIX(netdb, netdb.h) ]) PSI_CONFIG_POSIX(netinet/tcp, netinet/tcp.h) diff --git a/m4/posix/arpa_inet.m4 b/m4/posix/arpa_inet.m4 new file mode 100644 index 0000000..6473607 --- /dev/null +++ b/m4/posix/arpa_inet.m4 @@ -0,0 +1,11 @@ +PSI_CHECK_ARPA_INET() { + PSI_DECL(uint32_t htonl, [(uint32_t l)]) + PSI_DECL(uint16_t htons, [(uint16_t s)]) + PSI_DECL(uint32_t ntohl, [(uint32_t l)]) + PSI_DECL(uint16_t ntohs, [(uint16_t s)]) + + PSI_DECL(in_addr_t inet_addr, [(const char *cp)]) + PSI_DECL(char *inet_ntoa, [(struct in_addr in)]) + PSI_DECL(const char *inet_ntop, [(int af, const void *src, char *dst, socklen_t size)]) + PSI_DECL(int inet_pton, [(int af, const char *src, void *dst)]) +} \ No newline at end of file diff --git a/psi.d/arpa_inet.psi b/psi.d/arpa_inet.psi new file mode 100644 index 0000000..2a8404e --- /dev/null +++ b/psi.d/arpa_inet.psi @@ -0,0 +1,46 @@ +function psi\htonl(int $l) : int { + let l = intval($l); + return to_int(htonl); +} +function psi\htons(int $s) : int { + let s = intval($s); + return to_int(htons); +} + +function psi\ntohl(int $l) : int { + let l = intval($l); + return to_int(ntohl); +} +function psi\ntohs(int $s) : int { + let s = intval($s); + return to_int(ntohs); +} + + +function psi\inet_addr(string $cp) : int { + let cp = strval($cp); + return to_int(inet_addr); +} + +function psi\inet_ntoa(array $in) : string { + let in = arrval($in, + intval($s_addr) + ); + return to_string(inet_ntoa); +} + +function psi\inet_ntop(int $af, string $src) : string { + let af = intval($af); + let src = strval($src); + let size = psi\SIZEOF_STRUCT_SOCKADDR_STORAGE; + let dst = calloc(1, size); + return to_string(inet_ntop); +} + +function psi\inet_pton(int $af, string $src, string &$dst) : int { + let af = intval($af); + let src = strval($src); + let dst = calloc(1, psi\SIZEOF_STRUCT_SOCKADDR_STORAGE); + return to_int(inet_pton); + set $dst = to_string(dst, psi\SIZEOF_STRUCT_SOCKADDR_STORAGE); +} \ No newline at end of file diff --git a/tests/arpa_inet/inet001.phpt b/tests/arpa_inet/inet001.phpt new file mode 100644 index 0000000..d366e28 --- /dev/null +++ b/tests/arpa_inet/inet001.phpt @@ -0,0 +1,21 @@ +--TEST-- +inet_ntop/inet_pton +--INI-- +psi.directory={PWD}/../../psi.d:{PWD} +--SKIPIF-- + +--FILE-- +===TEST=== + +===DONE=== +--EXPECT-- +===TEST=== +int(1) +string(9) "127.1.1.1" +===DONE=== diff --git a/tests/arpa_inet/inet002.phpt b/tests/arpa_inet/inet002.phpt new file mode 100644 index 0000000..9cb95a5 --- /dev/null +++ b/tests/arpa_inet/inet002.phpt @@ -0,0 +1,14 @@ +--TEST-- +inet_addr/inet_ntoa +--INI-- +psi.directory={PWD}/../../psi.d:{PWD} +--FILE-- +===TEST=== + psi\inet_addr("217.0.0.1")])); +?> +===DONE=== +--EXPECT-- +===TEST=== +string(9) "217.0.0.1" +===DONE=== diff --git a/tests/arpa_inet/ntoh001.phpt b/tests/arpa_inet/ntoh001.phpt new file mode 100644 index 0000000..99d743c --- /dev/null +++ b/tests/arpa_inet/ntoh001.phpt @@ -0,0 +1,25 @@ +--TEST-- +arpa/inet +--INI-- +psi.directory={PWD}/../../psi.d:{PWD} +--SKIPIF-- + +--FILE-- +===TEST=== + +===DONE=== +--EXPECT-- +===TEST=== +int(55) +int(555555) +int(14080) +int(595200000) +===DONE===