没有合适的资源?快使用搜索试试~ 我知道了~
首页ip 分片代码(用于虚拟网络教学系统)
ip 分片代码(用于虚拟网络教学系统)
4星 · 超过85%的资源 需积分: 11 22 下载量 39 浏览量
更新于2023-03-16
评论
收藏 193KB DOC 举报
这个是虚拟的ip 分片过程的源代码,比较基本,大家可以试试看滑动窗口协议的基本原理,就是在任意时刻,发送方都维持了一个连续的允许发送的帧的序号,称为发送窗口;同时,接收方也维持了一个连续的允许接收的帧的序号,称为接收窗口。发送窗口和接收窗口的序号的上下界不一定要一样,甚至大小也可以不同。不同的滑动窗口协议窗口大小一般不同。发送方窗口内的序列号代表了那些已经被发送,但是还没有被确认的帧,或者是那些可以被发送的帧
资源详情
资源评论
资源推荐
/*
This file is taken from Linux2.0.36kernel source.
Modified in Jun 99 by Nergal.
*/
#include<sys/types.h>
#include<sys/time.h>
#include<netinet/in.h>
#include<netinet/in_systm.h>
#include<netinet/ip.h>
#include<netinet/tcp.h>
#include<arpa/inet.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include"checksum.h"
#include"ip_fragment.h"
#include"tcp.h"
#include"util.h"
#include"nids.h"
#defineIP_CE0x8000/* Flag: "Congestion" */
#defineIP_DF0x4000/* Flag: "Don't Fragment" */
#defineIP_MF0x2000/* Flag: "More Fragments" */
#defineIP_OFFSET0x1FFF/* "Fragment Offset" part */
#defineIP_FRAG_TIME(30 * 1000)/* fragment lifetime */
#defineUNUSED 314159
#defineFREE_READ UNUSED
#defineFREE_WRITE UNUSED
#defineGFP_ATOMIC UNUSED
#defineNETDEBUG(x)
structsk_buff {
char*data;
inttruesize;
};
structtimer_list {
structtimer_list *prev;
structtimer_list *next;
intexpires;
void(*function)();
unsignedlongdata;
// struct ipq *frags;
};
structhostfrags {
structipq *ipqueue;
intip_frag_mem;
u_int ip;
inthash_index;
structhostfrags *prev;
structhostfrags *next;
};
/* Describe an IP fragment. */
structipfrag {
intoffset;/* offset of fragment in IP datagram*/
intend;/* last byte of data in datagram*/
intlen;/* length of this fragment*/
structsk_buff *skb;/* complete received fragment*/
unsignedchar*ptr;/* pointer into real fragment data*/
structipfrag *next;/* linked list pointers*/
structipfrag *prev;
};
/* Describe an entry in the "incomplete datagrams" queue. */
structipq {
unsignedchar*mac;/* pointer to MAC header*/
structip *iph;/* pointer to IP header*/
intlen;/* total length of original datagram*/
shortihlen;/* length of the IP header*/
shortmaclen;/* length of the MAC header*/
structtimer_list timer;/* when will this queue expire?*/
structipfrag *fragments;/* linked list of received fragments*/
structhostfrags *hf;
structipq *next;/* linked list pointers*/
structipq *prev;
// struct device *dev;/* Device - for icmp replies */
};
/*
Fragment cache limits. We will commit 256K at one time. Should we
cross that limit we will prune down to 192K. This should cope with
even the most extreme cases without allowing an attacker to
measurably harm machine performance.
*/
#defineIPFRAG_HIGH_THRESH(256*1024)
#defineIPFRAG_LOW_THRESH(192*1024)
/*
This fragment handler is a bit of a heap. On the other hand it works
quite happily and handles things quite well.
*/
staticstructhostfrags **fragtable;
staticstructhostfrags *this_host;
staticintnumpack = 0;
staticinthash_size;
staticinttimenow;
staticunsignedinttime0;
staticstructtimer_list *timer_head = 0, *timer_tail = 0;
#defineint_ntoa(x)inet_ntoa(*((structin_addr *)&x))
staticint
jiffies()
{
structtimeval tv;
if(timenow)
returntimenow;
gettimeofday(&tv, 0);
timenow = (tv.tv_sec - time0) * 1000 + tv.tv_usec / 1000;
returntimenow;
}
/* Memory Tracking Functions */
staticvoid
atomic_sub(intile,int*co)
{
*co -= ile;
}
staticvoid
atomic_add(intile,int*co)
{
*co += ile;
}
staticvoid
kfree_skb(structsk_buff * skb,inttype)
{
(void)type;
free(skb);
}
staticvoid
panic(char*str)
{
fprintf(stderr, "%s", str);
exit(1);
}
staticvoid
add_timer(structtimer_list * x)
{
if(timer_tail) {
timer_tail->next = x;
x->prev = timer_tail;
x->next = 0;
timer_tail = x;
}
else{
x->prev = 0;
x->next = 0;
timer_tail = timer_head = x;
}
}
staticvoid
del_timer(structtimer_list * x)
{
if(x->prev)
x->prev->next = x->next;
else
timer_head = x->next;
if(x->next)
x->next->prev = x->prev;
else
timer_tail = x->prev;
}
staticvoid
frag_kfree_skb(structsk_buff * skb,inttype)
{
if(this_host)
atomic_sub(skb->truesize, &this_host->ip_frag_mem);
kfree_skb(skb, type);
}
staticvoid
frag_kfree_s(void*ptr,intlen)
{
if(this_host)
atomic_sub(len, &this_host->ip_frag_mem);
free(ptr);
}
staticvoid*
frag_kmalloc(intsize,intdummy)
{
void*vp = (void*) malloc(size);
(void)dummy;
if(!vp)
returnNULL;
atomic_add(size, &this_host->ip_frag_mem);
returnvp;
}
/* Create a new fragment entry. */
staticstructipfrag *
ip_frag_create(intoffset,intend,structsk_buff * skb,unsignedchar*ptr)
{
structipfrag *fp;
fp = (structipfrag *) frag_kmalloc(sizeof(structipfrag), GFP_ATOMIC);
if(fp == NULL) {
// NETDEBUG(printk("IP: frag_create: no memory left !\n"));
nids_params.no_mem("ip_frag_create");
return(NULL);
}
memset(fp, 0,sizeof(structipfrag));
/* Fill in the structure. */
fp->offset = offset;
剩余22页未读,继续阅读
kim707870102
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1