Implement src/testclient-promisc.c
Implement src/testclient-promisc.c to demonstrate raw packet access ("promiscuous mode") to interfaces
This commit is contained in:
parent
2c3ff15d16
commit
bd68e33973
2 changed files with 116 additions and 1 deletions
|
@ -14,7 +14,8 @@ HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \
|
|||
OBJS = kiss.o ax25.o if.o call.o frame.o sock.o route.o server.o \
|
||||
list.o hash.o dict.o print.o
|
||||
|
||||
EXAMPLES = testserver testclient-connect testclient-listen decode
|
||||
EXAMPLES = testserver testclient-connect testclient-listen testclient-promisc \
|
||||
decode
|
||||
|
||||
HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/, $(HEADERS))
|
||||
|
||||
|
|
114
src/testclient-promisc.c
Normal file
114
src/testclient-promisc.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <patty/ax25.h>
|
||||
#include <patty/print.h>
|
||||
|
||||
static void usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message != NULL) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s /var/run/patty/patty.sock\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct sockaddr_un addr;
|
||||
|
||||
int fd,
|
||||
sock,
|
||||
pty;
|
||||
|
||||
patty_ax25_addr peer;
|
||||
char path[PATTY_AX25_SOCK_PATH_SIZE];
|
||||
|
||||
uint8_t buf[4096];
|
||||
ssize_t readlen;
|
||||
|
||||
if (argc != 2) {
|
||||
usage(argc, argv, "No patty socket provided");
|
||||
}
|
||||
|
||||
patty_ax25_pton("KZ3ROX", 0, &peer);
|
||||
|
||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "socket()", argv[1], strerror(errno));
|
||||
|
||||
goto error_socket;
|
||||
}
|
||||
|
||||
memset(&addr, '\0', sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, argv[1], sizeof(addr.sun_path));
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
goto error_connect;
|
||||
}
|
||||
|
||||
if ((sock = patty_ax25_call_openif(fd, "kiss0", path, sizeof(path))) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s\n",
|
||||
argv[0], "patty_ax25_call_openif()", strerror(errno));
|
||||
|
||||
goto error_call_socket;
|
||||
}
|
||||
|
||||
if ((pty = open(path, O_RDWR)) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], path, "open()", strerror(errno));
|
||||
|
||||
goto error_open_pty;
|
||||
}
|
||||
|
||||
while ((readlen = read(pty, buf, sizeof(buf))) > 0) {
|
||||
patty_ax25_frame frame;
|
||||
|
||||
if (patty_ax25_frame_decode(&frame, PATTY_AX25_FRAME_NORMAL, buf, readlen) < 0) {
|
||||
perror("Unable to decode frame");
|
||||
|
||||
goto error_ax25_frame_decode;
|
||||
}
|
||||
|
||||
if (patty_print_frame(stdout, &frame, buf, readlen) < 0) {
|
||||
perror("Unable to print frame");
|
||||
|
||||
goto error_print_frame;
|
||||
}
|
||||
}
|
||||
|
||||
close(pty);
|
||||
|
||||
patty_ax25_call_close(fd, sock);
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
|
||||
error_print_frame:
|
||||
error_ax25_frame_decode:
|
||||
error_open_pty:
|
||||
patty_ax25_call_close(fd, sock);
|
||||
|
||||
error_call_socket:
|
||||
close(fd);
|
||||
|
||||
error_connect:
|
||||
error_socket:
|
||||
return 1;
|
||||
}
|
Loading…
Add table
Reference in a new issue