- Kubuntu 12.04 x64 with PB 5.11 x64 in ASCII and Unicode mode
- MacOS X 10.6.8 (Snow Leopard) with PB 5.11 x86 and x64 in ASCII and Unicode mode
- Windows 7 SP1 x64 with PB 5.11 x86 and x64 in ASCII and Unicode mode
Code: Select all
CompilerIf Defined(HOSTENT, #PB_Structure) = #False
Structure hostent
*h_name
*h_aliases
h_addrtype.L
h_length.L
*h_addr_list
EndStructure
CompilerEndIf
InitNetwork()
Procedure GetIPAddressesFromHostname(Hostname.S)
Protected *HostInfos.hostent
Protected *HostnameBuffer
*HostNameBuffer = AllocateMemory(StringByteLength(Hostname, #PB_Ascii))
PokeS(*HostnameBuffer, Hostname, MemorySize(*HostnameBuffer), #PB_Ascii)
*HostInfos = gethostbyname_(*HostnameBuffer)
FreeMemory(*HostnameBuffer)
If *HostInfos = 0
Debug "Error: unable to find host name!"
Else
Debug "Hostname: " + PeekS(*HostInfos\h_name, -1, #PB_Ascii)
If *HostInfos\h_length = 4
IPType = #PB_Network_IPv4
Else
IPType = #PB_Network_IPv6
EndIf
Debug "IP addresses:"
*IP = *HostInfos\h_addr_list
While PeekI(*IP) <> 0
Debug IPString(PeekI(PeekI(*IP)), IPType)
*IP + SizeOf(Integer)
Wend
EndIf
Debug ""
EndProcedure
GetIPAddressesFromHostname("www.google.com")
GetIPAddressesFromHostname("www.purebasic.com")