summaryrefslogtreecommitdiff
path: root/yarns/sockbind.c
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2013-12-16 09:36:52 +0000
committerBen Brown <ben.brown@codethink.co.uk>2013-12-16 09:36:52 +0000
commit672e64a86f5d07ff5c5d26495af257336f57deab (patch)
tree9ff1eed3a683ba90e8238c1cc7f1a07b5d61dd48 /yarns/sockbind.c
parent775d05edada9d9fdf2bd9bc4eb62bbeec0961ad4 (diff)
parent149de8fcb40dc355e0a81ae8e17c4a43b614d8d7 (diff)
downloadtbdiff-672e64a86f5d07ff5c5d26495af257336f57deab.tar.gz
Merge branch 'benbrown/S9482/convert-socket-tests'
Diffstat (limited to 'yarns/sockbind.c')
-rw-r--r--yarns/sockbind.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/yarns/sockbind.c b/yarns/sockbind.c
new file mode 100644
index 0000000..8bbcfcf
--- /dev/null
+++ b/yarns/sockbind.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+/*
+ * There is currently no command within Baserock to create named Unix sockets;
+ * this program is used to compensate for that.
+ */
+
+int main(int argc, char *argv[])
+{
+ int sfd;
+ struct sockaddr_un sock;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s PATH\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (strlen(argv[1]) >= sizeof(sock.sun_path)) {
+ fprintf(stderr, "%s: file name too long\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+
+ if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ perror("socket");
+ return EXIT_FAILURE;
+ }
+
+ sock.sun_family = AF_UNIX;
+ strcpy(sock.sun_path, argv[1]);
+ if (bind(sfd, (struct sockaddr*)&sock, sizeof(sock)) == -1) {
+ perror("bind");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}