Here's the code:
` Example 'main' code
` Try to call WSAStartup() once at the start of the program, and
` don't forget to call WSACleanup() before you exit.
if WSAStartup() = 0
Count=GetLocalIPCount()
for index=0 to Count-1
print GetLocalIP(index)
next index
WSACleanup()
endif
sync
wait key
` Library code - put these into a separate .dba file and include them.
#constant WSOCK32DLLNUMBER 201
function GetLocalIPCount()
local Count as integer
local p as DWORD
local v as DWORD
local HOSTENT as DWORD
HOSTENT=make memory(256)
Count=0
if GetHostName( HOSTENT, 256 ) = 0
HostInfo=GetHostByName( HOSTENT )
if HostInfo <> 0
p=HostInfo+12
p=*p
do
v=*p
if v = 0 then exit
inc p, 4
inc Count
loop
endif
endif
delete memory HOSTENT
endfunction Count
function GetLocalIP(index as integer)
local ip as string
local p as DWORD
local HOSTENT as DWORD
HOSTENT=make memory(256)
if GetHostName( HOSTENT, 256 ) = 0
HostInfo=GetHostByName( HOSTENT )
if HostInfo <> 0
p=HostInfo+12
p=*p
p=*p
p=p+(index*4)
ip=INET_ntoa( *p )
endif
endif
delete memory HOSTENT
endfunction ip
function GetHostName(memptr as DWORD, size as integer)
local r as integer
local a as DWORD
local s as DWORD
r=call dll(WSOCK32DLLNUMBER, "gethostname", memptr, size)
endfunction r
function GetHostByName(memptr as DWORD)
local r as integer
r=call dll(WSOCK32DLLNUMBER, "gethostbyname", memptr)
endfunction r
function INET_ntoa(addr as DWORD)
local ip as string
ip=call dll(WSOCK32DLLNUMBER, "inet_ntoa", addr)
endfunction ip
function WSAStartup()
local WSADATA as DWORD
local r as integer
local v as WORD
load dll "wsock32.dll", WSOCK32DLLNUMBER
WSADATA=make memory(16384)
v=2
r=call dll(WSOCK32DLLNUMBER, "WSAStartup", v, WSADATA)
delete memory WSADATA
endfunction r
function WSACleanup()
call dll WSOCK32DLLNUMBER, "WSACleanup"
delete dll WSOCK32DLLNUMBER
endfunction