summaryrefslogtreecommitdiff
path: root/tcpstat.c
blob: ff248482c4fc8df7edac2fde43309032026e9faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <sys/socket.h>
#include <sys/un.h>

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include "debug.h"
#include "data.h"

#define COMMAND "list\nbye\n"

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");

	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;
}