Compare commits

...

14 Commits
v2 ... master

Author SHA1 Message Date
Kelvin Sherlock c8d4567479 Merge branch 'master' of https://github.com/ksherlock/tcpsnooper 2021-03-14 22:47:48 -04:00
Kelvin Sherlock bb28886f5a display raw long version word 2021-03-14 22:47:28 -04:00
ksherlock 28e759de98
Update makefile.mk 2019-07-15 21:45:50 -04:00
ksherlock 12e48f3b63
Update readme 2019-07-15 21:34:57 -04:00
Kelvin Sherlock 4a0dc5ee7d up/down arrows as synonym for left/right 2019-07-10 23:55:36 -04:00
Kelvin Sherlock 1dcbc4872b add timer states display 2019-07-10 23:55:14 -04:00
Kelvin Sherlock 751c8ce200 ws cleanup 2019-07-10 23:32:14 -04:00
Kelvin Sherlock b66dc76ee7 display TCP Tool errors. 2019-07-10 23:32:01 -04:00
Kelvin Sherlock 96bad24744 display state and tcp error names. 2019-07-10 23:31:36 -04:00
Kelvin Sherlock 4cf3b61286 typo. 2019-07-09 22:56:52 -04:00
Kelvin Sherlock cf0b2fa26f clean up makefile a little bit, add ifconfig. 2019-01-19 21:41:49 -05:00
Kelvin Sherlock aee73c0de9 marinetti callback was trashing memory. WriteLine store to _toolErr, in the wrong bank. 2019-01-19 21:29:45 -05:00
Kelvin Sherlock e064126d90 clang-format 2019-01-19 21:25:25 -05:00
Kelvin Sherlock a4a81fbe4d add ifconfig 2019-01-19 21:25:02 -05:00
6 changed files with 273 additions and 62 deletions

View File

@ -2,31 +2,46 @@
.PHONY: all
all: tcpsnooper.cda netstat
all: tcpsnooper.cda netstat ifconfig
.PHONY: clean
clean:
rm -rf o
tcpsnooper.cda : o/snooper.a
iix -DKeepType=cda link o/snooper keep=tcpsnooper.cda
iix -DKeepType=cda link $(^:.a=) keep=$@
netstat : o/netstat.a
iix link o/netstat keep=netstat
iix link $(^:.a=) keep=$@
ifconfig : o/ifconfig.a
iix link $(^:.a=) keep=$@
o:
mkdir o
o/%.a : %.c | o
iix compile $< keep=o/$*
o/snooper.a : snooper.c | o
iix compile snooper.c keep=o/snooper
o/%.a : %.asm | o
iix compile $< keep=o/$*
# o/snooper.a : snooper.c | o
# iix compile snooper.c keep=o/snooper
# o/netstat.a : netstat.c | o
# iix compile netstat.c keep=o/netstat
o/netstat.a : netstat.c | o
iix compile netstat.c keep=o/netstat
# no longer used.
cda.mac: cda.asm
iix macgen cda.asm cda.mac 13:ainclude:m16.= 13:orcainclude:m16.=
o/cda.a : cda.asm | cda.mac o
iix compile cda.asm keep=o/cda
# o/cda.a : cda.asm | cda.mac o
# iix compile cda.asm keep=o/cda
o/debug.a : debug.c ur.c | o
iix compile debug.c keep=o/debug
# o/debug.a : debug.c ur.c | o
# iix compile debug.c keep=o/debug

113
ifconfig.c Normal file
View File

