📄 arp.lst
字号:
230 ARP_DEBUGOUT("Preparing for ARP Reply\n\r");
231
232 /* OK. Now send reply */
233
234 NETWORK_SEND_INITIALIZE(ARP_BUFFER);
235
236 /* Add datalink (Ethernet addresses) information */
237
238 for( i=0; i<MAXHWALEN; i++) {
239 send_frame.destination[i] = rem_hwadr[i];
240 send_frame.source[i] = localmachine.localHW[i];
241 }
242
243 send_frame.protocol = PROTOCOL_ARP;
244
245 NETWORK_ADD_DATALINK(&send_frame);
246
247 /* PUT ARP Data */
248
249 SEND_NETWORK_B( (BYTE)(AR_HARDWARE>>8) ); /* Hardware Type */
250 SEND_NETWORK_B( (BYTE)AR_HARDWARE );
251 SEND_NETWORK_B(0x08); /* Protocol Type */
252 SEND_NETWORK_B(0x00);
253 SEND_NETWORK_B(MAXHWALEN); /* HW Adr Len */
254 SEND_NETWORK_B(MAXPRALEN); /* Protocol Adr. Len*/
255 SEND_NETWORK_B( 0x00 ); /* ARP Opcode */
256 SEND_NETWORK_B( 0x02 );
257 SEND_NETWORK_B((UINT8)(localmachine.localHW[5])); /* Address fields */
258 SEND_NETWORK_B((UINT8)(localmachine.localHW[4]));
259 SEND_NETWORK_B((UINT8)(localmachine.localHW[3]));
260 SEND_NETWORK_B((UINT8)(localmachine.localHW[2]));
261 SEND_NETWORK_B((UINT8)(localmachine.localHW[1]));
262 SEND_NETWORK_B((UINT8)(localmachine.localHW[0]));
263 SEND_NETWORK_B((UINT8)(localmachine.localip>>24));
264 SEND_NETWORK_B((UINT8)(localmachine.localip>>16));
265 SEND_NETWORK_B((UINT8)(localmachine.localip>>8));
266 SEND_NETWORK_B((UINT8)(localmachine.localip));
267 SEND_NETWORK_B((UINT8)rem_hwadr[5]);
268 SEND_NETWORK_B((UINT8)rem_hwadr[4]);
269 SEND_NETWORK_B((UINT8)rem_hwadr[3]);
270 SEND_NETWORK_B((UINT8)rem_hwadr[2]);
271 SEND_NETWORK_B((UINT8)rem_hwadr[1]);
272 SEND_NETWORK_B((UINT8)rem_hwadr[0]);
273 SEND_NETWORK_B((UINT8)(rem_ip>>24));
274 SEND_NETWORK_B((UINT8)(rem_ip>>16));
275 SEND_NETWORK_B((UINT8)(rem_ip>>8));
276 SEND_NETWORK_B((UINT8)rem_ip);
277
278 NETWORK_COMPLETE_SEND(0x0040); /* Send the packet */
279
280 ARP_DEBUGOUT("ARP Reply Sent..\n\r");
281
282 /* Add the Sender's info to cache because we can */
283
284 arp_add(rem_ip, &send_frame.destination[0], ARP_TEMP_IP);
285
286 return;
287
288 }
289
290
291 /** \brief Extract data from the received ARP packet
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 6
292 * \author
293 * \li Jari Lahti (jari.lahti@violasystems.com)
294 * \date 10.07.2002
295 * \warning
296 * \li This function starts reading data from Ethernet controller
297 * without initializing it for reading it first, so NIC must already
298 * be initialized for reading from correct address (it expects ar$sha
299 * field from ARP packet immediately)
300 *
301 * This function is invoked from process_arp() function when ARP reply
302 * packet is detected. Basic checking is performed to see if the packet
303 * is intended for us, and if it is, ARP cache table is checked and
304 * corresponding entry is refreshed (resolved).
305 *
306 */
307 void arp_get_response(void)
308 {
309 struct arp_entry *qstruct;
310 UINT8 rem_hwadr[MAXHWALEN];
311 UINT32 rem_ip;
312 UINT32 ltemp;
313 INT8 i;
314 UINT8 j;
315
316 /* Read Sender's HW address */
317
318 for( i=MAXHWALEN-1; i >= 0; i-- )
319 rem_hwadr[i] = RECEIVE_NETWORK_B();
320
321 /* Read Sender's IP Address */
322
323 for( i=0; i<MAXPRALEN; i++) {
324 rem_ip <<= 8;
325 rem_ip |= RECEIVE_NETWORK_B();
326 }
327
328
329 /* Skip our HW Address */
330
331 for(i=0; i<MAXHWALEN; i++)
332 RECEIVE_NETWORK_B();
333
334
335 /* Is The Packet For Us? */
336
337 for( i=0; i<MAXPRALEN; i++) {
338 ltemp <<= 8;
339 ltemp |= RECEIVE_NETWORK_B();
340 }
341
342
343 if( ltemp != localmachine.localip )
344 return; /* No */
345
346 ARP_DEBUGOUT("Now entering to process ARP Reply..\n\r");
347
348 /* Are we waiting for that reply? */
349
350 for( i=1; i<ARP_TSIZE; i++ ) {
351 qstruct = &arp_table[i];
352
353 if( qstruct->state == ARP_FREE )
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 7
354 continue;
355
356 if( qstruct->state == ARP_RESERVED )
357 continue;
358
359 if( rem_ip == qstruct->pradr ) {
360 /* We are caching that IP, refresh it */
361
362 ARP_DEBUGOUT("Refreshing ARP cache from Reply..\n\r");
363
364 for( j=0; j<MAXHWALEN; j++ )
365 qstruct->hwadr[j] = rem_hwadr[j];
366
367 qstruct->ttl = ARP_TIMEOUT;
368 qstruct->retries = ARP_MAXRETRY; /* No need for Retry */
369 qstruct->state = ARP_RESOLVED;
370
371 /* Done */
372
373 break;
374 }
375
376 }
377
378 }
379
380 /** \brief Send ARP request based on information in an ARP cache table
381 * \author
382 * \li Jari Lahti (jari.lahti@violasystems.com)
383 * \date 1.11.2001
384 * \param entry Index of ARP cache entry that is beeing resolved
385 *
386 * Invoked from arp_find() and arp_manage() functions, arp_send_request
387 * creates ARP request packet based on data stored in the ARP cache entry
388 * who's index is given as a parameter.
389 */
390 void arp_send_req (UINT8 entry)
391 {
392
393 struct arp_entry *qstruct;
394 UINT8 i;
395
396 qstruct = &arp_table[entry];
397
398 NETWORK_SEND_INITIALIZE(ARP_BUFFER);
399
400 /* Add datalink (Ethernet addresses) information */
401
402 for( i=0; i<MAXHWALEN; i++) {
403 send_frame.destination[i] = 0xFF;
404 send_frame.source[i] = localmachine.localHW[i];
405 }
406
407 send_frame.protocol = PROTOCOL_ARP;
408
409 NETWORK_ADD_DATALINK(&send_frame);
410
411 /* PUT ARP Data */
412
413 SEND_NETWORK_B( (BYTE) (AR_HARDWARE>>8) ); /* Hardware Type */
414 SEND_NETWORK_B( (BYTE) AR_HARDWARE );
415 SEND_NETWORK_B(0x08); /* Protocol Type */
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 8
416 SEND_NETWORK_B(0x00);
417 SEND_NETWORK_B(MAXHWALEN); /* HW Adr Len */
418 SEND_NETWORK_B(MAXPRALEN); /* Protocol Adr. Len*/
419 SEND_NETWORK_B( (BYTE)(ARP_REQUEST>>8)); /* ARP Opcode */
420 SEND_NETWORK_B( (BYTE) ARP_REQUEST );
421 SEND_NETWORK_B((UINT8)localmachine.localHW[5]); /* Address fields */
422 SEND_NETWORK_B((UINT8)localmachine.localHW[4]);
423 SEND_NETWORK_B((UINT8)localmachine.localHW[3]);
424 SEND_NETWORK_B((UINT8)localmachine.localHW[2]);
425 SEND_NETWORK_B((UINT8)localmachine.localHW[1]);
426 SEND_NETWORK_B((UINT8)localmachine.localHW[0]);
427 SEND_NETWORK_B((UINT8)(localmachine.localip>>24));
428 SEND_NETWORK_B((UINT8)(localmachine.localip>>16));
429 SEND_NETWORK_B((UINT8)(localmachine.localip>>8));
430 SEND_NETWORK_B((UINT8)localmachine.localip);
431 SEND_NETWORK_B((UINT8)0xFF);
432 SEND_NETWORK_B((UINT8)0xFF);
433 SEND_NETWORK_B((UINT8)0xFF);
434 SEND_NETWORK_B((UINT8)0xFF);
435 SEND_NETWORK_B((UINT8)0xFF);
436 SEND_NETWORK_B((UINT8)0xFF);
437 SEND_NETWORK_B((UINT8)(qstruct->pradr>>24));
438 SEND_NETWORK_B((UINT8)(qstruct->pradr>>16));
439 SEND_NETWORK_B((UINT8)(qstruct->pradr>>8));
440 SEND_NETWORK_B((UINT8)qstruct->pradr);
441
442
443 /* Packet assembled now, just send it ... */
444
445 NETWORK_COMPLETE_SEND(0x0040); /* Min packet size */
446
447 ARP_DEBUGOUT("ARP Request Sent\n\r");
448
449 }
450
451
452 /** \brief Allocate ARP entry in ARP cache table
453 * \author
454 * \li Jari Lahti (jari.lahti@violasystems.com)
455 * \date 1.11.2001
456 * \param type Type of ARP cache entry beeing allocated. Can be one of the
457 * following:
458 * \li #ARP_FIXED_IP
459 * \li #ARP_TEMP_IP
460 * \return >=0 - pointer to allocated ARP entry (actaully index in the
461 * ARP cache table)
462 *
463 * Allocate arp entry for given type. Chooses the unused entry if
464 * one exists. Otherwice deletes entries in round-robin fashion.
465 */
466 INT8 arp_alloc (UINT8 type)
467 {
468 struct arp_entry *qstruct;
469 INT8 i;
470 static BYTE aenext = 1; /* Cache Manager */
471 INT16 found;
472
473 /* try to find free entry */
474 found=-1;
475
476 for( i=0; i<ARP_TSIZE; i++ ) {
477
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 9
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -