view rvinterf/l1filter/pktsort.c @ 898:203c025e71ab default tip

CHANGES: fc-host-tools-r17 released
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Apr 2022 19:09:21 +0000
parents ea458ee48691
children
line wrap: on
line source

/*
 * Here we sort out incoming packets from the target relayed via rvinterf.
 */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "pktmux.h"
#include "limits.h"
#include "localsock.h"
#include "localtypes.h"
#include "exitcodes.h"

extern u_char rvi_msg[];
extern int rvi_msg_len;
extern char **filter_list;

static
is_filter_match()
{
	char **fp;
	int len;

	for (fp = filter_list; *fp; fp++) {
		len = strlen(*fp);
		if (rvi_msg_len < len + 3)
			continue;
		if (strncmp(rvi_msg + 2, *fp, len))
			continue;
		if (rvi_msg[len+2] != ' ')
			continue;
		return 1;
	}
	return 0;
}

static void
print_l1_trace()
{
	u_char *dp, *endp;
	int c, newline;

	dp = rvi_msg + 2;
	endp = rvi_msg + rvi_msg_len;
	while (dp < endp) {
		c = *dp++;
		if (c == '\r')
			continue;
		if (c == '\n') {
			putchar(c);
			newline = 1;
			continue;
		}
		newline = 0;
		if (c & 0x80) {
			putchar('M');
			putchar('-');
			c &= 0x7F;
		}
		if (c == 0x7F) {
			putchar('^');
			putchar('?');
			continue;
		}
		if (c < 0x20) {
			putchar('^');
			c += '@';
		}
		putchar(c);
	}
	if (!newline)
		putchar('\n');
}

static void
l1_packet_rx()
{
	if (is_filter_match())
		print_l1_trace();
}

void
process_pkt_from_target()
{
	switch (rvi_msg[1]) {
	case RVT_L1_HEADER:
		l1_packet_rx();
		return;
	default:
		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
			rvi_msg[1]);
		exit(ERROR_RVINTERF);
	}
}