亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? slhc.c

?? 這是新華龍(www.xhl.xom.xn)開發(fā)的
?? C
字號:
/*
 * Routines to compress and uncompress tcp packets (for transmission
 * over low speed serial lines).
 */

#include "global.h"
#include "mbuf.h"
#include "internet.h"
#include "ip.h"
#include "tcp.h"
#include "slhc.h"

static uint8 *encode(uint8 *cp,uint16 n);
static long decode(struct mbuf **bpp);


/* Initialize compression data structure
 *	slots must be in range 0 to 255 (zero meaning no compression)
 */
struct slcompress *
slhc_init(rslots,tslots)
int rslots;
int tslots;
{
	register uint16 i;
	register struct cstate *ts;
	struct slcompress *comp;

	comp = callocw( 1, sizeof(struct slcompress) );

	if ( rslots > 0  &&  rslots < 256 ) {
		comp->rstate = callocw( rslots, sizeof(struct cstate) );
		comp->rslot_limit = rslots - 1;
	}

	if ( tslots > 0  &&  tslots < 256 ) {
		comp->tstate = callocw( tslots, sizeof(struct cstate) );
		comp->tslot_limit = tslots - 1;
	}

	comp->xmit_oldest = 0;
	comp->xmit_current = 255;
	comp->recv_current = 255;

	if ( tslots > 0 ) {
		ts = comp->tstate;
		for(i = comp->tslot_limit; i > 0; --i){
			ts[i].this = i;
			ts[i].next = &(ts[i - 1]);
		}
		ts[0].next = &(ts[comp->tslot_limit]);
		ts[0].this = 0;
	}
	return comp;
}


/* Free a compression data structure */
void
slhc_free(comp)
struct slcompress *comp;
{
	if ( comp == NULL )
		return;

	if ( comp->rstate != NULL )
		free( comp->rstate );

	if ( comp->tstate != NULL )
		free( comp->tstate );

	free( comp );
}


/* Encode a number */
static uint8 *
encode(cp,n)
register uint8 *cp;
uint16 n;
{
	if(n >= 256 || n == 0){
		*cp++ = 0;
		cp = put16(cp,n);
	} else {
		*cp++ = n;
	}
	return cp;
}

/* Decode a number */
static long
decode(bpp)
struct mbuf **bpp;
{
	register int x;

	x = PULLCHAR(bpp);
	if(x == 0){
		return pull16(bpp);	/* pull16 returns -1 on error */
	} else {
		return (long)x;		/* -1 if PULLCHAR returned error */
	}
}

