Fix up sched.h for XPG7.
[glibc.git] / manual / examples / mkisock.c
blob2fd8b3d2f9bbfb8cf11eef3068e49c07a3c2ed97
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/socket.h>
4 #include <netinet/in.h>
6 int
7 make_socket (uint16_t port)
9 int sock;
10 struct sockaddr_in name;
12 /* Create the socket. */
13 sock = socket (PF_INET, SOCK_STREAM, 0);
14 if (sock < 0)
16 perror ("socket");
17 exit (EXIT_FAILURE);
20 /* Give the socket a name. */
21 name.sin_family = AF_INET;
22 name.sin_port = htons (port);
23 name.sin_addr.s_addr = htonl (INADDR_ANY);
24 if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
26 perror ("bind");
27 exit (EXIT_FAILURE);
30 return sock;