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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ip.c

?? 用于底層開發的TCPIP協議棧源代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
#undef SIM
/* Upper half of IP, consisting of send/receive primitives, including
 * fragment reassembly, for higher level protocols.
 * Not needed when running as a standalone gateway.
 */
#include "global.h"
#include "mbuf.h"
#include "timer.h"
#include "internet.h"
#include "netuser.h"
#include "iface.h"
#include "pktdrvr.h"
#include "ip.h"
#include "icmp.h"

static int fraghandle(struct ip *ip,struct mbuf **bpp);
static void ip_timeout(void *arg);
static void free_reasm(struct reasm *rp);
static void freefrag(struct frag *fp);
static struct reasm *lookup_reasm(struct ip *ip);
static struct reasm *creat_reasm(struct ip *ip);
static struct frag *newfrag(uint16 offset,uint16 last,struct mbuf **bpp);
void ttldec(struct iface *ifp);

struct mib_entry Ip_mib[20] = {
	"",			0,
	"ipForwarding",		1,
	"ipDefaultTTL",		MAXTTL,
	"ipInReceives",		0,
	"ipInHdrErrors",	0,
	"ipInAddrErrors",	0,
	"ipForwDatagrams",	0,
	"ipInUnknownProtos",	0,
	"ipInDiscards",		0,
	"ipInDelivers",		0,
	"ipOutRequests",	0,
	"ipOutDiscards",	0,
	"ipOutNoRoutes",	0,
	"ipReasmTimeout",	TLB,
	"ipReasmReqds",		0,
	"ipReasmOKs",		0,
	"ipReasmFails",		0,
	"ipFragOKs",		0,
	"ipFragFails",		0,
	"ipFragCreates",	0,
};

struct reasm *Reasmq;
uint16 Id_cntr = 0;	/* Datagram serial number */
static struct raw_ip *Raw_ip;
int Ip_trace = 0;

#define	INSERT	0
#define	APPEND	1
#define	PREPEND	2

/* Send an IP datagram. Modeled after the example interface on p 32 of
 * RFC 791
 */
int
ip_send(
int32 source,			/* source address */
int32 dest,			/* Destination address */
char protocol,			/* Protocol */
char tos,			/* Type of service */
char ttl,			/* Time-to-live */
struct mbuf **bpp,		/* Data portion of datagram */
uint16 length,			/* Optional length of data portion */
uint16 id,			/* Optional identification */
char df				/* Don't-fragment flag */
){
	struct ip ip;			/* IP header */

	ipOutRequests++;

	if(bpp == NULL)
		return -1;
	if(source == INADDR_ANY)
		source = locaddr(dest);
	if(length == 0 && *bpp != NULL)
		length = len_p(*bpp);
	if(id == 0)
		id = Id_cntr++;
	if(ttl == 0)
		ttl = ipDefaultTTL;

	/* Fill in IP header */
	ip.version = IPVERSION;
	ip.tos = tos;
	ip.length = IPLEN + length;
	ip.id = id;
	ip.offset = 0;
	ip.flags.mf = 0;
	ip.flags.df = df;
	ip.flags.congest = 0;
	ip.ttl = ttl;
	ip.protocol = protocol;
	ip.source = source;
	ip.dest = dest;
	ip.optlen = 0;
	if(Ip_trace)
		dumpip(NULL,&ip,*bpp,0);

	htonip(&ip,bpp,IP_CS_NEW);
	if(ismyaddr(ip.dest)){
		/* Pretend it has been sent by the loopback interface before
		 * it appears in the receive queue
		 */
#ifdef	SIM
		net_sim(bpp);
#else
		net_route(&Loopback,bpp);
#endif
		Loopback.ipsndcnt++;
		Loopback.rawsndcnt++;
		Loopback.lastsent = secclock();
	} else
		net_route(NULL,bpp);
	return 0;
}

/* Reassemble incoming IP fragments and dispatch completed datagrams
 * to the proper transport module
 */
