1 / 20
文档名称:

uip各部分协议代码的分析.docx

格式:docx   大小:28KB   页数:20页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

uip各部分协议代码的分析.docx

上传人:rsqcpza 2019/6/22 文件大小:28 KB

下载得到文件列表

uip各部分协议代码的分析.docx

文档介绍

文档介绍:uip各部分协议代码的分析篇一:uIP的ARP协议代码分析之一_ARP请求从下面的文章我们了解到,对于一个设备用的ARP协议而言,重要的东西包括三方面: . . 下面我们来看uIP中是如何实现的,thefunction *checkstheARPcachetoseeifanentryforthedestinationIP *,headerisprependedandthe * *destinationIPaddress,thepacketintheuip_buf[]isreplacedby * *anditisassumedthattheyhigherlevelprotocols*eventuallywillretransmitthedroppedpacket. *如果目的IP地址是在局域网中,函数就会从ARP缓存表中查找有*,就取对应的MAC地址,加上以太网头,并返回,否则uip_buf[]中的数据包会被替换成一个*,此函数假设高层协议会最终重传扔掉的包. *work,theIP*addressofthedefaultrouterisusedinstead.*如果目标IP地址并非一个局域网IP,则会使用默认路由的IP地址. *Whenthefunctionreturns,apacketispresentintheuip_buf[] *buffer,andthelengthofthepacketisintheglobalvariable *,uip_buf[]中已经有了一个包,其长度由uip_len指定. *//*----------------------------------------------------------------------------- ------ */void uip_arp_out { structarp_entry*tabptr; /*FindthedestinationIPaddressintheARPtableand isn'work,weusethedefaultrouter'sIP addressinstead. //在ARP表中找到目的IP地址,,则使用默认路由的IP. IfnotARPtableentryisfound,weoverwritetheoriginal IPpacketwithanARPrequestfortheIPaddress.*///如果 ARP表中找不到,则将原来的IP包替换成一个ARP请求./**/if){memcpy; }else{ /**/if){ /*work,soweneedtousethedefaultrouter'sIPaddressinsteadofthedestination ,所以保用默认路由器的地址来确在MAC地址*/uip_ipaddr_copy; }else{ /*Else,,使用目标IP地址*/ uip_ipaddr_copy;} for{//这里遍历表,对比目的IP与ARP缓存表中的IP. tabptr=&arp_table; if) {break;}} if{/*ThedestinationaddresswasnotinourARPtable,sowe ,将原IP包替换为ARP请求并返回*/ memset;memset;memcpy;memcpy; uip_ipaddr_copy; uip_ipaddr_copy;BUF- >opcode=HTONS;/*ARPrequest.*/ BUF->hwtype=HTONS;BUF->protocol=HTONS; BUF->hwlen=6; BUF->pr