Home Series60 Smartphone Pocket PC PC Omnis
         
 

EXTFunc - TechNote EF0003 (Read IP Address)

Variable Name Type Description
typedata Character Required functions (as extracted from EXTFUNC.TXT or WIN32API.TXT)
AddrByte Long Integer Current IP address section
hostname Character Host name
ipaddr Character Output IP address
ptrAddrByte Long Integer Memory pointer for IP address bytes
ptrAddrList Long Integer Memory pointer for IP address list
ptrHostEnt Long Integer Memory pointer for HOSTENT type
Procedural Version
Declare Function ('Declare Function gethostname Lib "wsock32" (ByVal szHost As String, ByVal dwHostLen As Long) As Long',kFalse)
Declare Function ('Declare Function gethostbyname Lib "wsock32" (ByVal szHost As String) As Long',kFalse)
Declare Type ("HOSTENT:hName As Long,hAliases As Long,hAddrType As Integer,hLen As Integer,hAddrList As Long",kFalse)
Call Function ("gethostname",hostname,256) 
Calculate hostname as trim(hostname)
Call Function ("gethostbyname",hostname) Returns ptrHostEnt
Allocate Type ("HOSTENT",ptrHostEnt) Returns ptrHostEnt ;; Allocate type from memory pointer
Get Type Value (ptrHostEnt,"hAddrList") Returns ptrAddrList
Allocate Type ("Long",ptrAddrList) Returns ptrAddrList
Get Type Value (ptrAddrList) Returns ptrAddrByte
Free Type (ptrAddrList)
Calculate ipaddr as ""
For loopcnt from 1 to 4 step 1
	Allocate Type ("Byte",ptrAddrByte) Returns ptrAddrByte
	Get Type Value (ptrAddrByte) Returns AddrByte
	Free Type (ptrAddrByte)
	Calculate ipaddr as con(ipaddr,AddrByte,".")
	Calculate ptrAddrByte as ptrAddrByte+1
End For
Free Type (ptrHostEnt)
WEBClient Version
Initialize data block specifying ExtFunc functions (needed as Win32 API file doesn't exist in WebClient) 
Begin text block
Text: Type HOSTENT (Carriage return,Linefeed)
Text: hName As Long (Carriage return,Linefeed)
Text: hAliases As Long (Carriage return,Linefeed)
Text: hAddrType As Integer (Carriage return,Linefeed)
Text: hLen As Integer (Carriage return,Linefeed)
Text: hAddrList As Long (Carriage return,Linefeed)
Text: End Type (Carriage return,Linefeed)
Text: Declare Function gethostname Lib "wsock32" (ByVal szHost As String, ByVal dwHostLen As Long) As Long (Carriage return,Linefeed)
Text: Declare Function gethostbyname Lib "wsock32" (ByVal szHost As String) As Long (Carriage return,Linefeed)
End text block
Get text block typedata
WebClient Method [Marked as "Execute on Web Client"]
Do $cinst.$objs.EFUNC.$loadtypedata(typedata)
Do $cinst.$objs.EFUNC.$callfunc ("gethostname",hostname,256) 
Calculate hostname as trim(hostname)
Do $cinst.$objs.EFUNC.$callfunc("gethostbyname",hostname) Returns ptrHostEnt
Do $cinst.$objs.EFUNC.$alloctype ("HOSTENT",ptrHostEnt) Returns ptrHostEnt ;; Allocate type from memory pointer
Do $cinst.$objs.EFUNC.$gettypevalue (ptrHostEnt,"hAddrList") Returns ptrAddrList
Do $cinst.$objs.EFUNC.$alloctype ("Long",ptrAddrList) Returns ptrAddrList
Do $cinst.$objs.EFUNC.$gettypevalue (ptrAddrList) Returns ptrAddrByte
Do $cinst.$objs.EFUNC.$freetype (ptrAddrList)
Calculate ipaddr as ""
For loopcnt from 1 to 4 step 1
	Do $cinst.$objs.EFUNC.$alloctype ("Byte",ptrAddrByte) Returns ptrAddrByte
	Do $cinst.$objs.EFUNC.$gettypevalue (ptrAddrByte) Returns AddrByte
	Do $cinst.$objs.EFUNC.$freetype (ptrAddrByte)
	Calculate ipaddr as con(ipaddr,AddrByte,".")
	Calculate ptrAddrByte as ptrAddrByte+1
End For
Do $cinst.$objs.EFUNC.$freetype (ptrHostEnt)

Need help with your particular problem?  Then simply email support