| 
 
| 我在学习uip,PC通过交叉网线连接DM9000A,串口打印DM9000A的输入输出数据,发现DM9000A发出去的ARP请求的帧长是42字节,PC发送给路由的ARP请求是64字节,TCP/IP书上说了,以太网的最小帧长是64字节。 查看uip源码,ARP请求和回应的最后数据帧长度确实就一个ARP头部长度,没有填充0,没有CRC校验,接下来立即将这个包提交给DM9000A发出。
 查看lwip的ARP请求,情况也是一样的。
 ARP请求
 if (i == UIP_ARPTAB_SIZE) {
 /* The destination address was not in our ARP table, so we
 overwrite the IP packet with an ARP request. */
 memset(BUF->ethhdr.dest.addr, 0xff, 6);
 memset(BUF->dhwaddr.addr, 0x00, 6);
 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
 uip_ipaddr_copy(BUF->dipaddr, ipaddr);
 uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);
 BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
 BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
 BUF->protocol = HTONS(UIP_ETHTYPE_IP);
 BUF->hwlen = 6;
 BUF->protolen = 4;
 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
 uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
 uip_len = sizeof(struct arp_hdr);
 return;
 }
 
 ARP回应
 /* ARP request. If it asked for our address, we send out a
 reply. */
 if (uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
 /* First, we register the one who made the request in our ARP
 table, since it is likely that we will do more communication
 with this host in the future. */
 uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
 /* The reply opcode is 2. */
 BUF->opcode = HTONS(2);
 memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
 BUF->dipaddr[0] = BUF->sipaddr[0];
 BUF->dipaddr[1] = BUF->sipaddr[1];
 BUF->sipaddr[0] = uip_hostaddr[0];
 BUF->sipaddr[1] = uip_hostaddr[1];
 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
 uip_len = sizeof(struct arp_hdr);
 }
 
 
 DM9000A发出的ARP请求以太网数据帧:
 [0]tx: length: 42
 
 tx: 00: ff ff ff ff ff ff 12 34
 tx: 08: 56 78 9a bc 08 06 00 01
 tx: 10: 08 00 06 04 00 01 12 34
 tx: 18: 56 78 9a bc c0 a8 02 20
 tx: 20: 00 00 00 00 00 00 c0 a8
 tx: 28: 02 20
 
 PC发送给路由的ARP请求以太网数据帧:
 [0]rx: length: 64
 rx: 00: ff ff ff ff ff ff 00 23
 rx: 08: 8b 94 8b 31 08 06 00 01
 rx: 10: 08 00 06 04 00 01 00 23
 rx: 18: 8b 94 8b 31 c0 a8 02 cf
 rx: 20: 00 00 00 00 00 00 c0 a8
 rx: 28: 02 01 00 00 00 00 00 00
 rx: 30: 00 00 00 00 00 00 00 00
 rx: 38: 00 00 00 00 6a bc be 18
 
 | 
 |