int
slhc_compress(comp, bpp, compress_cid)
struct slcompress *comp;
struct mbuf **bpp;
int compress_cid;
{
	register struct cstate *ocs = &(comp->tstate[comp->xmit_oldest]);
	register struct cstate *lcs = ocs;
	register struct cstate *cs = lcs->next;
	register uint16 hlen,iplen;
	register struct tcp *oth;
	register unsigned long deltaS, deltaA;
	register uint16 changes = 0;
	uint8 new_seq[16];
	register uint8 *cp = new_seq;
	struct tcp th;
	struct ip iph;
	struct mbuf *copy;

	/* Copy TCP/IP header, allowing for worst-case options in both
	 * Using dup_p seemed to result in unexplained
	 * memory leaks -- but only some of the time. Must find out why.
	 */
/*	dup_p(&copy,*bpp,0,IPLEN+IP_MAXOPT+TCPLEN+TCP_MAXOPT); */
	copy = copy_p(*bpp,IPLEN+IP_MAXOPT+TCPLEN+TCP_MAXOPT);

	/* Peek at IP header */
	iplen = hlen = ntohip(&iph,&copy);

	/* Bail if this packet isn't TCP, or is an IP fragment */
	if(iph.protocol != TCP_PTCL || iph.offset != 0 || iph.flags.mf){
		/* Send as regular IP */
		if(iph.protocol != TCP_PTCL)
			comp->sls_o_nontcp++;
		else
			comp->sls_o_tcp++;
		free_p(&copy);
		return SL_TYPE_IP;
	}
	/* Extract TCP header */
	hlen += ntohtcp(&th,&copy);
	free_p(&copy);	/* Done with copy */

	/*  Bail if the TCP packet isn't `compressible' (i.e., ACK isn't set or
	 *  some other control bit is set, or has options).
	 */
	if(th.flags.syn || th.flags.fin || th.flags.rst || !th.flags.ack
	 || th.flags.mss || th.flags.wscale || th.flags.tstamp){
		/* TCP connection stuff; send as regular IP */
		comp->sls_o_tcp++;
		return SL_TYPE_IP;
	}
	/*
	 * Packet is compressible -- we're going to send either a
	 * COMPRESSED_TCP or UNCOMPRESSED_TCP packet.  Either way,
	 * we need to locate (or create) the connection state.
	 *
	 * States are kept in a circularly linked list with
	 * xmit_oldest pointing to the end of the list.  The
	 * list is kept in lru order by moving a state to the
	 * head of the list whenever it is referenced.  Since
	 * the list is short and, empirically, the connection
	 * we want is almost always near the front, we locate
	 * states via linear search.  If we don't find a state
	 * for the datagram, the oldest state is (re-)used.
	 */
	for ( ; ; ) {
		if( iph.source == cs->cs_ip.source
		 && iph.dest == cs->cs_ip.dest
		 && th.source == cs->cs_tcp.source
		 && th.dest == cs->cs_tcp.dest)
			goto found;

		/* if current equal oldest, at end of list */
		if ( cs == ocs )
			break;
		lcs = cs;
		cs = cs->next;
		comp->sls_o_searches++;
	};
	/*
	 * Didn't find it -- re-use oldest cstate.  Send an
	 * uncompressed packet that tells the other side what
	 * connection number we're using for this conversation.
	 *
	 * Note that since the state list is circular, the oldest
	 * state points to the newest and we only need to set
	 * xmit_oldest to update the lru linkage.
	 */
	comp->sls_o_misses++;
	comp->xmit_oldest = lcs->this;

	goto uncompressed;

found:
	/*
	 * Found it -- move to the front on the connection list.
	 */
	if(lcs == ocs) {
		/* found at most recently used */
	} else if (cs == ocs) {
		/* found at least recently used */
		comp->xmit_oldest = lcs->this;
	} else {
		/* more than 2 elements */
		lcs->next = cs->next;
		cs->next = ocs->next;
		ocs->next = cs;
	}

	/*
	 * Make sure that only what we expect to change changed.
	 * Check the following:
	 * IP protocol version, header length & type of service.
	 * The "Don't fragment" bit.
	 * The time-to-live field.
	 * The TCP header length.
	 * IP options, if any.
	 * TCP options, if any.
	 * If any of these things are different between the previous &
	 * current datagram, we send the current datagram `uncompressed'.
	 */
	oth = &cs->cs_tcp;

	if(iph.version != cs->cs_ip.version || iph.optlen != cs->cs_ip.optlen
	 || iph.tos != cs->cs_ip.tos
	 || iph.flags.df != cs->cs_ip.flags.df
	 || iph.ttl != cs->cs_ip.ttl
	 || (iph.optlen > 0 && memcmp(iph.options,cs->cs_ip.options,iph.optlen) != 0)){
		goto uncompressed;
	}
	/*
	 * Figure out which of the changing fields changed.  The
	 * receiver expects changes in the order: urgent, window,
	 * ack, seq (the order minimizes the number of temporaries
	 * needed in this section of code).
	 */
	if(th.flags.urg){
		deltaS = th.up;
		cp = encode(cp,deltaS);
		changes |= NEW_U;
	} else if(th.up != oth->up){
		/* argh! URG not set but urp changed -- a sensible
		 * implementation should never do this but RFC793
		 * doesn't prohibit the change so we have to deal
		 * with it. */
		goto uncompressed;
	}
	if((deltaS = th.wnd - oth->wnd) != 0){
		cp = encode(cp,deltaS);
		changes |= NEW_W;
	}
	if((deltaA = th.ack - oth->ack) != 0L){
		if(deltaA > 0x0000ffff)
			goto uncompressed;
		cp = encode(cp,deltaA);
		changes |= NEW_A;
	}
	if((deltaS = th.seq - oth->seq) != 0L){
		if(deltaS > 0x0000ffff)
			goto uncompressed;
		cp = encode(cp,deltaS);
		changes |= NEW_S;
	}

	switch(changes){
	case 0:	/* Nothing changed. If this packet contains data and the
		 * last one didn't, this is probably a data packet following
		 * an ack (normal on an interactive connection) and we send
		 * it compressed.  Otherwise it's probably a retransmit,
		 * retransmitted ack or window probe.  Send it uncompressed
		 * in case the other side missed the compressed version.
		 */
		if(iph.length != cs->cs_ip.length && cs->cs_ip.length == hlen)
			break;
		goto uncompressed;
	case SPECIAL_I:
	case SPECIAL_D:
		/* actual changes match one of our special case encodings --
		 * send packet uncompressed.
		 */
		goto uncompressed;
	case NEW_S|NEW_A:
		if(deltaS == deltaA &&
		    deltaS == cs->cs_ip.length - hlen){
			/* special case for echoed terminal traffic */
			changes = SPECIAL_I;
			cp = new_seq;
		}
		break;
	case NEW_S:
		if(deltaS == cs->cs_ip.length - hlen){
			/* special case for data xfer */
			changes = SPECIAL_D;
			cp = new_seq;
		}
		break;
	}
	deltaS = iph.id - cs->cs_ip.id;
	if(deltaS != 1){
		cp = encode(cp,deltaS);
		changes |= NEW_I;
	}
	if(th.flags.psh)
		changes |= TCP_PUSH_BIT;
	/* Grab the cksum before we overwrite it below.  Then update our
	 * state with this packet's header.
	 */
	deltaA = th.checksum;
	ASSIGN(cs->cs_ip,iph);
	ASSIGN(cs->cs_tcp,th);
	/* We want to use the original packet as our compressed packet.
	 * (cp - new_seq) is the number of bytes we need for compressed
	 * sequence numbers.  In addition we need one byte for the change
	 * mask, one for the connection id and two for the tcp checksum.
	 * So, (cp - new_seq) + 4 bytes of header are needed.
	 */
	deltaS = cp - new_seq;
	pullup(bpp,NULL,hlen);		/* Strip TCP/IP headers */
	if(compress_cid == 0 || comp->xmit_current != cs->this){
		pushdown(bpp,NULL,deltaS + 4);
		cp = (*bpp)->data;
		*cp++ = changes | NEW_C;
		*cp++ = cs->this;
		comp->xmit_current = cs->this;
	} else {
		pushdown(bpp,NULL,deltaS + 3);
		cp = (*bpp)->data;
		*cp++ = changes;
	}
	cp = put16(cp,(uint16)deltaA);	/* Write TCP checksum */
	memcpy(cp,new_seq,deltaS);	/* Write list of deltas */
	comp->sls_o_compressed++;
	return SL_TYPE_COMPRESSED_TCP;

	/* Update connection state cs & send uncompressed packet (i.e.,
	 * a regular ip/tcp packet but with the 'conversation id' we hope
	 * to use on future compressed packets in the protocol field).
	 */
uncompressed:
	iph.protocol = cs->this;
	ASSIGN(cs->cs_ip,iph);
	ASSIGN(cs->cs_tcp,th);
	comp->xmit_current = cs->this;
	comp->sls_o_uncompressed++;
	pullup(bpp,NULL,iplen);	/* Strip old IP header */
	htonip(&iph,bpp,IP_CS_OLD);	/* replace with new one */
	return SL_TYPE_UNCOMPRESSED_TCP;
}


