1995-02-18 09:27:10 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
init_sockaddr (struct sockaddr_in *name,
|
|
|
|
const char *hostname,
|
1998-03-31 01:26:52 +08:00
|
|
|
uint16_t port)
|
1995-02-18 09:27:10 +08:00
|
|
|
{
|
|
|
|
struct hostent *hostinfo;
|
|
|
|
|
|
|
|
name->sin_family = AF_INET;
|
|
|
|
name->sin_port = htons (port);
|
|
|
|
hostinfo = gethostbyname (hostname);
|
|
|
|
if (hostinfo == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Unknown host %s.\n", hostname);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
|
|
|
|
}
|