mirror of
https://sourceware.org/git/glibc.git
synced 2025-12-24 17:51:17 +03:00
initial import
This commit is contained in:
31
manual/examples/mkisock.c
Normal file
31
manual/examples/mkisock.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
int
|
||||
make_socket (unsigned short int port)
|
||||
{
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user