Version: 1.00.00 - last Update: Friday, October 02, 2009, 19:10:00
Foxtools WinSock Library Functions
_WSOCKGETHOSTBYADDR
_WSockGetHostByAddr() is the second of three Foxtools functions that were added by Calvin Hsia. WSockStartUp() initializes the Winsock library. Call _WSockStartUp() and _WSockCleanUp() to initialize/uninitialize the Winsock library. The _WSockGetHostByAddr() function finally takes an IP address string like "123.123.123.123" and resolves it into the name of the machine.
_WSockGetHostByAddr() wraps the Windows Socket function gethostbyaddr() <<< go there to find out the details! The following part is "borrowed” from Microsoft’s msdn Winsock Reference:
The gethostbyaddr function retrieves the host information corresponding to a network address. Note: The gethostbyaddr function has been deprecated by the introduction of the getnameinfo function. Developers creating Windows Sockets 2 applications are urged to use the getnameinfo function instead of the gethostbyaddr function. (As we cannot switch to the new GetNameInfo() internally, this information is of no big use for us.)
If you followed the link above you may know by now that there are a lot of different return/error values. All of these are eaten by the Foxtools wrapper. Instead, our Foxtools function solely returns 1 or 0 flagging success or failure.
VFP Syntax
iSuccess = _WSockGetHostByAddr(m.cIPAddress, @cHostName)
Parameters
[in] cIPAddress
The IP address of the computer to be resolved - a String-parameter like “123.240.100.15”.
[in] cHostName
Buffer variable that must have been defined before the call. _WSockGetHostBy Addr() returns the computer name in this variable if successful.
VFP Example(s)
Calling the _WSockGetHostByAddr() function can be accomplished with the following:
STORE 0 to buff1, buff2, buff3, buff4, buff5, buff6 IF _WSockStartUp(256 + 1, @buff1, @buff2, @buff3, @buff4, @buff5, @buff6) = 0 *\\ use your local IP address here IF _WSockGetHostByAddr("192.168.100.12", @buff1) = 1 ? m.buff1 ELSE Error “_WSockGetHostByAddr error” ENDIF = _WSockCleanUp() ENDIF