void
ip_recv(
struct iface *iface,	/* Incoming interface */
struct ip *ip,		/* Extracted IP header */
struct mbuf **bpp,	/* Data portion */
int rxbroadcast,	/* True if received on subnet broadcast address */
int32 spi		/* Security association, if any */
){
	/* Function to call with completed datagram */
	register struct raw_ip *rp;
	struct mbuf *bp1;
	int rxcnt = 0;
	register struct iplink *ipp;

	/* If we have a complete packet, call the next layer
	 * to handle the result. Note that fraghandle passes back
	 * a length field that does NOT include the IP header
	 */
	if(bpp == NULL || fraghandle(ip,bpp) == -1)
		return;		/* Not done yet */

	/* Trim data segment if necessary. */
	trim_mbuf(bpp,ip->length - (IPLEN + ip->optlen));

	ipInDelivers++;
	if(Ip_trace)
		dumpip(iface,ip,*bpp,spi);

	for(rp = Raw_ip;rp != NULL;rp = rp->next){
		if(rp->protocol != ip->protocol)
			continue;
		rxcnt++;
		/* Duplicate the data portion, and put the header back on */
		dup_p(&bp1,*bpp,0,len_p(*bpp));
		if(bp1 != NULL){
			htonip(ip,&bp1,IP_CS_OLD);
			enqueue(&rp->rcvq,&bp1);
			if(rp->r_upcall != NULL)
				(*rp->r_upcall)(rp);
		} else {
			free_p(&bp1);
		}
	}
	/* Look it up in the transport protocol table */
	for(ipp = Iplink;ipp->funct != NULL;ipp++){
		if(ipp->proto == ip->protocol)
			break;
	}
	if(ipp->funct != NULL){
		/* Found, call transport protocol */
		(*ipp->funct)(iface,ip,bpp,rxbroadcast,spi);
	} else {
		/* Not found */
		if(rxcnt == 0){
			/* Send an ICMP Protocol Unknown response... */
			ipInUnknownProtos++;
			/* ...unless it's a broadcast */
			if(!rxbroadcast){
				icmp_output(ip,*bpp,ICMP_DEST_UNREACH,
				 ICMP_PROT_UNREACH,NULL);
			}
		}
		free_p(bpp);
	}
}
/* Handle IP packets encapsulated inside IP */
void
ipip_recv(
struct iface *iface,	/* Incoming interface */
struct ip *ip,		/* Extracted IP header */
struct mbuf **bpp,	/* Data portion */
int rxbroadcast,	/* True if received on subnet broadcast address */
int32 spi
){
	net_route(&Encap,bpp);
}

/* Process IP datagram fragments
 * If datagram is complete, return its length (MINUS header);
 * otherwise return -1
 */
