Merge branch 'moteus' of https://github.com/moteus/luasocket into moteus
This commit is contained in:
commit
5e0b56b8d3
5 changed files with 50 additions and 6 deletions
24
src/inet.c
24
src/inet.c
|
@ -176,9 +176,24 @@ static int inet_global_getaddrinfo(lua_State *L)
|
|||
}
|
||||
lua_newtable(L);
|
||||
for (iterator = resolved; iterator; iterator = iterator->ai_next) {
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf,
|
||||
(socklen_t) sizeof(hbuf), sbuf, 0, NI_NUMERICHOST);
|
||||
char hbuf[NI_MAXHOST]
|
||||
#ifndef _WINDOWS
|
||||
,sbuf[NI_MAXSERV]
|
||||
#endif
|
||||
;
|
||||
ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf,
|
||||
(socklen_t) sizeof(hbuf),
|
||||
#ifdef _WINDOWS
|
||||
NULL, 0,
|
||||
#else
|
||||
sbuf, 0,
|
||||
#endif
|
||||
NI_NUMERICHOST);
|
||||
if(ret){
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, socket_gaistrerror(ret));
|
||||
return 2;
|
||||
}
|
||||
lua_pushnumber(L, i);
|
||||
lua_newtable(L);
|
||||
switch (iterator->ai_family) {
|
||||
|
@ -463,6 +478,9 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv,
|
|||
struct addrinfo *iterator = NULL, *resolved = NULL;
|
||||
const char *err = NULL;
|
||||
t_socket sock = *ps;
|
||||
/* translate luasocket special values to C */
|
||||
if (strcmp(address, "*") == 0) address = NULL;
|
||||
if (!serv) serv = "0";
|
||||
/* try resolving */
|
||||
err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved));
|
||||
if (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue