#define I_STRING #define I_CTYPE #define I_SIGNAL #define I_TIME #define I_LIMITS #include "includes.h" #include "terminal.h" /* initially written by Michael O'Reilly rewritten by jeff grills (jefftep@cs.utexas.edu) to use, run remotely like: linecheck remote.out locally: linecheck stderr < /dev/modem > /dev/modem linecheck's first argument must be the name of a file to write the information into. if you specify "stderr," then the output is written to the standard error stream, as normal. this is what you prefer to do on your local machine so you can watch it work. on the remote machine, you need to specify a file to record this information in. you can tell linecheck not to test certain chars by listing their decimal number on the command line. for instance, if you know flow-control will get eaten, you can use "linecheck stderr 17 19", and it won't test those chars. this is also useful for testing a set of escape sequences, to make sure it makes your line clean. if it says something needs escaped, that means it didn't get through okay this time. if you get an invalid packet printed, it means the packet wasn't sent by the linecheck on the other side, and may either be line static, or some very braindead terminal response to a (possibly series) of characters to what was printed over the line. in this case, it's your responsibility to determine which, and escape the previously sent char if needed. There is no way this program can identity a braindead terminal server from line static, so this is the way it has to be. if, for some reason, you get stuck out in lala land, and can't kill the program, try typing "00000". That should kill it, and restore your terminal. It'll print "### sending char" and "### received valid". Don't worry if these two number are out of sync. That's fine. Just worry, on either side, if you get some "Invalid packet: " lines. Look at them closely, and see if it's line static, or a real problem. At the end, it'll print out a summary of what it thinks you should escape. This just means these chars didn't get received correctly this time. Again, if line static munched something, some of these may be valid. *** IF *** your terminal server generates extra responses for odd chars, then you may not be told to escape something, but need to anyway. This will be evident from a "Invalid packet: " on the local side, after attempting to send a character. Again, it may be line static. You have to make the call. if you're running it locally in a xterm, I suggest you turn on window logging. if you have problems with this program, and want me to look at it, mail me *both* the local and remote output, and label them appropriately. */ /* -------------------------------------------------- */ #define START_AT 0 #define STOP_AT 256 #define START 'A' #define STOP 'B' #define END_PACKET 'C' #define XON '\021' #define DONE "done" #define RDONE "rdone" #define SLEEP 1 #define TRIES 1 #define BUMS 1 #define BUFFSIZE 200 /* -------------------------------------------------- */ unsigned char buff[BUFFSIZE]; unsigned char linecheck_mask = 255; int valid[STOP_AT+1], skip[STOP_AT], pid, debugging; /* -------------------------------------------------- */ int freqtest(void); void sig_int(int x) { if (pid) kill(pid, SIGINT); exit(-1); } /* -------------------------------------------------- */ void debug(unsigned char *s) { while (*s) { /* boy, there are some screwed up isprint()s out there */ if ( isprint(*s) && (*s < 128) ) fprintf(stderr, "%c", *(s++)); else fprintf(stderr, "<%d>", (int) *(s++)); } fprintf(stderr, "\n"); } /* -------------------------------------------------- */ int mgets(unsigned char *buff, int len) { unsigned char ch; int i, zcount; i = 0; zcount = 0; while(1) { read(STDIN_FILENO, &ch, 1); ch &= linecheck_mask; /* check if we get five 0's and abort */ if ( ch == '0' ) { if (++zcount == 5) { kill(pid, SIGINT); terminal_restore(0,0); exit(0); } } else zcount = 0; /* handle next char */ if (ch == '\n') /* check if this is really inside the packet */ if ( (i == 4) && (buff[0] == '1') && (buff[1] == '0') && (buff[2] == ' ') && (buff[3] == START) ) buff[i++] = ch; else { buff[i] = '\0'; return i; } else { /* store this char in the buffer */ buff[i++] = ch; /* don't let packet overflow */ if ( (i+1) == len) { buff[i] = '\0'; return i; } } } } /* -------------------------------------------------- */ void handshake() { int i; fprintf(stderr, "Handshaking\n"); printf("\n%c\n", START); i = 0; while ( ! i ) { mgets(buff, BUFFSIZE); if ( (buff[0] == START) && (buff[1] == '\0') ) { i = 1; printf("\n%c\n", STOP); } else if ( (buff[0] == STOP) && (buff[1] == '\0') ) i = 1; else if (buff[0] != '\0' ) { fprintf(stderr, "unexpected packet: "); debug(buff); } } fprintf(stderr, "Handshaking successful\n"); } /* -------------------------------------------------- */ void skipchars(char **s) { while(*s) { if (! strcmp(*s,"--seven_in")) linecheck_mask = 127; else skip[atoi(*s)] = 1; s++; } } /* -------------------------------------------------- */ void bum(char *s) { int i; for (i=0; i