Initial revision
authorroland <roland>
Mon, 9 Nov 1992 23:53:27 +0000 (23:53 +0000)
committerroland <roland>
Mon, 9 Nov 1992 23:53:27 +0000 (23:53 +0000)
manual/examples/mkisock.c [new file with mode: 0644]

diff --git a/manual/examples/mkisock.c b/manual/examples/mkisock.c
new file mode 100644 (file)
index 0000000..07411bb
--- /dev/null
@@ -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;
+}