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

diff --git a/manual/examples/mkfsock.c b/manual/examples/mkfsock.c
new file mode 100644 (file)
index 0000000..45cd00a
--- /dev/null
@@ -0,0 +1,36 @@
+#include <sys/socket.h>
+#include <stdio.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <stdlib.h>
+
+int 
+make_named_socket (const char *filename)
+{
+  struct sockaddr_un name;
+  int sock, status;
+  size_t size;
+
+  /* Create the socket.  */
+  
+  sock = socket (PF_UNIX, SOCK_DGRAM, 0);
+  if (sock < 0)
+    {
+      perror ("socket");
+      exit (EXIT_FAILURE);
+    }
+
+  /* Bind a name to the socket.  */
+
+  name.sun_family = AF_FILE;
+  strcpy (name.sun_path, filename);
+  size = offsetof (name.sun_path) + strlen (name.sun_path) + 1;
+  status = bind (sock, (struct sockaddr *) &name, size);
+  if (status < 0)
+    {
+      perror ("bind");
+      exit (EXIT_FAILURE);
+    }
+
+  return sock;
+}