view rvinterf/asyncshell/pktsort.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents bbc41034f14c
children 31a36b400cdf
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 int oneshot_mode;

static void
process_rvt()
{
	u32 useid;

	if (rvi_msg_len < 7) {
		tty_cleanup();
		fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
		exit(ERROR_RVINTERF);
	}
	useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
		| rvi_msg[5];
	switch (useid) {
	case 0:
		handle_useid_0();
		return;
	default:
		tty_cleanup();
		fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
			useid);
		exit(ERROR_RVINTERF);
	}
}

static void
gpf_packet_rx()
{
	char fmtbuf[MAX_PKT_FROM_TARGET*8];	/* size it generously */

	format_g23_packet(rvi_msg + 1, rvi_msg_len - 1, fmtbuf);
	async_msg_output(fmtbuf);
}

static void
response_from_ati()
{
	char buf[MAX_PKT_FROM_TARGET*4+2];

	strcpy(buf, "ATI: ");
	safe_print_trace(rvi_msg + 2, rvi_msg_len - 2, buf + 5);
	async_msg_output(buf);
	if (oneshot_mode)
		oneshot_at_check_response();
}

void
process_pkt_from_target()
{
	switch (rvi_msg[1]) {
	case RVT_RV_HEADER:
		process_rvt();
		return;
	case RVT_L23_HEADER:
		gpf_packet_rx();
		return;
	case RVT_AT_HEADER:
		response_from_ati();
		return;
	case RVT_TCH_HEADER:
		tch_packet_rx();
		return;
	default:
		tty_cleanup();
		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
			rvi_msg[1]);
		exit(ERROR_RVINTERF);
	}
}