--****************************************************************************** --* * --* File: Socket_00.lua Revision: 1.0 * --* * --* Contents: first experiments with LuaSocket 1.4 * --* * --* Creation: 08.03.2002 Last Modification: 08.03.2002 * --* * --* Platform: IBM-compatible PC running Windows 98SE * --* * --* Environment: Lua 4.0, TkLua 4.0, LuaSocket 1.4 * --* * --* Author: Andreas Rozek Phone: ++49 (711) 6770682 * --* Kirschblütenweg 15 Fax: - * --* D-70569 Stuttgart EMail: Andreas.Rozek@T-Online.De * --* Germany * --* * --* URL: http://www.Andreas-Rozek.de/ * --* * --* Copyright: the software is published under the "GNU Lesser General Pub- * --* lic License" (see "http://www.fsf.org/copyleft/lesser.html" * --* for additional information) * --* * --* Comments: (none) * --* * --****************************************************************************** print(); print("Socket_00 - tries to retrieve the local host name or IP address"); print(); --****************************************************************************** --* * --* showHostInfo displays the HostInfo table returned by tohostname and toip * --* * --****************************************************************************** function showHostInfo (HostInfo) print(" canonic name = ", HostInfo.name); if (HostInfo.alias == nil) or (getn(HostInfo.alias) == 0) then -- 2nd case is important! print(" alias list = (empty)"); else write(" alias list = "); local AliasCount = getn(HostInfo.alias); for i = 1,AliasCount do write(HostInfo.alias[i]); if (i < AliasCount) then write (", "); end; end; write("\n"); end; if (HostInfo.ip == nil) or (getn(HostInfo.ip) == 0) then -- 2nd case is important! print(" address list = (empty)"); else write(" address list = "); local AddressCount = getn(HostInfo.ip); for i = 1,AddressCount do write(HostInfo.ip[i]); if (i < AddressCount) then write (", "); end; end; write("\n"); end; end; --****************************************************************************** --* * --* main program * --* * --****************************************************************************** print("trying 'tohostname(\"127.0.0.1\")'...(may block for several seconds)"); local HostName,HostInfo = tohostname("127.0.0.1"); if (HostName == nil) then print("...failed, reason: \""..tostring(HostInfo).."\""); else print(" HostName = ", HostName); showHostInfo(HostInfo); end; print(); print("trying 'toip(\"localhost\")'...(may block for several seconds)"); local Address,HostInfo = toip("localhost"); if (Address == nil) then print("...failed, reason: \""..tostring(HostInfo).."\""); else print(" Address = "..tostring(Address)); showHostInfo(HostInfo); end; exit();