From e247c2bbfe0f5b52ef532cacebcc1ea9dc3bbc76 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 19 Nov 2013 14:42:37 +0000 Subject: Added C program which creates named Unix sockets --- yarns/sockbind.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 yarns/sockbind.c 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 +#include +#include +#include +#include +#include + +/* + * 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; +} -- cgit v1.2.1