From 9de26ea193728ea08a3a90513bd7936be3101a37 Mon Sep 17 00:00:00 2001 From: mikeos Date: Thu, 31 Jan 2013 01:23:33 +0400 Subject: add commandline options --- stat.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 stat.c (limited to 'stat.c') diff --git a/stat.c b/stat.c new file mode 100644 index 0000000..1a5581a --- /dev/null +++ b/stat.c @@ -0,0 +1,50 @@ +#include +#include + +#include +#include +#include +#include + +#include "debug.h" + +#define COMMAND "list\nbye\n" + +static char buf[0x1000]; + +int main(int argc, char *argv[]) +{ + struct sockaddr_un sa; + int sock; + int n; + + if (argc < 2) { + fprintf(stderr, "Usage: %s socket_path\n", argv[0]); + exit(EXIT_FAILURE); + } + + sock = socket(PF_UNIX, SOCK_STREAM, 0); + if (sock < 0) + sys_err("socket"); + + memset(&sa, 0, sizeof(sa)); + sa.sun_family = AF_UNIX; + strcpy(sa.sun_path, argv[1]); + if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) + sys_err("connect"); + + if (write(sock, COMMAND, sizeof(COMMAND) - 1) < 0) + sys_err("write"); + + while ((n = read(sock, buf, sizeof(buf))) > 0) { + buf[n] = 0; + fputs(buf, stdout); + } + + if (n < 0) + sys_err("read"); + + close(sock); + return 0; +} + -- cgit v1.2.3-70-g09d2