From 893c216b889f260378fb21a7f576c061f7ff2248 Mon Sep 17 00:00:00 2001 From: mikeos Date: Sat, 13 Oct 2012 23:20:14 +0400 Subject: initial --- tcpstat.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tcpstat.c (limited to 'tcpstat.c') diff --git a/tcpstat.c b/tcpstat.c new file mode 100644 index 0000000..b76877f --- /dev/null +++ b/tcpstat.c @@ -0,0 +1,41 @@ +#include +#include + +#include +#include +#include +#include + +#include "debug.h" +#include "data.h" + +static char buf[0x1000]; + +int main(int argc, char *argv[]) +{ + struct sockaddr_un sa; + int sock; + int n; + + 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, UNIX_SOCKET_PATH); + if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) + sys_err("connect"); + + 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