1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-26 13:21:07 +03:00
Files
glibc/manual/examples/isockad.c
Roland McGrath 28f540f45b initial import
1995-02-18 01:27:10 +00:00

24 lines
529 B
C

#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,
unsigned short int port)
{
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;
}