If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

gethostbyaddr and gethostbyname

Any help on this appreciated.

This is a winsock program designed to prompt the user to enter a domain name.
The program is then supposed to return to the user a resolved ip address of that domain name. The user should also be able to enter an IP address and receive back a domain name.

While the program prompts the user to enter the domain name, all that is ever returned is error#:0

Re: gethostbyaddr and gethostbyname

Sorry. Change all the %i in the printf to %u. Printf is treating the numbers as signed so printing some as negative. They are unsigned numbers. I only gave an example of how to extract the ip address from the returned data.

Re: gethostbyaddr and gethostbyname

Er.. NO! Thats not how things work unfortunately. If you enter ip address 98.139.183.24 and get ir2.fp.vip.bf1.yahoo.com then your program is working! Try this. At the command line type nslookup and at the > prompt type www.yahoo.com. Then at the next > prompt type in the address just shown. Type exit to exit the program. Going from an ip address to a domain name is called reverse DNS lookup. To understand what is going on look at

Re: gethostbyaddr and gethostbyname

So I have new code here that I need to do the same with.

1. using the gethostbyname function, prompt user for domain name, which will be entered as a string to be resolved
2. return the ip address of the domain entered.
3. use inet_ntoa to format and display the ip address
4. if an error is returned, print a message for the error using the WSAGetLastError

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.