gethostbyname problem

Started by
1 comment, last by decebal 21 years, 6 months ago
I have this code:
  
HOSTENT *host;
char name[100]="mail.gmx.net";
host=gethostbyname(name);
	if(host)
		aValue=*((DWORD *)(*host->h_addr_list));
	else aValue=inet_addr(name);
	if(aValue!=INADDR_NONE)
{
//The address is good to use with a socket

}
  
but it doesn''t work the address is invalid And do I need to be connected to the network what''s the problem Mankind must put an end to war before war puts an end to mankind. John F. Kennedy
Mankind must put an end to war before war puts an end to mankind. John F. Kennedy
Advertisement
make sure you have called wsastartup and you have recieved a WSADATA structure

you can specify the version with MAKEWORD(2,2)

--Fireking

Owner/Leader
Genetics 3rd Dimension Development
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
You really should be calling inet_addr first. The point is to avoid having to go out to the net to lookup a name that doesn''t need looking up.

Yes, you need to be connected to a network for gethostbyname to work. You need to have access to some sort of DNS server.

What, exactly, is it that doesn''t work, and what error code do you get? What is invalid, the name you''re putting in or the result you''re getting back? You really haven''t supplied the basic info about your problem.
-Mike

This topic is closed to new replies.

Advertisement