@ -0,0 +1,113 @@
#include <Locator.h>
#include <TextTool.h>
#include <tcpip.h>
#include <string.h>
/*
* ifconfig [ up | down | status ]
*
*/
/*
* callback by Marinetti to display a connect message
*
*/
#pragma databank 1
void display(const char *pstr) { WriteLine(pstr); }
#pragma databank 0
// todo - support flags
// -s: be silent (ie - no output, return value only
// -f: force disconnect
//
int main(int argc, char **argv) {
LongWord address;
char buffer[16];
if (argc != 2) {
WriteCString("Usage: ifconfig [ up | down | status ]\n\r");
WriteCString(" up Connects to network\n\r");
WriteCString(" down Disconnects from network\n\r");
WriteCString(" status Queries status\n\r");
exit(1);
}
if (!strcmp(argv[1], "up")) {
TCPIPStatus();
if (_toolErr) {
LoadOneTool(54, 0x0200);
if (_toolErr) {
ErrWriteCString("Unable to load Marinetti\r\n");
exit(1);
}
}
// acedemic only - TCPStartup() just for show.
if (!TCPIPStatus()) {
TCPIPStartUp();
}
if (TCPIPGetConnectStatus()) {
ErrWriteCString("Already connected to network\r\n");
exit(0);
}
TCPIPConnect(display);
if (_toolErr) {
ErrWriteCString("Error connecting to network\r\n");
exit(1);
}
WriteCString("Connected to network\r\n");
WriteCString("IP Address is: ");
address = TCPIPGetMyIPAddress();
TCPIPConvertIPToCASCII(address, buffer, 0);
WriteCString(buffer);
WriteCString("\r\n");
exit(0);
}
if (!strcmp(argv[1], "down")) {
// if tool isn't loaded, we're already down...
TCPIPStatus();
if (_toolErr) {
ErrWriteCString("Marinetti not loaded\r\n");
exit(0);
}
if (!TCPIPGetConnectStatus()) {
ErrWriteCString("Not connected to network\r\n");
exit(0);
}
// todo - flag to force up & down
TCPIPDisconnect(true, display);
WriteCString("Disconnected from network\r\n");
// UnloadOneTool(54);
exit(0);
}
if (!strcmp(argv[1], "status")) {
// if tool isn't loaded, we're already down...
TCPIPStatus();
if (_toolErr) {
WriteCString("Network is down\r\n");
exit(1);
}
if (!TCPIPGetConnectStatus()) {
WriteCString("Network is down\r\n");
exit(1);
}
WriteCString("Network is up\r\n");
WriteCString("IP Address is: ");
address = TCPIPGetMyIPAddress();
TCPIPConvertIPToCASCII(address, buffer, 0);
WriteCString(buffer);
WriteCString("\r\n");
exit(0);
}
ErrWriteCString("illegal option -- ");
ErrWriteCString(argv[1]);
ErrWriteCString("\r\n");
exit(1);
}

View File

@ -27,9 +27,6 @@
#for use with dmake(1)
# for compiling netstat and tcpsnooper.cda
# Requires Kelvin's modified Orca C library to be present in the current directory.
# Kelvin's modified Orca C library includes an implementation of fdprintf()
CFLAGS += $(DEFINES) -v #-O
netstat: netstat.o

View File

@ -82,7 +82,7 @@ static char *stateStr =
"LASTACK "
"CLOSING "
"TIMEWAIT "
"UNKOWN ";
"UNKNOWN ";
static destRec dest;

36
readme
View File

@ -1,41 +1,11 @@
TCP Snooper
TCP Snooper is a Classic Desk Accessory (CDA) which shows some information on all currently active Marinetti TCP connections. It is useful if youUre programming or debugging a TCP program, or if you just like to know whatUs going on with your system.
Information shown includes the ipid, state, address. source port, destination port, and how much data is in the receive queue and send queue.
Kelvin Sherlock, 2004-2006
TCP Snooper is a Classic Desk Accessory (CDA) which displays information on all currently active Marinetti TCP connections. It is useful if youUre programming or debugging a TCP program, or if you just like to know what's going on with your system.
How To Build TCP Snooper
======================
TCP Snooper is written in Orca/C and Orca/M, therefore you will need both Orca/C and Orca/M to be able to build this utility.
To be able to follow these instructions without modification, you will need to have the the GNO/ME environment installed. It should also be possible to build the utility using the Orca environment, however no instructions are provided on how to do this.
Prerequisites
------------
Kelvin has modified his liborca library to include an implementation of fdprintf() which is used by TCP Snooper. Kelvin's modified liborca library cannot be released as part of the Marinetti Open Source Project, but it is required to be able to build TCP Snooper.
You can download Kelvin's Orca library from http://iigs.ksherlock.com/liborca/
Place it in the same directory as the TCP Snooper source code.
You also need to generate the macro file that is used by the source code.
If you are using GNO/ME you can do this with the following command:
macgen cda.mac /lang/orca/libraries/ainclude/m16.* /lang/orca/libraries/orcainclude/m16.tools /lang/orca/libraries/ainclude/m16.orca
If you are using Orca:
macgen cda.mac 2:ainclude:m16.= 2:orcainclude:m16.tools 2:orcainclude:m16.orca
Build TCPSnooper
---------------
A makefile for use with dmake is provided. dmake should be installed in your GNO/ME environment.
The makefile can be used to make either the command line version or the CDA version of the utility.
dmake netstat --> creates command line version
dmake tcpsnooper.cda -->creates CDA version
TCP Snooper is written in ORCA/C. It can be built usig Golden Gate (GNUmakefile) or with GNO/ME (using dmake - makefile.mk).
It can also be manually built under ORCA Shell (`cmpl snooper.c keep=snooper.cda`)

144
snooper.c
View File

