- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :-)
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 :-)
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page