home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / manual / examples / isockaddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-09  |  523 b   |  23 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6.  
  7. void 
  8. init_sockaddr (struct sockaddr_in *name,
  9.            const char *hostname, unsigned short int port)
  10. {
  11.   struct hostent *hostinfo;
  12.  
  13.   name->sin_family = AF_INET;
  14.   name->sin_port = htons (port);
  15.   hostinfo = gethostbyname (serverhost);
  16.   if (hostinfo == NULL) 
  17.     {
  18.       fprintf (stderr, "Unknown host %s.\n", hostname);
  19.       exit (EXIT_FAILURE);
  20.     }
  21.   name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
  22. }
  23.