@ -54,7 +54,7 @@ void Display(Word ipid, srBuff *srBuffer) {
"xxx.xxx.xxx.xxx " // 16 address
"xxxxx " // 6 source port
"xxxxx " // 6 dest port
"$xxxxxxxx " // 10 rcv queue
"$xxxxxxxx " // 10 rcv queue
"$xxxxxxxx "; // 10 send queue
static char buffer16[16];
@ -69,7 +69,7 @@ void Display(Word ipid, srBuff *srBuffer) {
"LASTACK "
"CLOSING "
"TIMEWAIT "
"UNKOWN ";
"UNKNOWN ";
static destRec dest;
@ -311,13 +311,15 @@ void DisplayLinkLayer(void) {
void DisplayTCP(void) {
static DNSRec dns;
unsigned long version;
Long l;
print_tab("TCP Status", 10);
// version
VersionString(0, TCPIPLongVersion(), buffer);
printf(" Version: %b\r", buffer);
version = TCPIPLongVersion();
VersionString(0, version, buffer);
printf(" Version: %b ($%08lx)\r", buffer, version);
printf(" Connect Status: $%04x\r", TCPIPGetConnectStatus());
// ip address
@ -345,6 +347,49 @@ void DisplayTCP(void) {
void DisplayIpid2(unsigned page, userRecord *rec) {
static char *error_codes[] = {
"OK",
"DeafDestPort",
"HostReset",
"ConExists",
"ConIllegal",
"NoResources",
"NoSocket",
"BadPrec",
"BadSec",
"BadConnection",
"ConClosing",
"Closing",
"ConReset",
"UserTimeout",
"ConRefused",
};
static char *states[] = {
"CLOSED",
"LISTEN",
"SYNSENT",
"SYNRCVD",
"ESTABLISHED",
"FINWAIT1",
"FINWAIT2",
"CLOSEWAIT",
"LASTACK",
"CLOSING",
"TIMEWAIT",
};
static char *timer_states[] = {
"OFF",
"SYN",
"DATA",
"2MSL",
"SYNACK",
};
unsigned x,y;
print_tab("User Record", 11);
if (page == 0) {
@ -352,12 +397,12 @@ void DisplayIpid2(unsigned page, userRecord *rec) {
printf(" uwUserID: $%04x\r", rec->uwUserID);
printf(" uwDestIP: $%08lx (%b)\r", rec->uwDestIP, buffer);
printf(" uwDestPort: $%04x (%u)\r", rec->uwDestPort,
printf(" uwDestPort: $%04x (%u)\r", rec->uwDestPort,
rec->uwDestPort);
printf(" uwIP_TOS: $%04x\r", rec->uwIP_TOS);
printf(" uwIP_TTL: $%04x\r", rec->uwIP_TTL);
printf(" uwSourcePort: $%04x (%u)\r", rec->uwSourcePort,
printf(" uwSourcePort: $%04x (%u)\r", rec->uwSourcePort,
rec->uwSourcePort);
printf(" uwLogoutPending: $%04x\r", rec->uwLogoutPending);
printf(" uwICMPQueue: $%08lx\r", rec->uwICMPQueue);
@ -387,9 +432,20 @@ void DisplayIpid2(unsigned page, userRecord *rec) {
printf(" uwRCV_WND: $%04x\r", rec->uwRCV_WND);
printf(" uwRCV_UP: $%04x\r", rec->uwRCV_UP);
printf(" uwIRS: $%08lx\r", rec->uwIRS);
printf(" uwTCP_State: $%04x\r", rec->uwTCP_State);
x = rec->uwTCP_State;
printf(" uwTCP_State: $%04x", x);
if (x < sizeof(states)/sizeof(states[0]))
printf(" (%s)", states[x]);
fputs("\r", stdout);
printf(" uwTCP_StateTick: $%08lx\r", rec->uwTCP_StateTick);
printf(" uwTCP_ErrCode: $%04x\r", rec->uwTCP_ErrCode);
x = rec->uwTCP_ErrCode;
printf(" uwTCP_ErrCode: $%04x", x);
if (x < sizeof(error_codes)/sizeof(error_codes[0]))
printf(" (%s)", error_codes[x]);
fputs("\r", stdout);
printf(" uwTCP_ICMPError: $%04x\r", rec->uwTCP_ICMPError);
printf(" uwTCP_Server: $%04x\r", rec->uwTCP_Server);
printf(" uwTCP_ChildList: $%08lx\r", rec->uwTCP_ChildList);
@ -402,7 +458,16 @@ void DisplayIpid2(unsigned page, userRecord *rec) {
printf(" uwTCP_FINSEQ: $%08lx\r", rec->uwTCP_FINSEQ);
printf(" uwTCP_MyFINACKed: $%04x\r", rec->uwTCP_MyFINACKed);
printf(" uwTCP_Timer: $%08lx\r", rec->uwTCP_Timer);
printf(" uwTCP_TimerState: $%04x\r", rec->uwTCP_TimerState);
x = rec->uwTCP_TimerState;
printf(" uwTCP_TimerState: $%04x", x);
if ((x & 0x01) == 0) {
x >>= 1;
if (x < sizeof(timer_states)/sizeof(timer_states[0]))
printf(" (%s)", timer_states[x]);
}
fputs("\r", stdout);
printf(" uwTCP_rt_timer: $%04x\r", rec->uwTCP_rt_timer);
printf(" uwTCP_2MSL_timer: $%04x\r", rec->uwTCP_2MSL_timer);
printf(" uwTCP_SaveTTL: $%04x\r", rec->uwTCP_SaveTTL);
@ -479,14 +544,14 @@ int DisplayIpid(unsigned ipid) {
c = ReadKey();
if (c == 0x1b || c == 'Q' || c == 'q')
return 0;
if (c == LEFT) {
if (c == LEFT || c == UP) {
if (page == 0)
page = MAX_PAGE;
else
--page;
break;
}
if (c == RIGHT) {
if (c == RIGHT || c == DOWN) {
if (page == MAX_PAGE)
page = 0;
else
@ -627,6 +692,51 @@ void DisplayErrors(void) {
putchar('\r');
}
void DisplayToolErrors(unsigned page) {
print_tab("Tool Errors", 11);
if (page == 0)
fputs(
" $3601 BADIPID Bad IPID for this request\r"
" $3602 NOCONNECTION Not connected to the network\r"
" $3603 NORECONDATA No reconnect data\r"
" $3604 LINKERROR Problem with the link layer\r"
" $3605 SCRIPTFAILED The script failed / timed out\r"
" $3606 CONNECTED Not while connected to the network\r"
" $3607 SOCKETOPEN Socket still open\r"
" $3608 INITNOTFOUND Init not found in memory\r"
" $3609 VERSIONMISMATCH Different versions of tool, init, cdev\r"
" $360A BADTUNETABLELEN Bad tune table length\r"
" $360B IPIDTABLEFULL IPID table full\r"
" $360C NOICMPQUEUED No ICMP datagrams in the queue\r"
" $360D LOGINSPENDING There are still IPIDs logged in\r"
" $360E TCPIPNOTACTIVE Not active. Probably in P8 mode.\r"
" $360F NODNSERVERS No servers registered with Marinetti\r",
stdout);
if (page == 1)
fputs(
" $3610 DNRBUSY DNR is current busy. Try again later\r"
" $3611 NOLINKLAYER Unable to load link layer module\r"
" $3612 BADLINKLAYER Not a link layer module\r"
" $3613 ENJOYCOKE But not so close to the keyboard\r"
" $3614 NORECONSUPPRT This module doesn't support reconnect\r"
" $3615 USERABORTED The user aborted the connect/disconnect script\r"
" $3616 BADUSERPASS Invalid username and/or password\r"
" $3617 BADPARAMETER Invalid parameter for this call\r"
" $3618 BADENVIRONMENT No desktop or tools not started\r"
" $3619 NOINCOMING There is no pending incoming request\r"
" $361A LINKBUSY Modem or interface is busy\r"
" $361B NOLINKINTERFACE No dial tone or similar\r"
" $361C NOLINKRESPONSE No modem answer or similar\r"
" $361D NODNRPENDING No such entry in DNR list\r"
" $361E BADALIVEMINUTES Minutes value is invalid\r"
" $361F BUFFERTOOSMALL Buffer is too small\r"
" $3620 NOTSERVER This ipid is not set up as a server\r"
" $3621 BADTRIGGERNUM Invalid trigger number\r",
stdout);
}
/*
putchar(30);
putchar(32 + 0);
@ -636,7 +746,7 @@ putchar(29);
#define status_line() fputs("\x1e\x20\x37\x1d", stdout)
void DisplayMain(void) {
enum { MAX_PAGE = 5 };
enum { MAX_PAGE = 7 };
char c;
unsigned page = 0;
@ -661,6 +771,12 @@ void DisplayMain(void) {
case 5:
DisplayDP();
break;
case 6:
DisplayToolErrors(0);
break;
case 7:
DisplayToolErrors(1);
break;
}
menu:
@ -676,14 +792,14 @@ void DisplayMain(void) {
c = ReadKey();
if (c == 'Q' || c == 'q' || c == ESC)
return;
if (c == LEFT) {
if (c == LEFT || c == UP) {
if (page == 0)
page = MAX_PAGE;
else
--page;
break;
}
if (c == RIGHT) {
if (c == RIGHT || c == DOWN) {
if (page == MAX_PAGE)
page = 0;
else