Back to index

glibc  2.9
isockad.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/socket.h>
00004 #include <netinet/in.h>
00005 #include <netdb.h>
00006 
00007 void 
00008 init_sockaddr (struct sockaddr_in *name,
00009               const char *hostname,
00010               uint16_t port)
00011 {
00012   struct hostent *hostinfo;
00013 
00014   name->sin_family = AF_INET;
00015   name->sin_port = htons (port);
00016   hostinfo = gethostbyname (hostname);
00017   if (hostinfo == NULL) 
00018     {
00019       fprintf (stderr, "Unknown host %s.\n", hostname);
00020       exit (EXIT_FAILURE);
00021     }
00022   name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
00023 }