Back to index

glibc  2.9
mkisock.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 
00006 int 
00007 make_socket (uint16_t port)
00008 {
00009   int sock;
00010   struct sockaddr_in name;
00011 
00012   /* Create the socket. */
00013   sock = socket (PF_INET, SOCK_STREAM, 0);
00014   if (sock < 0)
00015     {
00016       perror ("socket");
00017       exit (EXIT_FAILURE);
00018     }
00019 
00020   /* Give the socket a name. */
00021   name.sin_family = AF_INET;
00022   name.sin_port = htons (port);
00023   name.sin_addr.s_addr = htonl (INADDR_ANY);
00024   if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
00025     {
00026       perror ("bind");
00027       exit (EXIT_FAILURE);
00028     }
00029 
00030   return sock;
00031 }