if( host_lookup( &server, hostname, port ) < 0 )
{
perror( hostname );//打印出来localhost: success
return -1;
}
int
host_lookup(
struct sockaddr_in * server,
const char * hostname,
int port
)
{
struct hostent * hp;
if( !(hp = gethostbyname(hostname)) )
return -1;
server->sin_family = AF_INET;
server->sin_port = htons( port );
memcpy( &server->sin_addr, hp->h_addr, hp->h_length );
return 0;
}