From 9f237e103a96a95bf294c06f7774323e8cfe761b 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 sockets --- yarns/sockbind.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 yarns/sockbind.c diff --git a/yarns/sockbind.c b/yarns/sockbind.c new file mode 100644 index 0000000..2f656ba --- /dev/null +++ b/yarns/sockbind.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include + +/* + * There is currently no command within Busybox or otherwise to create named + * UNIX sockets; this program is used to compensate for that. + */ + +int main(int argc, char *argv[]) +{ + int sfd, len; + struct sockaddr_un sock = { .sun_family = AF_UNIX }; + + if (argc != 2) { + fprintf(stderr, "Usage: %s PATH\n", argv[0]); + return EXIT_FAILURE; + } + + len = sizeof(sock) - offsetof(struct sockaddr_un, sun_path); + strncpy(sock.sun_path, argv[1], len); + + if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + perror("socket"); + return EXIT_FAILURE; + } + + if (bind(sfd, (struct sockaddr*)&sock, sizeof(sock)) == -1) { + perror("bind"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} -- cgit v1.2.1