int
slhc_uncompress(comp, bpp)
struct slcompress *comp;
struct mbuf **bpp;
{
	register int changes;
	long x;
	register struct tcp *thp;
	register struct cstate *cs;
	int len;

	if(bpp == NULL){
		comp->sls_i_error++;
		return 0;
	}
	/* We've got a compressed packet; read the change byte */
	comp->sls_i_compressed++;
	if(len_p(*bpp) < 3){
		comp->sls_i_error++;
		return 0;
	}
	changes = PULLCHAR(bpp);	/* "Can't fail" */
	if(changes & NEW_C){
		/* Make sure the state index is in range, then grab the state.
		 * If we have a good state index, clear the 'discard' flag.
		 */
		x = PULLCHAR(bpp);	/* Read conn index */
		if(x < 0 || x > comp->rslot_limit)
			goto bad;

		comp->flags &=~ SLF_TOSS;
		comp->recv_current = x;
	} else {
		/* this packet has an implicit state index.  If we've
		 * had a line error since the last time we got an
		 * explicit state index, we have to toss the packet. */
		if(comp->flags & SLF_TOSS){
			comp->sls_i_tossed++;
			return 0;
		}
	}
	cs = &comp->rstate[comp->recv_current];
	thp = &cs->cs_tcp;

	if((x = pull16(bpp)) == -1)	/* Read the TCP checksum */
		goto bad;
	thp->checksum = x;

