-
Notifications
You must be signed in to change notification settings - Fork 2
/
neighsnoop.c
49 lines (41 loc) · 1.38 KB
/
neighsnoop.c
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
47
48
49
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* SPDX-FileCopyrightText: 2024 - 1984 Hosting Company <[email protected]> */
/* SPDX-FileCopyrightText: 2024 - Freyx Solutions <[email protected]> */
/* SPDX-FileContributor: Freysteinn Alfredsson <[email protected]> */
/* SPDX-FileContributor: Julius Thor Bess Rikardsson <[email protected]> */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SOCKET_PATH "/run/neighsnoopd.sock"
#define BUFFER_SIZE 4096
int main(void)
{
int client_fd;
int count;
struct sockaddr_un addr;
char buffer[BUFFER_SIZE];
// Create a UNIX domain socket
if ((client_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(EXIT_FAILURE);
}
// Set up the socket address
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path) - 1);
// Connect to the server
if (connect(client_fd, (struct sockaddr*)&addr,
sizeof(struct sockaddr_un)) == -1) {
perror("connect");
exit(EXIT_FAILURE);
}
// Read the response from the server
memset(buffer, 0, BUFFER_SIZE);
while ((count = read(client_fd, buffer, BUFFER_SIZE)) > 0)
write(STDOUT_FILENO, buffer, count);
close(client_fd);
return 0;
}