X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=psi.d%2Fnetdb.psi;h=f37476d186275cf701243b34c6db58e287700871;hp=df3454768b0b19ff987c5680a5f792e95b04497b;hb=3b0b651ea1b555d8d023e45b43e5eb93b23d00a1;hpb=c2dc24a4967dd767fc4a240f93ca0de4600a8c62 diff --git a/psi.d/netdb.psi b/psi.d/netdb.psi index df34547..f37476d 100644 --- a/psi.d/netdb.psi +++ b/psi.d/netdb.psi @@ -11,18 +11,51 @@ function psi\endservent() : void { return void(endservent); } +function psi\sethostent(bool $stayopen) : void { + let stayopen = intval($stayopen); + return void(sethostent); +} +function psi\setnetset(bool $stayopen) : void { + let stayopen = intval($stayopen); + return void(setnetent); +} +function psi\setprotoent(bool $stayopen) : void { + let stayopen = intval($stayopen); + return void(setprotoent); +} +function psi\setservent(bool $stayopen) : void { + let stayopen = intval($stayopen); + return void(setservent); +} + +function psi\gethostent() : array { + return to_array(*gethostent, + to_string(h_name), + to_array(h_aliases, to_string(h_aliases)), + to_int(h_addrtype), + to_int(h_length), + to_array(h_addr_list, to_string(h_addr_list, h_length)) + ); +} + function psi\gai_strerror(int $errcode) : string { let errcode = intval($errcode); return to_string(gai_strerror); } -function psi\getaddrinfo(string $node, string $service, array $hints, object &$res = NULL) : int { +// extern int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) +function psi\getaddrinfo(string $node, string $service, array $hints = NULL, object &$res = NULL) : int { let node = strval($node); let service = strval($service); - let hints = arrval($hints); + let hints = &arrval($hints, + intval($ai_flags), + intval($ai_family), + intval($ai_socktype), + intval($ai_protocol) + ); let res = &NULL; return to_int(getaddrinfo); - set $res = to_array(*res, + set $res = to_array(**res, to_int(ai_flags), to_int(ai_family), to_int(ai_socktype), @@ -30,6 +63,21 @@ function psi\getaddrinfo(string $node, string $service, array $hints, object &$r to_int(ai_addrlen), to_string(ai_addr, ai_addrlen), to_string(ai_canonname), - to_array(ai_next, ...) + to_array(*ai_next, ...) ); -} \ No newline at end of file + free freeaddrinfo(*res); +} + +// extern int getnameinfo(struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags) +function psi\getnameinfo(string $addr, string &$host = NULL, string &$service = NULL, int $flags = 0) : int { + let sa = strval($addr); + let salen = strlen($addr); + let hostlen = psi\NI_MAXHOST; + let host = calloc(hostlen, psi\SIZEOF_CHAR); + let servlen = psi\NI_MAXSERV; + let serv = calloc(servlen, psi\SIZEOF_CHAR); + let flags = intval($flags); + return to_int(getnameinfo); + set $host = to_string(host); + set $service = to_string(serv); +}