	thp->flags.psh = (changes & TCP_PUSH_BIT) ? 1 : 0;

	switch(changes & SPECIALS_MASK){
	case SPECIAL_I:		/* Echoed terminal traffic */
		{
		register uint16 i;
		i = cs->cs_ip.length;
		i -= (cs->cs_ip.optlen + IPLEN + TCPLEN);
		thp->ack += i;
		thp->seq += i;
		}
		break;

	case SPECIAL_D:			/* Unidirectional data */
		thp->seq += cs->cs_ip.length - (cs->cs_ip.optlen +IPLEN + TCPLEN);
		break;

	default:
		if(changes & NEW_U){
			thp->flags.urg = 1;
			if((x = decode(bpp)) == -1)
				goto bad;
			thp->up = x;
		} else
			thp->flags.urg = 0;
		if(changes & NEW_W){
			if((x = decode(bpp)) == -1)
				goto bad;
			thp->wnd += x;
		}
		if(changes & NEW_A){
			if((x = decode(bpp)) == -1)
				goto bad;
			thp->ack += x;
		}
		if(changes & NEW_S){
			if((x = decode(bpp)) == -1)
				goto bad;
			thp->seq += x;
		}
		break;
	}
	if(changes & NEW_I){
		if((x = decode(bpp)) == -1)
			goto bad;
		cs->cs_ip.id += x;
	} else
		cs->cs_ip.id++;

	/*
	 * At this point, bpp points to the first byte of data in the
	 * packet.  Put the reconstructed TCP and IP headers back on the
	 * packet.  Recalculate IP checksum (but not TCP checksum).
	 */
	len = len_p(*bpp) + IPLEN + TCPLEN + cs->cs_ip.optlen;
	cs->cs_ip.length = len;

	htontcp(thp,bpp,0,0);
	htonip(&cs->cs_ip,bpp,IP_CS_NEW);
	return len;
bad:
	comp->sls_i_error++;
	return slhc_toss( comp );
}


int
slhc_remember(comp, bpp)
struct slcompress *comp;
struct mbuf **bpp;
{
	register struct cstate *cs;
	struct ip iph;
	struct tcp th;
	uint16 len;
	uint16 hdrlen;
	int slot;

	if(bpp == NULL){
		comp->sls_i_error++;
		return slhc_toss(comp);
	}

	/* Sneak a peek at the IP header's IHL field to find its length */
	hdrlen = ((*bpp)->data[0] & 0xf) << 2;
	if(hdrlen < IPLEN){
		/* The IP header length field is too small to be valid */
		comp->sls_i_error++;
		return slhc_toss(comp);
	}
	len = len_p(*bpp);	/* Actual length of whole packet */
	ntohip(&iph,bpp);	/* Extract IP header */
	/* Verify indicated length <= actual length */
	if(iph.length > len){
		/* Packet has been truncated, or header is garbage */
		comp->sls_i_error++;
		return slhc_toss(comp);
	}
	/* Verify conn ID */
	slot = iph.protocol;
	if(slot > comp->rslot_limit){
		/* Out of range */
		comp->sls_i_error++;
		return slhc_toss(comp);
	}
	iph.protocol = TCP_PTCL;	/* Replace conn ID with TCP_PTCL */

