1995-02-18 09:27:10 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
int
|
1998-03-31 01:26:52 +08:00
|
|
|
make_socket (uint16_t port)
|
1995-02-18 09:27:10 +08:00
|
|
|
{
|
|
|
|
int sock;
|
|
|
|
struct sockaddr_in name;
|
|
|
|
|
|
|
|
/* Create the socket. */
|
|
|
|
sock = socket (PF_INET, SOCK_STREAM, 0);
|
|
|
|
if (sock < 0)
|
|
|
|
{
|
|
|
|
perror ("socket");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give the socket a name. */
|
|
|
|
name.sin_family = AF_INET;
|
|
|
|
name.sin_port = htons (port);
|
|
|
|
name.sin_addr.s_addr = htonl (INADDR_ANY);
|
|
|
|
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
|
|
|
|
{
|
|
|
|
perror ("bind");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sock;
|
|
|
|
}
|