X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=psi.d%2Fnetdb.psi;h=2b74b2db2e6c9b768f048d32aca03d0d0b93c6fe;hp=dd81ed882de993602f2e670fd1c91b4f75ca3272;hb=77a446cbcdce6558c00066e5f13e43e8b1b18ff7;hpb=cfebc76ed7426836f21296cca9a14b422bfa04cf diff --git a/psi.d/netdb.psi b/psi.d/netdb.psi index dd81ed8..2b74b2d 100644 --- a/psi.d/netdb.psi +++ b/psi.d/netdb.psi @@ -43,11 +43,11 @@ function psi\gai_strerror(int $errcode) : string { return to_string(gai_strerror); } -// extern int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); +// 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, object &$res = NULL) : int { let node = strval($node); let service = strval($service); - let hints = arrval($hints); + let hints = &arrval($hints); let res = &NULL; return to_int(getaddrinfo); set $res = to_array(**res, @@ -60,5 +60,19 @@ function psi\getaddrinfo(string $node, string $service, array $hints, object &$r to_string(ai_canonname), to_array(*ai_next, ...) ); - free freeaddrinfo(res); -} \ 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); +}