	/* Extract TCP header and replace both headers
	 * Neither header checksum is recalculated
	 */
	ntohtcp(&th,bpp);
	htontcp(&th,bpp,0,0);
	htonip(&iph,bpp,IP_CS_OLD);

	/* Checksum IP header (now that protocol field is TCP again) */
	if(cksum(NULL,*bpp,hdrlen) != 0){
		/* Bad IP header checksum; discard */
		comp->sls_i_error++;
		return slhc_toss(comp);
	}
	/* Update local state */
	comp->recv_current = slot;
	cs = &comp->rstate[slot];
	comp->flags &=~ SLF_TOSS;

	ASSIGN(cs->cs_ip,iph);
	ASSIGN(cs->cs_tcp,th);
	comp->sls_i_uncompressed++;
	return len;
}


int
slhc_toss(comp)
struct slcompress *comp;
{
	if ( comp == NULL )
		return 0;

	comp->flags |= SLF_TOSS;
	return 0;
}

void
slhc_i_status(comp)
struct slcompress *comp;
{
	if (comp != NULL) {
		printf("\t%10ld Cmp,"
			" %10ld Uncmp,"
			" %10ld Bad, "
			" %10ld Tossed\n",
			comp->sls_i_compressed,
			comp->sls_i_uncompressed,
			comp->sls_i_error,
			comp->sls_i_tossed);
	}
}


