home *** CD-ROM | disk | FTP | other *** search
- /*
- * SLIP routines
- *
- * new with NCSA/BYU Telnet version 2.4.15
- *
- * by Jim Logan Feb 1992
- *
- */
-
- #include <Dialogs.h>
- #include <memory.h>
- #include <OSUtils.h>
- #include <string.h>
-
- #include "configrec.h"
- #include "protocol.h"
- #include "ip.h"
- #include "data.h"
- #include "wind.h"
-
- #include "maclook.h"
- #include "menu.h"
- #include "netevent.h"
- #include "ser.h"
-
- #define input_size 8192
- #define input_buf_size 12288
- #define output_buf_size 8192
- #define SLIP_IN_BUFS 64
-
- #define SLIP_END 0xc0
- #define SLIP_ESC 0xdb
- #define SLIP_ESC_END 0334
- #define SLIP_ESC_ESC 0335
-
- static char slip_end = 0xc0;
- static char slip_esc_end[] = { 0xdb,0xdc };
- static char slip_esc_esc[] = { 0xdb,0xdd };
-
- short
- old_received = 0,
- received = 0,
- slipfirstbuf = 0,
- sliplastbuf = 0;
-
- extern WindRec *screens; /* From "maclook.c" */
-
- extern short slip_connection;
-
- extern unsigned char SLIP_ip_number[];
-
- unsigned char *slipinptr[SLIP_IN_BUFS],*slipinbuf,*slipoutbuf;
-
-
- initslip() {
- long mysize;
- mysize = input_buf_size;
- slipinbuf = (unsigned char *) NewPtr(mysize);
- mysize = output_buf_size;
- slipoutbuf = (unsigned char *) NewPtr(mysize);
- slipinptr[0] = slipinbuf;
- }
-
-
- switchtoslip(pnum) int pnum; {
- struct port *p;
- int slipscrn;
-
- if (pnum < 0 || pnum >= NPORTS)
- return;
-
- if (NULL == (p = portlist[pnum]))
- return;
-
- p->state = SCLOSED;
- p->in.port = p->out.port = 0;
-
- slip_connection = 1;
-
- /* Close the serial connection, and require the operator
- to open SLIP sessions with the "Open" function
- under the "File" menu. */
-
- slipscrn = WindByPort(pnum);
- if (slipscrn >= 0)
- destroyport(slipscrn);
-
- setupport(0); /* Open a connection, maybe even SLIP */
- }
-
-
- int SLIPdlayersend(unsigned char *ptr,int size) {
- int pos;
-
- ptr += sizeof(DLAYER);
- size -= sizeof(DLAYER);
- pos = 1;
- slipoutbuf[0] = slip_end;
- while (size > 0) {
- switch (*ptr) {
- case SLIP_END:
- slipoutbuf[pos++] = slip_esc_end[0];
- slipoutbuf[pos++] = slip_esc_end[1];
- break;
- case SLIP_ESC:
- slipoutbuf[pos++] = slip_esc_esc[0];
- slipoutbuf[pos++] = slip_esc_esc[1];
- break;
- default:
- slipoutbuf[pos++] = *ptr;
- }
- ptr++;
- size--;
- }
- slipoutbuf[pos++] = slip_end;
- write_serial(slipoutbuf,pos);
- return(size);
- }
-
-
- SLIPreceive(unsigned char *ptr,int size) {
- while (size > 0) {
- switch (*ptr) {
- case SLIP_END:
-
- if (received != old_received) {
-
- /* Don't allow the IP header to begin on /* BYU 2.4.19 */
- /* an odd byte or MacPlus will crash. /* BYU 2.4.19 */
- if (received > input_size)
- received = 0;
- else if (received & 1) /* BYU 2.4.19 */
- received++; /* BYU 2.4.19 */
-
- sliplastbuf++;
- if (sliplastbuf >= SLIP_IN_BUFS)
- sliplastbuf = 0;
-
- /* Prepare the next buffer space */
- slipinptr[sliplastbuf] = slipinbuf + received;
-
- if ((slipinbuf + received) == slipinptr[slipfirstbuf])
- SysBeep(4); /* Buffer overflow/overrun */
-
- old_received = received;
- }
- break;
- case SLIP_ESC:
- size--;
- if (size <= 0)
- return;
- ptr++;
- switch (*ptr) {
- case SLIP_ESC_END:
- if (received < input_size)
- slipinbuf[received++] = SLIP_END;
- break;
- case SLIP_ESC_ESC:
- if (received < input_size)
- slipinbuf[received++] = SLIP_ESC;
- break;
- default:
- slipinbuf[received++] = *ptr; /* Hmmmm, questionable! */
- break;
- }
- break;
- default:
- if (received < input_buf_size)
- slipinbuf[received++] = *ptr;
- }
- size--;
- ptr++;
- }
- }
-
-
- int SLIPdemux(int all) {
- #pragma unused(all)
- int nmuxed;
-
- nmuxed = 0;
- while (slipfirstbuf != sliplastbuf) {
- ipinterpret((IPKT *)(slipinptr[slipfirstbuf] - sizeof(DLAYER)),FROM_SLIP);
- slipfirstbuf++;
- if (slipfirstbuf >= SLIP_IN_BUFS)
- slipfirstbuf = 0;
- nmuxed++;
- }
-
- return(nmuxed);
- }
-