• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

This topic is now archived and is closed to further replies.

# gethostbyname problem

This topic is 5630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have this code:

HOSTENT *host;
char name[100]="mail.gmx.net";
host=gethostbyname(name);
if(host)
{
//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

##### Share on other sites
make sure you have called wsastartup and you have recieved a WSADATA structure

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

--Fireking

Genetics 3rd Dimension Development

##### Share on other sites
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.