=========================================================================*\ * Internal functions \*=========================================================================*/ -------------------------------------------------------------------------*\ * Passes all resolver information to Lua as a table \*-------------------------------------------------------------------------*/
| 311 | * Passes all resolver information to Lua as a table |
| 312 | \*-------------------------------------------------------------------------*/ |
| 313 | static 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 |
no test coverage detected