parser: accept trailing comma in enums; __restrict for arrays
[m6w6/ext-psi] / psi.d / arpa_inet.psi
1 #include <arpa/inet.h>
2
3 function psi\htonl(int $l) : int {
4 let l = intval($l);
5 return htonl(l) as to_int(htonl);
6 }
7 function psi\htons(int $s) : int {
8 let s = intval($s);
9 return htons(s) as to_int(htons);
10 }
11
12 function psi\ntohl(int $l) : int {
13 let l = intval($l);
14 return ntohl(l) as to_int(ntohl);
15 }
16 function psi\ntohs(int $s) : int {
17 let s = intval($s);
18 return ntohs(s) as to_int(ntohs);
19 }
20
21
22 function psi\inet_addr(string $cp) : int {
23 let cp = strval($cp);
24 return inet_addr(cp) as to_int(inet_addr);
25 }
26
27 function psi\inet_ntoa(array $in) : string {
28 let in = arrval($in,
29 intval($s_addr)
30 );
31 return inet_ntoa(in) as to_string(inet_ntoa);
32 }
33
34 function psi\inet_ntop(int $af, string $src) : string {
35 let af = intval($af);
36 let src = strval($src);
37 let size = psi\SIZEOF_STRUCT_SOCKADDR_STORAGE;
38 let dst = calloc(1, size);
39 return inet_ntop(af, src, dst, size) as to_string(inet_ntop);
40 }
41
42 function psi\inet_pton(int $af, string $src, string &$dst) : int {
43 let af = intval($af);
44 let src = strval($src);
45 let dst = calloc(1, psi\SIZEOF_STRUCT_SOCKADDR_STORAGE);
46 return inet_pton(af, src, dst) as to_int(inet_pton);
47 set $dst = to_string(dst, psi\SIZEOF_STRUCT_SOCKADDR_STORAGE);
48 }