



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
RIP.txt#include sysinclude.h#include extern void rip_sendIpPkt(unsigned char* pData, UINT16 len, unsigned short dstPort, UINT8 iNo);/*RIP*/extern struct stud_rip_route_node *g_rip_route_table;/*/typedef struct _packet_header /*RIP*/unsigned char command;/*REQUESTRESONSE*/unsigned char version;/*12*/unsigned short pad0;/*/ packet_header;typedef struct _packet_data/*RIP*/unsigned short addrfamily;/*2*/unsigned short routetag;/*/unsigned int ipaddr;/*IP*/unsigned int netmask;/*/unsigned int nexthop;/*/unsigned int metric;/*/ packet_data;#define DECLAREERROR(pkt,type) printf(Discard because %dn,type);ip_DiscardPkt(pkt,type);return 0;/*RIP*/unsigned char buffer256;/*/void dumpPkt(unsigned char*buf,int len)/*/printf(Dumping sending packets:n);int l=0;for (int i=0;iif_no=iNo|pnow-metric=16)pnow=pnow-next;/*/do/*RIP*/packet_header*ph=(packet_header*)buffer;ph-command=2; /*RESPONSE*/ph-version=version; /*/ph-pad0=0; /*0*/*/int pCount=0;while (pCountaddrfamily=htons(2); pd-routetag=0; pd-ipaddr=htonl(pnow-dest);if (version=2)pd-netmask=htonl(pnow-mask);elsepd-netmask=0;if (version=2)pd-nexthop=htonl(pnow-nexthop);elsepd-nexthop=0;pd-metric=htonl(pnow-metric);pCount+;do pnow=pnow-next; while (pnow&(pnow-if_no=iNo|pnow-metric=16);/*/dumpPkt(buffer,sizeof(packet_header)+sizeof(packet_data)*pCount);rip_sendIpPkt(buffer,sizeof(packet_header)+sizeof(packet_data)*pCount,520,iNo); while (pnow);#include char*clone(char*org,int len)/*/char*t=(char*)malloc(len);memmove(t,org,len);return t;int stud_rip_packet_recv(char*pBuffer, int bufferSize, UINT8 iNo, UINT32 srcAdd)pBuffer=clone(pBuffer,bufferSize);/*/packet_header*ph=(packet_header*)pBuffer;if (ph-command!=1&ph-command!=2) DECLAREERROR(pBuffer,STUD_RIP_TEST_COMMAND_ERROR);if (ph-version!=1&ph-version!=2) DECLAREERROR(pBuffer,STUD_RIP_TEST_VERSION_ERROR);if (ph-pad0!=0) DECLAREERROR(pBuffer,STUD_RIP_TEST_COMMAND_ERROR);if (ph-command=1)/*REQUEST*/printf(Get valid requestn);MakePacket(ph-version,iNo);else/*RESPONSE*/dumpPkt(unsigned char*)pBuffer,bufferSize);/*/int snums=(bufferSize-sizeof(packet_header)/sizeof(packet_data);/*RIP*/for (int i=0;iipaddr=ntohl(pd-ipaddr);pd-netmask=ntohl(pd-netmask);pd-nexthop=ntohl(pd-nexthop);pd-metric=ntohl(pd-metric);/*RIP*/stud_rip_route_node*hd=g_rip_route_table;dumpPkt(unsigned char*)pd,sizeof(packet_data);int hdcount=0;while (hd) if (hd-dest=pd-ipaddr&hd-mask=pd-netmask) break;hd=hd-next;hdcount+;do/*RIP*/if (hd) /*/printf(Match at %d and nexthop %xn,hdcount,hd-nexthop);if (hd-nexthop!=pd-nexthop)if (hd-metricpd-metric)hd-metric=pd-metric+1;/*/hd-nexthop=pd-nexthop;/*/hd-if_no=iNo;break;/*RIP*/hd-metric=pd-metric+1;hd-nexthop=pd-nexthop;hd-if_no=iNo;/*161616*/if (hd-metric16)hd-metric=16;else /*/printf(Unmatched.n);if (pd-metric=16) break;/*16*/stud_rip_route_node* nhd=(stud_rip_route_node*)malloc(sizeof(stud_rip_route_node);/*/nhd-dest=pd-ipaddr;nhd-mask=pd-netmask;nhd-nexthop=pd-nexthop;nhd-metric=pd-metric+1;/*1*/nhd-if_no=iNo;nhd-next=g_rip_route_table;/*/g_rip_route_table=nhd; while (false);/*/void stud_rip_route_timeout(UINT32 destAdd, UINT32 mask, unsigned char msgType)if (msgType=RIP_MSG_SEND_ROUTE)/*/MakePacket(2,1);MakePac
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 现代物流运输合同规范及范本
- 工程融资居间合同范本3篇
- 卫浴浴室柜安装合同3篇
- 聚氨酯混凝土施工方案
- 公路坍方清理的施工方案
- 彭水木纹铝单板施工方案
- 智能家居工程合同价款支付与系统集成服务
- 企业内部人才储备项目人力资源助理试用期合同
- 文化创意产业项目合同知识产权担保责任承诺
- 新劳动合同法实施后企业员工劳动合同续签及解约协议
- 农贸市场装修施工方案
- 2022年广东双百社工笔试真题及答案
- EPLAN电气设计 课件全套 陈乾 任务1-15 初识Eplan、Eplan的安装-图纸设计与电气元件选型练习
- 【拆书阅读笔记】-《网飞文化手册》
- 四川公路工程竣工文件资料编制实施细则
- 提升家庭教育指导能力
- 设备借用协议范本
- 交安工程施工合同
- 高中生物选择性必修一知识点总结
- 肠造口并发症讲稿课件
- GB/T 6403.5-2008砂轮越程槽
评论
0/150
提交评论