MCPcopy Create free account
hub / github.com/Tencent/UnLua / inet_pushresolved

Function inet_pushresolved

Plugins/UnLuaExtensions/LuaSocket/Source/src/inet.cpp:313–348  ·  view source on GitHub ↗

=========================================================================*\ * Internal functions \*=========================================================================*/ -------------------------------------------------------------------------*\ * Passes all resolver information to Lua as a table \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

311* Passes all resolver information to Lua as a table
312\*-------------------------------------------------------------------------*/
313static void inet_pushresolved(lua_State *L, struct hostent *hp)
314{
315 char **alias;
316 struct in_addr **addr;
317 int i, resolved;
318 lua_newtable(L); resolved = lua_gettop(L);
319 lua_pushstring(L, "name");
320 lua_pushstring(L, hp->h_name);
321 lua_settable(L, resolved);
322 lua_pushstring(L, "ip");
323 lua_pushstring(L, "alias");
324 i = 1;
325 alias = hp->h_aliases;
326 lua_newtable(L);
327 if (alias) {
328 while (*alias) {
329 lua_pushnumber(L, i);
330 lua_pushstring(L, *alias);
331 lua_settable(L, -3);
332 i++; alias++;
333 }
334 }
335 lua_settable(L, resolved);
336 i = 1;
337 lua_newtable(L);
338 addr = (struct in_addr **) hp->h_addr_list;
339 if (addr) {
340 while (*addr) {
341 lua_pushnumber(L, i);
342 lua_pushstring(L, inet_ntoa(**addr));
343 lua_settable(L, -3);
344 i++; addr++;
345 }
346 }
347 lua_settable(L, resolved);
348}
349
350/*-------------------------------------------------------------------------*\
351* Tries to create a new inet socket

Callers 2

inet_global_tohostnameFunction · 0.85
inet_global_toipFunction · 0.85

Calls 4

lua_gettopFunction · 0.85
lua_pushstringFunction · 0.85
lua_settableFunction · 0.85
lua_pushnumberFunction · 0.85

Tested by

no test coverage detected