libexec/telnetd/utility.c
/*
 * netclear()
 *
 *	We are about to do a TELNET SYNCH operation.  Clear
 * the path to the network.
 *
 *	Things are a bit tricky since we may have sent the first
 * byte or so of a previous TELNET command into the network.
 * So, we have to scan the network buffer from the beginning
 * until we are up to where we want to be.
 *
 *	A side effect of what we do, just to keep things
 * simple, is to clear the urgent data pointer.  The principal
 * caller should be setting the urgent data pointer AFTER calling
 * us in any case.
 */
netclear()
We are about to do a TELNET SYNCH operation.  Clear
the path to the network.

Things are a bit tricky since we may have sent the first
byte or so of a previous TELNET command into the network.
So, we have to scan the network buffer from the beginning
until we are up to where we want to be.

A side effect of what we do, just to keep things
simple, is to clear the urgent data pointer.  The principal
caller should be setting the urgent data pointer AFTER calling
us in any case.
netclear () We are about to do a TELNET SYNCH operation . Clear the path to the network . Things are a bit tricky since we may have sent the first byte or so of a previous TELNET command into the network . So we have to scan the network buffer from the beginning until we are up to where we want to be . A side effect of what we do just to keep things simple is to clear the urgent data pointer . The principal caller should be setting the urgent data pointer AFTER calling us in any case .
void
netclear()
{
    register char *thisitem, *next;
    char *good;
#define	wewant(p)	((nfrontp > p) && ((*p&0xff) == IAC) && \
				((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
#ifdef	ENCRYPTION
    thisitem = nclearto > netobuf ? nclearto : netobuf;
#else	
    thisitem = netobuf;
#endif	
    while ((next = nextitem(thisitem)) <= nbackp) {
	thisitem = next;
    }
#ifdef	ENCRYPTION
    good = nclearto > netobuf ? nclearto : netobuf;
#else	
    good = netobuf;	
#endif	
    while (nfrontp > thisitem) {
	if (wewant(thisitem)) {
	    int length;
	    next = thisitem;
	    do {
		next = nextitem(next);
	    } while (wewant(next) && (nfrontp > next));
	    length = next-thisitem;
	    memmove(good, thisitem, length);
	    good += length;
	    thisitem = next;
	} else {
	    thisitem = nextitem(thisitem);
	}
    }
    nbackp = netobuf;
    nfrontp = good;		
    neturg = 0;
}
void netclear ( ) { register char * thisitem , * next ; char * good ; #define wewant ( p ) 	((nfrontp > p) && ((*p&0xff) == IAC) && \
				((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) #ifdef ENCRYPTION thisitem = nclearto > netobuf ? nclearto : netobuf ; #else thisitem = netobuf ; #endif while ( ( next = nextitem ( thisitem ) ) <= nbackp ) { thisitem = next ; } #ifdef ENCRYPTION good = nclearto > netobuf ? nclearto : netobuf ; #else good = netobuf ; #endif while ( nfrontp > thisitem ) { if ( wewant ( thisitem ) ) { int length ; next = thisitem ; do { next = nextitem ( next ) ; } while ( wewant ( next ) && ( nfrontp > next ) ) ; length = next - thisitem ; memmove ( good , thisitem , length ) ; good += length ; thisitem = next ; } else { thisitem = nextitem ( thisitem ) ; } } nbackp = netobuf ; nfrontp = good ; neturg = 0 ; }
netclear()
      We are about to do a TELNET SYNCH operation.
netclear () We are about to do a TELNET SYNCH operation .
/* ENCRYPTION */ /* ENCRYPTION */ /* Now, thisitem is first before/at boundary. */ /* ENCRYPTION */ /* where the good bytes go */ /* ENCRYPTION */ /* next byte to be sent */