summaryrefslogtreecommitdiff
path: root/manual/examples
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1992-11-09 23:26:13 +0000
committerRoland McGrath <roland@gnu.org>1992-11-09 23:26:13 +0000
commit46ed3c64a14ed30a039eec55ebc9acbb8a523923 (patch)
tree9c2ca890a5d2f7f34e0c6e7cd1827e0073679e14 /manual/examples
parentb2b15a08b7aeaba1a7c8b105c100dab4be6025d6 (diff)
Initial revision
Diffstat (limited to 'manual/examples')
-rw-r--r--manual/examples/mkfsock.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/manual/examples/mkfsock.c b/manual/examples/mkfsock.c
new file mode 100644
index 0000000000..45cd00adc2
--- /dev/null
+++ b/manual/examples/mkfsock.c
@@ -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;
+}