reformat.

This commit is contained in:
Kelvin Sherlock 2019-01-16 21:26:42 -05:00
parent 9ef349f561
commit 267e1803d0
2 changed files with 335 additions and 292 deletions

4
.clang-format Normal file
View File

@ -0,0 +1,4 @@
---
IndentWidth: '4'
...

623
nscda.c
View File

@ -33,16 +33,15 @@
#include <tcpip.h> #include <tcpip.h>
#include <tcpipx.h> #include <tcpipx.h>
#include <memory.h>
#include <misctool.h> #include <misctool.h>
#include <texttool.h> #include <texttool.h>
#include <memory.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
static char buffer[80]; static char buffer[80];
const char Header1[] = const char Header1[] =
" Ipid State Address sPort dPort RcvQueue SendQueue\r"; " Ipid State Address sPort dPort RcvQueue SendQueue\r";
const char Header2[] = const char Header2[] =
@ -50,84 +49,78 @@ const char Header2[] =
// xxxxx xxxxxxxxxxx xxx.xxx.xxx.xxx xxxxx xxxxx $xxxxxxxx $xxxxxxxx // xxxxx xxxxxxxxxxx xxx.xxx.xxx.xxx xxxxx xxxxx $xxxxxxxx $xxxxxxxx
void Display(Word ipid, srBuff *srBuffer) { void Display(Word ipid, srBuff *srBuffer) {
static char buffer[80] = "xxxxx " // 6 ipid static char buffer[80] = "xxxxx " // 6 ipid
"xxxxxxxxxxx " // 12 state "xxxxxxxxxxx " // 12 state
"xxx.xxx.xxx.xxx " // 16 address "xxx.xxx.xxx.xxx " // 16 address
"xxxxx " // 6 source port "xxxxx " // 6 source port
"xxxxx " // 6 dest port "xxxxx " // 6 dest port
"$xxxxxxxx " // 10 rcv queue "$xxxxxxxx " // 10 rcv queue
"$xxxxxxxx "; // 10 send queue "$xxxxxxxx "; // 10 send queue
static char buffer16[16]; static char buffer16[16];
static char *stateStr = "CLOSED " static char *stateStr = "CLOSED "
"LISTEN " "LISTEN "
"SYNSENT " "SYNSENT "
"SYNRCVD " "SYNRCVD "
"ESTABLISHED " "ESTABLISHED "
"FINWAIT1 " "FINWAIT1 "
"FINWAIT2 " "FINWAIT2 "
"CLOSEWAIT " "CLOSEWAIT "
"LASTACK " "LASTACK "
"CLOSING " "CLOSING "
"TIMEWAIT " "TIMEWAIT "
"UNKOWN "; "UNKOWN ";
static destRec dest; static destRec dest;
char *cp; char *cp;
Word i, j; Word i, j;
TCPIPGetDestination(ipid, &dest); TCPIPGetDestination(ipid, &dest);
for (i = 0; i < 80; i++) for (i = 0; i < 80; i++)
buffer[i] = ' '; buffer[i] = ' ';
Int2Dec(ipid, buffer, 5, 0); Int2Dec(ipid, buffer, 5, 0);
cp = buffer + 6; cp = buffer + 6;
i = srBuffer->srState; i = srBuffer->srState;
if (i > 10) if (i > 10)
i = 11; i = 11;
i *= 12; // sizeof the string... i *= 12; // sizeof the string...
for (j = 0; j < 12; j++) for (j = 0; j < 12; j++)
*cp++ = stateStr[i + j]; *cp++ = stateStr[i + j];
cp = buffer + 18; cp = buffer + 18;
// includes the last space, so we're ok. // includes the last space, so we're ok.
TCPIPConvertIPToCASCII(srBuffer->srDestIP, buffer16, 0); TCPIPConvertIPToCASCII(srBuffer->srDestIP, buffer16, 0);
for (j = 0; buffer16[j]; j++) for (j = 0; buffer16[j]; j++)
*cp++ = buffer16[j]; *cp++ = buffer16[j];
i = TCPIPGetSourcePort(ipid); i = TCPIPGetSourcePort(ipid);
Int2Dec(i, buffer + 34, 5, 0); Int2Dec(i, buffer + 34, 5, 0);
Int2Dec(srBuffer->srDestPort, buffer + 40, 5, 0); Int2Dec(srBuffer->srDestPort, buffer + 40, 5, 0);
buffer[46] = '$'; buffer[46] = '$';
Long2Hex(srBuffer->srRcvQueued, buffer + 47, 8); Long2Hex(srBuffer->srRcvQueued, buffer + 47, 8);
buffer[56] = '$'; buffer[56] = '$';
Long2Hex(srBuffer->srSndQueued, buffer + 57, 8); Long2Hex(srBuffer->srSndQueued, buffer + 57, 8);
buffer[66] = '\r'; buffer[66] = '\r';
buffer[67] = 0; buffer[67] = 0;
fputs(buffer, stdout); fputs(buffer, stdout);
} }
asm int ReadKey(void) { asm int ReadKey(void) {
sep #0x20 sep #0x20 loop : lda > 0xe0c000 bpl loop sta > 0xe0c010 rep #0x20 and
loop: #0x7f rtl
lda >0xe0c000
bpl loop
sta >0xe0c010
rep #0x20
and #0x7f
rtl
} }
/* ORCA Console control codes */ /* ORCA Console control codes */
@ -144,322 +137,368 @@ asm int ReadKey(void) {
#define ESC 0x1b #define ESC 0x1b
int ReadInt(void) { int ReadInt(void) {
unsigned i = 0; unsigned i = 0;
unsigned c; unsigned c;
unsigned rv; unsigned rv;
putchar(CURSOR_ON); putchar(CURSOR_ON);
while (1) { while (1) {
c = ReadKey(); c = ReadKey();
if (c == 0x1b) { if (c == 0x1b) {
rv = -1; rv = -1;
break; break;
}
if (c == 13) {
if (i == 0)
rv = -1;
break;
} else if ((c == 8) || (c == 0x7f)) {
if (i) {
putchar(8);
putchar(' ');
putchar(8);
i--;
rv /= 10;
}
} else if ((c >= '0') && (c <= '9')) {
if (i < 5) {
putchar(c);
i++;
rv *= 10;
rv += c - '0';
continue;
}
}
SysBeep();
} }
if (c == 13) { putchar(CURSOR_OFF);
if (i == 0) rv = -1; return rv;
break;
} else if ((c == 8) || (c == 0x7f)) {
if (i) {
putchar(8);
putchar(' ');
putchar(8);
i--;
rv /= 10;
}
} else if ((c >= '0') && (c <= '9')) {
if (i < 5) {
putchar(c);
i++;
rv *= 10;
rv += c - '0';
continue;
}
}
SysBeep();
}
putchar(CURSOR_OFF);
return rv;
} }
void hexdump(const void *data, Word length) {
Word i;
Word j;
Word k;
Word x;
static char text[17];
void hexdump(const void *data, Word length) if (length > 16 * 320)
{ length = 16 * 320;
Word i;
Word j;
Word k;
Word x;
static char text[17];
if (length > 16 * 320) length = 16 * 320; for (i = 0, j = 0, x = 0; i < length; i++) {
for (i = 0, j = 0, x = 0; i < length; i++) k = ((unsigned char *)data)[i];
{ buffer[j++] = "0123456789abcdef"[k >> 4];
buffer[j++] = "0123456789abcdef"[k & 0x0f];
buffer[j++] = ' ';
k = ((unsigned char *)data)[i]; text[x++] = isprint(k) ? k : '.';
buffer[j++] = "0123456789abcdef"[k >> 4];
buffer[j++] = "0123456789abcdef"[k & 0x0f];
buffer[j++] = ' ';
text[x++] = isprint(k) ? k : '.'; if ((i & 0x0f) == 0x07)
buffer[j++] = ' ';
if ((i & 0x0f) == 0x07) buffer[j++] = ' '; if ((i & 0x0f) == 0x0f) {
buffer[j++] = ' ';
buffer[j++] = 0;
text[x++] = 0;
if ((i & 0x0f) == 0x0f) printf("%04x: %s%s\r", i - 15, buffer, text);
{ j = 0;
buffer[j++] = ' '; x = 0;
buffer[j++] = 0; }
text[x++] = 0;
printf("%04x: %s%s\r", i - 15, buffer, text);
j = 0;
x = 0;
} }
}
if (i & 0x0f) if (i & 0x0f) {
{ while (j < 52)
while (j < 52) buffer[j++] = ' '; buffer[j++] = ' ';
buffer[j++] = 0; buffer[j++] = 0;
text[x++] = 0; text[x++] = 0;
printf("%04x: %s%s\r", i - 15, buffer, text);
}
printf("%04x: %s%s\r", i - 15, buffer, text);
}
} }
void DisplayQueue(Word which, const userRecord *rec) {
Handle h;
Word size;
putchar(0x0c);
if (which == 'S') {
fputs("Send Queue\r\r");
h = (Handle)rec->uwTCPDataOut;
} else {
fputs("Receive Queue\r\r");
h = (Handle)rec->uwTCPDataIn;
}
if (h) {
size = GetHandleSize(h);
hexdump(*h, size);
}
}
void DisplayDP(void) { void DisplayDP(void) {
Word dp; Word dp;
putchar(0x0c); putchar(0x0c);
fputs("Marinetti DP\r\r", stdout); fputs("Marinetti DP\r\r", stdout);
dp = TCPIPGetDP(); dp = TCPIPGetDP();
printf("Direct Page: $%04x\r", dp); printf("Direct Page: $%04x\r", dp);
hexdump((void *)dp, 0x0100); hexdump((void *)dp, 0x0100);
} }
void DisplayLinkLayer(void) { void DisplayLinkLayer(void) {
static linkInfoBlk link; static linkInfoBlk link;
variablesPtr lv; variablesPtr lv;
unsigned c; unsigned c;
TCPIPGetLinkLayer(&link); TCPIPGetLinkLayer(&link);
lv = TCPIPGetLinkVariables(); lv = TCPIPGetLinkVariables();
putchar(0x0c); putchar(0x0c);
fputs("Link Layer Status\r\r", stdout); fputs("Link Layer Status\r\r", stdout);
printf("MethodID: $%04x\r", link.liMethodID); printf("MethodID: $%04x\r", link.liMethodID);
printf("Name: %b\r", link.liName); printf("Name: %b\r", link.liName);
VersionString(0, link.liVersion, buffer); VersionString(0, link.liVersion, buffer);
printf("Version: %b\r", buffer); printf("Version: %b\r", buffer);
printf("Flags: $%04x\r", link.liFlags); printf("Flags: $%04x\r", link.liFlags);
fputs("\r", stdout); fputs("\r", stdout);
printf("Variables:\r");
printf("Version: %d\r", lv->lvVersion);
printf("Connected: $%04x\r", lv->lvConnected);
TCPIPConvertIPToASCII(lv->lvIPaddress, buffer, 0);
printf("IP Address: %b\r", buffer);
printf("RefCon: $%08lx\r", lv->lvRefCon);
printf("Errors: $%08lx\r", lv->lvErrors);
printf("MTU: %d\r", lv->lvMTU);
printf("Variables:\r");
printf("Version: %d\r", lv->lvVersion);
printf("Connected: $%04x\r", lv->lvConnected);
TCPIPConvertIPToASCII(lv->lvIPaddress, buffer, 0);
printf("IP Address: %b\r", buffer);
printf("RefCon: $%08lx\r", lv->lvRefCon);
printf("Errors: $%08lx\r", lv->lvErrors);
printf("MTU: %d\r", lv->lvMTU);
} }
void DisplayTCP(void) { void DisplayTCP(void) {
static DNSRec dns; static DNSRec dns;
Long l; Long l;
unsigned c; unsigned c;
putchar(0x0c); putchar(0x0c);
fputs("TCP Status\r\r", stdout); fputs("TCP Status\r\r", stdout);
// version // version
VersionString(0, TCPIPLongVersion(), buffer); VersionString(0, TCPIPLongVersion(), buffer);
printf("Version: %b\r", buffer); printf("Version: %b\r", buffer);
printf("Connect Status: $%04x\r", TCPIPGetConnectStatus()); printf("Connect Status: $%04x\r", TCPIPGetConnectStatus());
// ip address // ip address
l = TCPIPGetMyIPAddress(); l = TCPIPGetMyIPAddress();
TCPIPConvertIPToASCII(l, buffer, 0); TCPIPConvertIPToASCII(l, buffer, 0);
printf("IP Address: %b\r", buffer); printf("IP Address: %b\r", buffer);
// dns // dns
TCPIPGetDNS(&dns); TCPIPGetDNS(&dns);
TCPIPConvertIPToASCII(dns.DNSMain, buffer, 0); TCPIPConvertIPToASCII(dns.DNSMain, buffer, 0);
printf("DNS 1: %b\r", buffer); printf("DNS 1: %b\r", buffer);
TCPIPConvertIPToASCII(dns.DNSAux, buffer, 0); TCPIPConvertIPToASCII(dns.DNSAux, buffer, 0);
printf("DNS 2: %b\r", buffer); printf("DNS 2: %b\r", buffer);
// hostname // hostname
TCPIPGetHostName((hnBuffPtr)buffer); TCPIPGetHostName((hnBuffPtr)buffer);
printf("Hostname: %b\r", buffer); printf("Hostname: %b\r", buffer);
// mtu
printf("MTU: %d\r", TCPIPGetMTU());
printf("Alive Flag: $%04x\r", TCPIPGetAliveFlag());
printf("Alive Minutes: %d\r", TCPIPGetAliveMinutes());
printf("Login Count: %d\r", TCPIPGetLoginCount());
// mtu
printf("MTU: %d\r", TCPIPGetMTU());
printf("Alive Flag: $%04x\r", TCPIPGetAliveFlag());
printf("Alive Minutes: %d\r", TCPIPGetAliveMinutes());
printf("Login Count: %d\r", TCPIPGetLoginCount());
} }
unsigned DisplayIpid(unsigned ipid) { unsigned DisplayIpid(unsigned ipid) {
/* extended debug information */ /* extended debug information */
Handle h;
Word size;
unsigned page = 0;
putchar(0x0c); enum { MAX_PAGE = 0; };
printf("IPID: %d\r", ipid); Handle h;
Word size;
unsigned page = 0;
userRecord *rec;
unsigned c;
putchar(0x0c);
printf("IPID: %d\r", ipid);
h = (Handle)TCPIPGetUserRecord(ipid); h = (Handle)TCPIPGetUserRecord(ipid);
if (_toolErr) return; if (_toolErr || !h) {
if (!h) return; printf("\r\rInvalid PID");
ReadKey();
return;
}
size = (Word)GetHandleSize(h); size = (Word)GetHandleSize(h);
rec = (userRecord *)*h;
printf("Datagram count (all): %d\r", for (;;) {
TCPIPGetDatagramCount(ipid, protocolAll));
printf("Datagram count (icmp): %d\r", switch (page) {
TCPIPGetDatagramCount(ipid, protocolICMP)); case 0:
break;
}
printf("Datagram count (tcp): %d\r", for (;;) {
TCPIPGetDatagramCount(ipid, protocolTCP)); c = ReadKey();
if (c == 0x1b || c == 'Q' || c == 'q')
return;
if (c == LEFT) {
if (page == 0)
page = MAX_PAGE;
else
--page;
break;
}
if (c == RIGHT) {
if (page == MAX_PAGE)
page = 0;
else
++page;
break;
}
SysBeep();
}
}
}
printf("Datagram count (udp): %d\r", printf("Datagram count (all): %d\r", TCPIPGetDatagramCount(ipid, protocolAll));
TCPIPGetDatagramCount(ipid, protocolUDP));
printf("Datagram count (icmp): %d\r",
TCPIPGetDatagramCount(ipid, protocolICMP));
printf("User statistic 1: $%08lx\r", printf("Datagram count (tcp): %d\r", TCPIPGetDatagramCount(ipid, protocolTCP));
TCPIPGetUserStatistic(ipid, 1));
printf("User statistic 2: $%08lx\r", printf("Datagram count (udp): %d\r", TCPIPGetDatagramCount(ipid, protocolUDP));
TCPIPGetUserStatistic(ipid, 2));
printf("User statistic 1: $%08lx\r", TCPIPGetUserStatistic(ipid, 1));
printf("User statistic 2: $%08lx\r", TCPIPGetUserStatistic(ipid, 2));
} }
void DisplayIpids(void) { void DisplayIpids(void) {
static srBuff srBuffer; static srBuff srBuffer;
unsigned ipid; unsigned ipid;
unsigned line; unsigned line;
unsigned count; unsigned count;
putchar(0x0c); putchar(0x0c);
fputs(Header1, stdout); fputs(Header1, stdout);
fputs(Header2, stdout); fputs(Header2, stdout);
line = 2; line = 2;
count = TCPIPGetLoginCount(); count = TCPIPGetLoginCount();
if (!count) return; if (!count)
/* in theory, there could be 50 ipids. */ return;
/* 20 ought to be enough */ /* in theory, there could be 50 ipids. */
/* 20 ought to be enough */
for (ipid = 0; ipid < 100; ipid += 2) { for (ipid = 0; ipid < 100; ipid += 2) {
TCPIPStatusTCP(ipid, &srBuffer); TCPIPStatusTCP(ipid, &srBuffer);
if (_toolErr) if (_toolErr)
continue; continue;
Display(ipid, &srBuffer); Display(ipid, &srBuffer);
--count; --count;
++line; ++line;
if (count == 0) return; if (count == 0)
if (line == 23) return; return;
} if (line == 23)
return;
}
} }
void DisplayMain(void) { void DisplayMain(void) {
enum { enum { MAX_PAGE = 3 };
MAX_PAGE = 3 char c;
}; unsigned page = 0;
char c;
unsigned page = 0;
for(;;) { for (;;) {
switch (page) { switch (page) {
case 0: case 0:
DisplayIpids(); DisplayIpids();
break; break;
case 1: case 1:
DisplayTCP(); DisplayTCP();
break; break;
case 2: case 2:
DisplayLinkLayer(); DisplayLinkLayer();
break; break;
case 3: case 3:
DisplayDP(); DisplayDP();
break; break;
} }
/* DCA */ /* DCA */
menu: menu:
putchar(30);
putchar(32 + 0);
putchar(32 + 23);
putchar(29); /* erase line */
if (page == 0) {
fputs("Q: Quit I: Info", stdout);
} else {
fputs("Q: Quit", stdout);
}
for(;;) {
c = ReadKey();
if (c == 'Q' || c == 'q' || c == ESC) return;
if (c == LEFT) {
if (page == 0) page = MAX_PAGE;
else --page;
break;
}
if (c == RIGHT) {
if (page == MAX_PAGE) page = 0;
else ++page;
break;
}
if (c == 'I' || c == 'i') {
putchar(30); putchar(30);
putchar(32 + 0); putchar(32 + 0);
putchar(32 + 23); putchar(32 + 23);
putchar(29); /* erase line */ putchar(29); /* erase line */
fputs("ipid: ", stdout);
int ipid = ReadInt(); if (page == 0) {
if (ipid < 0) goto menu; fputs("Q: Quit I: Info", stdout);
DisplayIpid(ipid); } else {
break; fputs("Q: Quit", stdout);
} }
SysBeep();
for (;;) {
c = ReadKey();
if (c == 'Q' || c == 'q' || c == ESC)
return;
if (c == LEFT) {
if (page == 0)
page = MAX_PAGE;
else
--page;
break;
}
if (c == RIGHT) {
if (page == MAX_PAGE)
page = 0;
else
++page;
break;
}
if (c == 'I' || c == 'i') {
putchar(30);
putchar(32 + 0);
putchar(32 + 23);
putchar(29); /* erase line */
fputs("ipid: ", stdout);
int ipid = ReadInt();
if (ipid < 0)
goto menu;
DisplayIpid(ipid);
break;
}
SysBeep();
}
} }
}
} }
void StartUp(void) { void StartUp(void) {
putchar(CURSOR_OFF); /* turn off cursor */ putchar(CURSOR_OFF); /* turn off cursor */
if (TCPIPStatus() == 0 || _toolErr) { if (TCPIPStatus() == 0 || _toolErr) {
fputs("Marinetti is not active", stdout); fputs("Marinetti is not active", stdout);
ReadKey(); ReadKey();
return; return;
} }
DisplayMain(); DisplayMain();
} }
void ShutDown(void) { void ShutDown(void) {}
}