954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get the IP address of a server for a socket

So I have to connect to a server on a specific port but all I have to identify the server is its name, e.g. "students.ce.sinclair.edu" in a char*. How can I get the ip address to assign to a sockaddr_in?

struct sockaddr_in server;
memset($server, 0, sizeof(server));
server.sin_family = AF_INET;
//server.sin_addr.s_addr = ->students.ce.sinclair.edu<-
server.sin_port = ####;

gethostbyname() sounds promising but I can't find a decent example. Any help would be greatly appreciated.

fusi0n423
Newbie Poster
18 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Check out this link
http://www.prasannatech.net/2008/07/socket-programming-tutorial.html

In the example code of TCP Client, there is a line
host = gethostbyname("127.0.0.1");

In place of 127.0.0.1 you can use the name of your server

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: