📄 uip_arp.lst
字号:
194 1 if((IPBUF->srcipaddr[0] & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1)) !=
195 1 (htons((UIP_IPADDR0 << 8) | UIP_IPADDR1)
196 1 & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1)))
197 1 return;
198 1 if((IPBUF->srcipaddr[1] & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3)) !=
199 1 (htons((UIP_IPADDR2 << 8) | UIP_IPADDR3)
200 1 & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3)))
201 1 return;
202 1
203 1 uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
204 1
205 1 return;
206 1 }
207 /*-----------------------------------------------------------------------------------*/
208
209 extern void puthex(unsigned char Byte);//以十六进制格式显示1个字节数据
210 extern void putstring(unsigned char *str);//显示字符串
211 extern void putword(unsigned int Word);//以十六进制格式显示1个字数据
212
213 void
214 uip_arp_arpin(void)
215 {
216 1
217 1 if(uip_len < sizeof(struct arp_hdr))
218 1 {
219 2 uip_len = 0;
220 2 return;
221 2 }
222 1
223 1 uip_len = 0;
224 1
225 1 //putstring("\r\nuip_arp_arpin");
226 1 //puthex(BUF->opcode);
227 1
228 1 switch(BUF->opcode)
229 1 {
230 2 case htons(ARP_REQUEST):
231 2
232 2 /* ARP request. If it asked for our address, we send out a
233 2 reply. */
234 2 if(BUF->dipaddr[0] == htons((UIP_IPADDR0 << 8) | UIP_IPADDR1) &&
235 2 BUF->dipaddr[1] == htons((UIP_IPADDR2 << 8) | UIP_IPADDR3))
236 2 {
237 3 /* The reply opcode is 2. */
238 3 BUF->opcode = htons(2);
239 3 BUF->dhwaddr = BUF->shwaddr;
240 3 //putstring("\r\ARP_REQUEST");
241 3 for(c = 0; c < 6; ++c)
C51 COMPILER V7.08 UIP_ARP 12/26/2003 07:27:15 PAGE 5
242 3 {
243 4 BUF->shwaddr.addr[c] =
244 4 BUF->ethhdr.src.addr[c] = ethaddr.addr[c];
245 4 BUF->ethhdr.dest.addr[c] = BUF->dhwaddr.addr[c];
246 4 }
247 3
248 3 BUF->dipaddr[0] = BUF->sipaddr[0];
249 3 BUF->dipaddr[1] = BUF->sipaddr[1];
250 3 BUF->sipaddr[0] = htons((UIP_IPADDR0 << 8) | UIP_IPADDR1);
251 3 BUF->sipaddr[1] = htons((UIP_IPADDR2 << 8) | UIP_IPADDR3);
252 3
253 3 BUF->ethhdr.type = htons(UIP_ETHTYPE_ARP);
254 3
255 3 uip_len = sizeof(struct arp_hdr);
256 3 }
257 2 break;
258 2 case htons(ARP_REPLY):
259 2 /* ARP reply. We insert or update the ARP table if it was meant
260 2 for us. */
261 2 if(BUF->dipaddr[0] == htons((UIP_IPADDR0 << 8) | UIP_IPADDR1) &&
262 2 BUF->dipaddr[1] == htons((UIP_IPADDR2 << 8) | UIP_IPADDR3))
263 2 {
264 3 uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
265 3 }
266 2 break;
267 2 }
268 1 }
269 /*-----------------------------------------------------------------------------------*/
270 void
271 uip_arp_out(void)
272 {
273 1 /* Find the destination IP address in the ARP table and construct
274 1 the Ethernet header. If the destination IP addres isn't on the
275 1 local network, we use the default router's IP address instead.
276 1
277 1 If not ARP table entry is found, we overwrite the original IP
278 1 packet with an ARP request for the IP address. */
279 1
280 1 /* Check if the destination address is on the local network. */
281 1 if((IPBUF->destipaddr[0] & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1)) !=
282 1 (htons((UIP_IPADDR0 << 8) | UIP_IPADDR1)
283 1 & htons((UIP_NETMASK0 << 8) | UIP_NETMASK1)) ||
284 1 (IPBUF->destipaddr[1] & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3)) !=
285 1 (htons((UIP_IPADDR2 << 8) | UIP_IPADDR3)
286 1 & htons((UIP_NETMASK2 << 8) | UIP_NETMASK3))) {
287 2 /* Destination address was not on the local network, so we need to
288 2 use the default router's IP address instead of the destination
289 2 address when determining the MAC address. */
290 2 ipaddr[0] = htons((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1);
291 2 ipaddr[1] = htons((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3);
292 2 } else {
293 2 /* Else, we use the destination IP address. */
294 2 ipaddr[0] = IPBUF->destipaddr[0];
295 2 ipaddr[1] = IPBUF->destipaddr[1];
296 2 }
297 1
298 1 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
299 2 if(ipaddr[0] == arp_table[i].ipaddr[0] &&
300 2 ipaddr[1] == arp_table[i].ipaddr[1])
301 2 break;
302 2 }
303 1
C51 COMPILER V7.08 UIP_ARP 12/26/2003 07:27:15 PAGE 6
304 1 if(i == UIP_ARPTAB_SIZE) {
305 2 /* The destination address was not in our ARP table, so we
306 2 overwrite the IP packet with an ARP request. */
307 2
308 2 for(c = 0; c < 6; ++c)
309 2 {
310 3 BUF->ethhdr.dest.addr[c] = 0xff; /* Broadcast ARP request. */
311 3 BUF->ethhdr.src.addr[c] =
312 3 BUF->shwaddr.addr[c] = ethaddr.addr[c];
313 3 BUF->dhwaddr.addr[c] = 0;
314 3 }
315 2
316 2 BUF->dipaddr[0] = ipaddr[0];
317 2 BUF->dipaddr[1] = ipaddr[1];
318 2 BUF->sipaddr[0] = htons((UIP_IPADDR0 << 8) | UIP_IPADDR1);
319 2 BUF->sipaddr[1] = htons((UIP_IPADDR2 << 8) | UIP_IPADDR3);
320 2 BUF->opcode = htons(ARP_REQUEST); /* ARP request. */
321 2 BUF->hwtype = htons(ARP_HWTYPE_ETH);
322 2 BUF->protocol = htons(UIP_ETHTYPE_IP);
323 2 BUF->hwlen = 6;
324 2 BUF->protolen = 4;
325 2 BUF->ethhdr.type = htons(UIP_ETHTYPE_ARP);
326 2
327 2 uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
328 2
329 2 uip_len = sizeof(struct arp_hdr);
330 2 return;
331 2 }
332 1
333 1 /* Build an ethernet header. */
334 1 for(c = 0; c < 6; ++c) {
335 2 IPBUF->ethhdr.dest.addr[c] = arp_table[i].ethaddr.addr[c];
336 2 IPBUF->ethhdr.src.addr[0] = ethaddr.addr[c];
337 2 }
338 1 IPBUF->ethhdr.type = htons(UIP_ETHTYPE_IP);
339 1
340 1 uip_len += sizeof(struct uip_eth_hdr);
341 1 }
342 /*-----------------------------------------------------------------------------------*/
343
344
345
346
347 void
348 uip_arp_req(void)
349 {
350 1 /* The destination address was not in our ARP table, so we
351 1 overwrite the IP packet with an ARP request. */
352 1 for(i = 0; i < 6; ++i)
353 1 {
354 2 BUF->ethhdr.dest.addr[i] = 0xff; /* Broadcast ARP request. */
355 2 BUF->ethhdr.src.addr[i] =
356 2 BUF->shwaddr.addr[i] = ethaddr.addr[i];
357 2 BUF->dhwaddr.addr[i] = 0;
358 2 }
359 1
360 1 BUF->dipaddr[0] = htons((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1);
361 1 BUF->dipaddr[1] = htons((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3);
362 1
363 1 //BUF->dipaddr[0] = ipaddr[0];
364 1 //BUF->dipaddr[1] = ipaddr[1];
365 1 BUF->sipaddr[0] = htons((UIP_IPADDR0 << 8) | UIP_IPADDR1);
C51 COMPILER V7.08 UIP_ARP 12/26/2003 07:27:15 PAGE 7
366 1 BUF->sipaddr[1] = htons((UIP_IPADDR2 << 8) | UIP_IPADDR3);
367 1 BUF->opcode = htons(ARP_REQUEST); /* ARP request. */
368 1 BUF->hwtype = htons(ARP_HWTYPE_ETH);
369 1 BUF->protocol = htons(UIP_ETHTYPE_IP);
370 1 BUF->hwlen = 6;
371 1 BUF->protolen = 4;
372 1 BUF->ethhdr.type = htons(UIP_ETHTYPE_ARP);
373 1
374 1 uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
375 1
376 1 uip_len = sizeof(struct arp_hdr);
377 1 }
378 /*-----------------------------------------------------------------------------------*/
379
380
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1699 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 102 6
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -