arphdr.c
来自「MCS51产单片机上实现的tcp/ip,很全的哦,需要的可以参考一下.」· C语言 代码 · 共 60 行
C
60 行
/* ARP header conversion routines
*/
#include "global.h"
#include "mbuf.h"
#include "arp.h"
/* Copy a host format arp structure into mbuf for transmission */
struct mbuf *
htonarp(arp)
register struct arp *arp;
{
struct mbuf *bp;
register uint8 *buf;
if(arp == (struct arp *)NULL)
return NULL;
bp = ambufw(ARPLEN + 2 * arp->hwalen);
buf = bp->data;
buf = put16(buf,arp->hardware);
buf = put16(buf,arp->protocol);
*buf++ = arp->hwalen;
*buf++ = arp->pralen;
buf = put16(buf,arp->opcode);
memcpy(buf,arp->shwaddr,(uint16)arp->hwalen);
buf += arp->hwalen;
buf = put32(buf,arp->sprotaddr);
memcpy(buf,arp->thwaddr,(uint16)arp->hwalen);
buf += arp->hwalen;
buf = put32(buf,arp->tprotaddr);
bp->cnt = buf - bp->data;
return bp;
}
/* Convert an incoming ARP packet into a host-format structure */
int
ntoharp(
struct arp *arp,
struct mbuf **bpp
){
if(arp == (struct arp *)NULL || bpp == NULL)
return -1;
arp->hardware = pull16(bpp);
arp->protocol = pull16(bpp);
arp->hwalen = PULLCHAR(bpp);
arp->pralen = PULLCHAR(bpp);
arp->opcode = pull16(bpp);
pullup(bpp,arp->shwaddr,(uint16)arp->hwalen);
arp->sprotaddr = pull32(bpp);
pullup(bpp,arp->thwaddr,(uint16)arp->hwalen);
arp->tprotaddr = pull32(bpp);
/* Get rid of anything left over */
free_p(bpp);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?