GetHostByName function in CVF

GetHostByName function in CVF

I'm trying to use the GetHostByName() Windows Sockets function in my CVF program (just for fun :-)). But the IP address it returns is not correct. Here is the code:

subroutine InetCheck()
use dfwina
implicit none
type (t_in_addr) addr,adr
type (t_hostent) hp
type (t_wsaData) wsaData
integer ptr,sptr,i,aptr,address
character str*100,s*100
pointer (ptr,hp)
pointer (sptr,s)
pointer (aptr,addr)
pointer (adrptr,address)
str="www.rambler.ru"C
call WSAStartup(MAKEWORD(2,2),wsaData);
ptr=gethostbyname(str)
aptr=hp.h_addr_list
sptr=inet_ntoa(hp.h_addr_list)
adrptr=hp.h_addr_list
write (str,'(i3)') &
127+LOBYTE(LOWORD(address)) ! First byte (unsigned)
if (WSAGetLastError().eq.0) call ShowMessage("Host",str)
if (WSAGetLastError().eq.0) call ShowMessage("Host",s)
call WSACleanUp()
end subroutine InetCheck

The WSAGetLastError function returns zero, but both messages (ShowMessage()) display various and wrong results!
If I try some IP address (for example, "182.158.0.1") instead "www.rambler.ru" the result is not correct too (does not match with "182.158.0.1").

What's wrong in my code?

Sorry for possible grammar and other mistakes.

Andrew, from Russia with love :-)

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.