void
slhc_o_status(comp)
struct slcompress *comp;
{
	if (comp != NULL) {
		printf("\t%10ld Cmp,"
			" %10ld Uncmp,"
			" %10ld AsIs,"
			" %10ld NotTCP\n",
			comp->sls_o_compressed,
			comp->sls_o_uncompressed,
			comp->sls_o_tcp,
			comp->sls_o_nontcp);
		printf("\t%10ld Searches,"
			" %10ld Misses\n",
			comp->sls_o_searches,
			comp->sls_o_misses);
	}
}


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产午夜精品久久久久久免费视 | 成人午夜电影网站| 国产精品一级片| 国产精品嫩草影院com| 欧美精品亚洲二区| 99精品欧美一区二区三区小说 | 亚洲精品成a人| 久久久久久久久久久久久女国产乱| 色婷婷综合激情| 成人午夜av电影| 久久精品国产一区二区三| 一区二区三区四区在线免费观看| 久久久国产精品不卡| 51精品国自产在线| 欧洲精品在线观看| 99热99精品| 国产99精品国产| 精品影院一区二区久久久| 亚洲成人久久影院| 一区二区三区鲁丝不卡| 国产精品的网站| 国产精品欧美一级免费| 久久一夜天堂av一区二区三区| 欧美日韩激情一区| 欧美性猛交xxxxxxxx| 91麻豆免费看| 色中色一区二区| 91亚洲精华国产精华精华液| 国产成人av在线影院| 国产精品一二三四| 国产九九视频一区二区三区| 国产综合色精品一区二区三区| 麻豆国产一区二区| 久久不见久久见免费视频1| 蜜桃av一区二区三区电影| 在线视频观看一区| 一本高清dvd不卡在线观看| 成人黄色小视频在线观看| 国产成人精品一区二区三区四区| 国产在线视频不卡二| 国产老肥熟一区二区三区| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲午夜免费电影| 香蕉久久一区二区不卡无毒影院| 亚洲午夜电影在线| 婷婷六月综合网| 免费日本视频一区| 蜜臀av一区二区在线免费观看| 日本中文一区二区三区| 久久成人久久爱| 国产成人综合自拍| 成人免费观看视频| 色94色欧美sute亚洲线路二| 欧美色区777第一页| 91精品欧美一区二区三区综合在| 日韩欧美国产午夜精品| 久久久久久久久久久电影| 日本一区二区久久| 亚洲欧美激情小说另类| 亚洲国产精品自拍| 久久国产生活片100| 国产成人自拍网| 色av综合在线| 欧美一区二区三区免费| 国产亚洲精久久久久久| 亚洲美女区一区| 日韩电影免费在线观看网站| 国产毛片精品国产一区二区三区| 成人av网站在线观看| 欧美日韩另类一区| 26uuuu精品一区二区| 亚洲视频在线一区观看| 日韩国产成人精品| www.色综合.com| 欧美高清视频不卡网| 久久精品一区二区三区av| 亚洲精品成a人| 精品一区二区在线播放| 色屁屁一区二区| 精品国产在天天线2019| 亚洲女同一区二区| 久久国产精品无码网站| 色悠悠久久综合| 精品第一国产综合精品aⅴ| 亚洲素人一区二区| 久久国产生活片100| 日本道精品一区二区三区 | 亚洲精品自拍动漫在线| 毛片av一区二区| 色综合久久久久| 免费成人av在线播放| 成人高清在线视频| 欧美一区2区视频在线观看| 国产精品成人在线观看| 男女性色大片免费观看一区二区| av成人动漫在线观看| 日韩欧美中文字幕公布| 一区二区三区四区在线免费观看 | 国产欧美日本一区视频| 偷拍亚洲欧洲综合| 91在线高清观看| 国产网红主播福利一区二区| 日日夜夜免费精品视频| 91论坛在线播放| 中文字幕欧美日韩一区| 精品制服美女丁香| 7878成人国产在线观看| 悠悠色在线精品| 99视频国产精品| 国产日韩欧美精品电影三级在线| 秋霞影院一区二区| 欧美日韩情趣电影| 亚洲精品国产第一综合99久久| 国产 日韩 欧美大片| 久久综合九色综合97_久久久| 视频一区欧美日韩| 精品视频在线免费观看| 亚洲精选免费视频| 91美女精品福利| 国产精品国产a| 成人深夜在线观看| 中文字幕精品综合| 国产精品伊人色| 久久亚洲精品国产精品紫薇| 理论电影国产精品| 日韩午夜电影在线观看| 日韩二区在线观看| 欧美一区二区三区电影| 性做久久久久久久久| 欧美人与性动xxxx| 午夜av电影一区| 666欧美在线视频| 青草国产精品久久久久久| 欧美一卡在线观看| 蜜臀av性久久久久蜜臀av麻豆| 在线不卡a资源高清| 日韩制服丝袜av| 欧美一级一级性生活免费录像| 日本在线观看不卡视频| 日韩欧美的一区二区| 美女脱光内衣内裤视频久久网站| 日韩一二在线观看| 激情文学综合插| 国产片一区二区| caoporm超碰国产精品| 自拍偷拍欧美精品| 在线视频你懂得一区| 午夜精品久久久久久久99樱桃| 欧美精品视频www在线观看| 丝袜美腿一区二区三区| 欧美电影免费提供在线观看| 国产露脸91国语对白| 国产欧美日韩不卡| 色婷婷久久综合| 日本欧美韩国一区三区| 久久这里都是精品| www.亚洲人| 五月天激情综合网| 日韩精品在线一区二区| 国产suv精品一区二区三区| 日韩理论片中文av| 在线成人午夜影院| 国产乱码一区二区三区| 综合久久国产九一剧情麻豆| 欧美色窝79yyyycom| 精品一区二区三区在线播放 | 3d成人动漫网站| 国产美女久久久久| 亚洲精品视频在线看| 777精品伊人久久久久大香线蕉| 狠狠色丁香婷婷综合| 亚洲另类春色国产| 欧美成人猛片aaaaaaa| 99久久伊人精品| 日韩在线一区二区| 中文字幕欧美日本乱码一线二线| 色猫猫国产区一区二在线视频| 男男视频亚洲欧美| 最新成人av在线| 欧美一级欧美三级在线观看| 成人精品一区二区三区中文字幕 | 粉嫩久久99精品久久久久久夜| 一区二区三区久久| 欧美精品一区二区久久久| 色综合天天综合色综合av| 久久疯狂做爰流白浆xx| 亚洲欧美一区二区三区极速播放 | 中文字幕日韩精品一区| 91精品国产品国语在线不卡| 不卡一区在线观看| 毛片一区二区三区| 亚洲最大成人网4388xx| 国产欧美日产一区| 日韩欧美国产一区在线观看| 在线精品视频一区二区三四| 国产成人在线观看| 日本不卡中文字幕| 洋洋av久久久久久久一区| 国产欧美一区二区精品久导航| 制服.丝袜.亚洲.中文.综合|