static int
fraghandle(
struct ip *ip,		/* IP header, host byte order */
struct mbuf **bpp	/* The fragment itself */
){
	register struct reasm *rp; /* Pointer to reassembly descriptor */
	struct frag *lastfrag,*nextfrag,*tfp;
	struct mbuf *tbp;
	uint16 i;
	uint16 last;		/* Index of first byte beyond fragment */

	last = ip->offset + ip->length - (IPLEN + ip->optlen);

	rp = lookup_reasm(ip);
	if(ip->offset == 0 && !ip->flags.mf){
		/* Complete datagram received. Discard any earlier fragments */
		if(rp != NULL){
			free_reasm(rp);
			ipReasmOKs++;
		}
		return ip->length;
	}
	ipReasmReqds++;
	if(rp == NULL){
		/* First fragment; create new reassembly descriptor */
		if((rp = creat_reasm(ip)) == NULL){
			/* No space for descriptor, drop fragment */
			ipReasmFails++;
			free_p(bpp);
			return -1;
		}
	}
	/* Keep restarting timer as long as we keep getting fragments */
	stop_timer(&rp->timer);
	start_timer(&rp->timer);

	/* If this is the last fragment, we now know how long the
	 * entire datagram is; record it
	 */
	if(!ip->flags.mf)
		rp->length = last;

	/* Set nextfrag to the first fragment which begins after us,
	 * and lastfrag to the last fragment which begins before us
	 */
	lastfrag = NULL;
	for(nextfrag = rp->fraglist;nextfrag != NULL;nextfrag = nextfrag->next){
		if(nextfrag->offset > ip->offset)
			break;
		lastfrag = nextfrag;
	}
	/* Check for overlap with preceeding fragment */
	if(lastfrag != NULL  && ip->offset < lastfrag->last){
		/* Strip overlap from new fragment */
		i = lastfrag->last - ip->offset;
		pullup(bpp,NULL,i);
		if(*bpp == NULL)
			return -1;	/* Nothing left */
		ip->offset += i;
	}
	/* Look for overlap with succeeding segments */
	for(; nextfrag != NULL; nextfrag = tfp){
		tfp = nextfrag->next;	/* save in case we delete fp */

		if(nextfrag->offset >= last)
			break;	/* Past our end */
		/* Trim the front of this entry; if nothing is
		 * left, remove it.
		 */
		i = last - nextfrag->offset;
		pullup(&nextfrag->buf,NULL,i);
		if(nextfrag->buf == NULL){
			/* superseded; delete from list */
			if(nextfrag->prev != NULL)
				nextfrag->prev->next = nextfrag->next;
			else
				rp->fraglist = nextfrag->next;
			if(tfp->next != NULL)
				nextfrag->next->prev = nextfrag->prev;
			freefrag(nextfrag);
		} else
			nextfrag->offset = last;
	}
	/* Lastfrag now points, as before, to the fragment before us;
	 * nextfrag points at the next fragment. Check to see if we can
	 * join to either or both fragments.
	 */
	i = INSERT;
	if(lastfrag != NULL && lastfrag->last == ip->offset)
		i |= APPEND;
	if(nextfrag != NULL && nextfrag->offset == last)
		i |= PREPEND;
	switch(i){
	case INSERT:	/* Insert new desc between lastfrag and nextfrag */
		tfp = newfrag(ip->offset,last,bpp);
		tfp->prev = lastfrag;
		tfp->next = nextfrag;
		if(lastfrag != NULL)
			lastfrag->next = tfp;	/* Middle of list */
		else
			rp->fraglist = tfp;	/* First on list */
		if(nextfrag != NULL)
			nextfrag->prev = tfp;
		break;
	case APPEND:	/* Append to lastfrag */
		append(&lastfrag->buf,bpp);
		lastfrag->last = last;	/* Extend forward */
		break;
	case PREPEND:	/* Prepend to nextfrag */
		tbp = nextfrag->buf;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧洲综合另类在线| 成年人国产精品| 色噜噜久久综合| 亚洲欧美日本韩国| 国产欧美一区二区三区沐欲 | 国产激情偷乱视频一区二区三区| 2欧美一区二区三区在线观看视频| 国产尤物一区二区在线| 中文字幕日韩一区| 91精品国产色综合久久不卡蜜臀| 国产精品亚洲а∨天堂免在线| 亚洲欧洲综合另类在线| 一区二区在线观看视频| 久久久国产精华| 欧美二区乱c少妇| 99久久er热在这里只有精品15| 麻豆精品一区二区| 亚洲综合在线观看视频| 91精品国产一区二区| 日韩精品一区二区三区视频在线观看 | 欧美性感一类影片在线播放| 国精品**一区二区三区在线蜜桃| 一区二区三区四区激情| 亚洲成人1区2区| 国产精品国产三级国产三级人妇| 91麻豆精品国产91久久久| av电影在线观看一区| 国产精品一品二品| 成人性生交大合| 国精产品一区一区三区mba桃花| 国产精品资源网| 91丨porny丨首页| 成人国产精品免费观看| 在线观看日韩精品| 色一情一乱一乱一91av| av在线播放成人| 欧美色中文字幕| 精品国一区二区三区| 91精品免费在线| 国产女同互慰高潮91漫画| 亚洲伦在线观看| 免费日本视频一区| 日韩电影在线一区二区| 三级欧美韩日大片在线看| 亚洲黄网站在线观看| 蜜桃久久av一区| 91在线视频官网| 精品国产一区二区三区久久影院 | 91精品免费在线观看| 久久精品夜色噜噜亚洲aⅴ| 在线成人免费观看| 亚洲国产激情av| 国产精品美女久久久久aⅴ国产馆| 久久精品一级爱片| 亚洲一区二区三区自拍| 黄页网站大全一区二区| 欧美色图12p| 日韩欧美国产不卡| 亚洲精品精品亚洲| 成人永久免费视频| 日韩欧美www| 亚洲一区二区影院| 色综合天天综合网国产成人综合天| 成人aaaa免费全部观看| 欧美va在线播放| 欧美国产成人在线| 久久国产精品无码网站| 风间由美中文字幕在线看视频国产欧美| 国产资源在线一区| 欧美一卡2卡三卡4卡5免费| 亚洲精选视频在线| 91视视频在线观看入口直接观看www | 欧美精品一区二区蜜臀亚洲| 天堂蜜桃一区二区三区| 在线视频国内一区二区| 国产精品久久看| 成人激情动漫在线观看| 国产视频亚洲色图| 国产成人综合网| 国产亚洲欧美在线| 国产成人aaaa| 欧美激情一二三区| av电影在线观看完整版一区二区| 国产精品天美传媒沈樵| 成人手机在线视频| 中文字幕综合网| 免费三级欧美电影| 日韩欧美国产一区二区三区 | 欧美xxxxxxxx| 欧美aaaaaa午夜精品| 91精品国产黑色紧身裤美女| 水蜜桃久久夜色精品一区的特点| 欧美日韩夫妻久久| 国产欧美一区在线| caoporn国产精品| 亚洲日本护士毛茸茸| 色一情一伦一子一伦一区| 亚洲国产欧美日韩另类综合| 国产成人综合亚洲网站| 国产精品三级电影| 欧美最猛性xxxxx直播| 亚洲成av人影院在线观看网| 91精品国产麻豆国产自产在线| 美国三级日本三级久久99| 久久蜜桃香蕉精品一区二区三区| 成人免费观看av| 亚洲午夜在线观看视频在线| 日韩欧美三级在线| 成人一道本在线| 亚洲午夜日本在线观看| 精品动漫一区二区三区在线观看| 国产成人亚洲综合色影视| 一区二区三区四区不卡视频| 欧美一区二区视频在线观看 | 亚洲国产精品成人综合| 欧洲在线/亚洲| 黄色资源网久久资源365| 一区二区三区在线观看网站| 欧美大白屁股肥臀xxxxxx| 成人av综合在线| 青青草成人在线观看| 亚洲欧美怡红院| 精品日韩在线观看| 在线影院国内精品| 国产成人av一区二区三区在线| 一区二区三区四区在线免费观看| 日韩欧美久久一区| 日本久久精品电影| 国产69精品一区二区亚洲孕妇| 亚洲国产综合人成综合网站| 久久精品水蜜桃av综合天堂| 欧美性生活大片视频| 成人久久久精品乱码一区二区三区| 亚洲成人一区二区在线观看| 国产精品免费看片| 久久人人超碰精品| 5858s免费视频成人| 日本韩国精品一区二区在线观看| 久久99国产精品免费| 久久无码av三级| 欧美精品久久久久久久久老牛影院| 懂色av一区二区三区蜜臀| 免费欧美在线视频| 香蕉成人伊视频在线观看| 17c精品麻豆一区二区免费| 久久蜜桃一区二区| 日韩视频免费直播| 顶级嫩模精品视频在线看| 激情久久五月天| 免费不卡在线观看| 日本一区中文字幕| 婷婷成人激情在线网| 精品国产乱子伦一区| 欧美一区二区三区在线看 | 亚洲激情图片一区| 国产精品久久看| 国产精品国产三级国产aⅴ中文| 久久这里只有精品首页| 2023国产一二三区日本精品2022| 日韩一区二区三区电影在线观看 | 欧美伊人久久久久久久久影院| 一本在线高清不卡dvd| 不卡av电影在线播放| 北岛玲一区二区三区四区| 不卡的av在线播放| 91免费国产在线| 在线视频欧美精品| 91精品国产入口在线| 日韩视频在线一区二区| 精品久久久久久久一区二区蜜臀| 欧美tickling挠脚心丨vk| 精品日韩成人av| 国产亚洲人成网站| 国产精品三级久久久久三级| 国产精品午夜在线| 亚洲欧洲中文日韩久久av乱码| 1024成人网| 亚洲电影一级片| 日韩激情一区二区| 国产美女精品人人做人人爽| 国产成人av资源| 99久久精品情趣| 欧美乱妇15p| 精品88久久久久88久久久| 国产精品沙发午睡系列990531| 亚洲欧美一区二区三区国产精品 | 视频一区视频二区中文| 激情av综合网| 色网站国产精品| 日韩手机在线导航| 成人欧美一区二区三区| 日本大胆欧美人术艺术动态| 国产福利一区在线| 欧美日韩专区在线| 国产亚洲婷婷免费| 日韩国产欧美三级| 不卡欧美aaaaa| 日韩视频在线观看一区二区| 亚洲啪啪综合av一区二区三区| 日本视频一区二区|