⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arp.lst

📁 cs8900 c51应用
💻 LST
📖 第 1 页 / 共 4 页
字号:
 727                                          ARP_DEBUGOUT("The Address of Def. GW is not Solved!\n\r");
 728                                          return(0);
 729                                  }
 730                          
 731                                  /* All OK       */
 732                                  
 733                                  ARP_DEBUGOUT(" >> Default Gateway MAC found!\n\r");
 734                          
 735                                  return(qstruct);
 736                                          
 737                          }
 738                  
 739                  }
 740                  
 741                  ARP_DEBUGOUT("Need to send ARP Request to default gateway..\n\r");
 742                          
 743                  i = arp_alloc(ARP_FIXED_IP);
 744                          
 745                  if( i < 0 )                             /* No Entries Left?     */
 746                          return(0);
 747                                  
 748                  /* Send Request after filling the fields        */
 749                          
 750                  qstruct = &arp_table[i];
 751                          
 752                  qstruct->pradr = machine->defgw;                                                /* Fill IP                              */
 753                  qstruct->hwadr[0] = 0xFF;                                       /* Fill Broadcast IP    */
 754                  qstruct->hwadr[1] = 0xFF;
 755                  qstruct->hwadr[2] = 0xFF;
 756                  qstruct->hwadr[3] = 0xFF;
 757                  qstruct->hwadr[4] = 0xFF;
 758                  qstruct->hwadr[5] = 0xFF;
 759                  qstruct->retries = ARP_MAXRETRY;
 760                  qstruct->ttl = ARP_RESEND;
 761                  arp_send_req( i );
 762                  qstruct->state = ARP_PENDING;                           /* Waiting for Reply    */
 763                  
 764                  return(0);
 765          
 766                  
 767          }
 768          
 769          /** \brief Manage ARP cache periodically
 770           *      \ingroup periodic_functions
 771           *      \author 
 772           *              \li Jari Lahti (jari.lahti@violasystems.com)
 773           *      \date 04.11.2001
 774           *      \warning
 775           *              \li Invoke this function periodically to ensure proper ARP
 776           *              cache behaviour
 777           *
 778           *      Iterate through ARP cache aging entries. If timed-out entry is found,
 779           *      remove it (dynamic address) or update it (static address). This function
 780           *      must be called periodically by the system.
 781           *
 782           */
 783          void arp_manage (void)
 784          {
 785                  struct arp_entry *qstruct;
 786                  UINT8 i,j;
 787                  static UINT8 aenext=0;
C51 COMPILER V7.06   ARP                                                                   11/26/2004 11:32:44 PAGE 14  

 788                  
 789                  /* Check Timer before entering  */
 790                  
 791                  if( check_timer(arp_timer) )
 792                          return;
 793                          
 794                  init_timer( arp_timer, ARP_MANG_TOUT*TIMERTIC);
 795                  
 796                  /* DEBUGOUT("Managing ARP Cache\n\r"); */
 797                  
 798                  for( i=0; i<ARP_TSIZE; i++ ) {
 799                          /* DEBUGOUT("."); */
 800                  
 801                          qstruct = &arp_table[aenext];
 802                          
 803                          j = aenext;
 804                          
 805                          /* Take next entry next time    */
 806                                          
 807                          aenext++;
 808                          if(aenext >= ARP_TSIZE)
 809                                  aenext = 0;     
 810                  
 811                          if( qstruct->state == ARP_FREE )
 812                                  continue;
 813                                  
 814                          /* TODO: How about ARP_RESERVED?        */
 815                                  
 816                          if( qstruct->ttl > 0 )                          /* Aging                */
 817                                  qstruct->ttl --;
 818                          
 819                          if( qstruct->ttl == 0 ) {                       /* Timed Out?   */
 820                                  /* Do it for temporay entries   */
 821                                  
 822                                  ARP_DEBUGOUT("Found Timed out Entry..\n\r");
 823                          
 824                                  if( qstruct->type == ARP_TEMP_IP ) {
 825          
 826                                          /* Release it?  */
 827                                          if( qstruct->state == ARP_RESOLVED ) {  
 828                                                  ARP_DEBUGOUT("Releasing ARP Entry..\n\r");
 829                                                  qstruct->state = ARP_FREE;
 830                                                  continue;
 831                                          }
 832                                          
 833                                          /* Decrease retries left        */
 834                                          
 835                                          if( qstruct->retries > 0 )      
 836                                                  qstruct->retries--;
 837                                          
 838                                          if( qstruct->retries == 0 )     {
 839                                                  ARP_DEBUGOUT("ARP Replies Used up, releasing entry..\n\r");
 840                                                  qstruct->state = ARP_FREE;
 841                                                  continue;
 842                                          }
 843                                          
 844                                          /* So we need to resend ARP request     */
 845                                          
 846                                          ARP_DEBUGOUT("Trying to Resolve dynamic ARP Entry..\n\r");
 847                                  
 848                                          qstruct->ttl = ARP_RESEND;
 849                                          arp_send_req( j );
C51 COMPILER V7.06   ARP                                                                   11/26/2004 11:32:44 PAGE 15  

 850                                          qstruct->state = ARP_PENDING;                           /* Waiting for Reply    */                      
 851                                          
 852                                          return;
 853                                  
 854                                  }
 855                          
 856                                  /* Do it for Static Entries                     */
 857                          
 858                                  if( qstruct->type == ARP_FIXED_IP ) {
 859                                          
 860                                          /* So we need to resend ARP request     */
 861                                          
 862                                          /* Do not try to refresh broadcast      */
 863                                          
 864                                          if(qstruct->pradr == IP_BROADCAST_ADDRESS)      {
 865                                                  qstruct->ttl = ARP_TIMEOUT;
 866                                                  continue;
 867                                          }
 868                                          
 869                                          ARP_DEBUGOUT("Refreshing Static ARP Entry..\n\r");
 870                                          
 871                                          if( qstruct->retries > 0 )      
 872                                                  qstruct->retries--;
 873                                          
 874                                          if( qstruct->retries == 0 )
 875                                                  qstruct->state = ARP_PENDING;
 876                                          else
 877                                                  qstruct->state = ARP_REFRESHING;
 878                                  
 879                                          qstruct->ttl = ARP_RESEND;
 880                                          
 881                                          arp_send_req( j );
 882                                          
 883                                          return;
 884                                  
 885                                  }
 886                          
 887                          }
 888                  
 889                  }
 890          
 891          
 892          }
 893          
 894          
 895          
 896          /** \brief Initialize data structures for ARP processing
 897           *      \ingroup core_initializer
 898           *      \author 
 899           *              \li Jari Lahti (jari.lahti@violasystems.com)
 900           *      \date 01.11.2001
 901           *      \warning 
 902           *              \li Invoke this function at start-up to properly initialize
 903           *              ARP cache subsystem.
 904           *
 905           *      Call this function to properly initialize ARP cache table and so that
 906           *      ARP allocates and initializes a timer for it's use.
 907           */
 908          void arp_init (void)
 909          {
 910                  struct arp_entry *qstruct;
 911                  INT8 i;
C51 COMPILER V7.06   ARP                                                                   11/26/2004 11:32:44 PAGE 16  

 912                  
 913                  ARP_DEBUGOUT("Initializing ARP");
 914                  
 915                  for( i=0; i<ARP_TSIZE; i++ ) {
 916                          qstruct = &arp_table[i];
 917                          
 918                          qstruct->state = ARP_FREE;
 919                          qstruct->type = ARP_TEMP_IP;
 920                          
 921                          ARP_DEBUGOUT(".");
 922                  }
 923                  
 924                  arp_timer = get_timer();
 925                  init_timer(arp_timer, ARP_MANG_TOUT*TIMERTIC);
 926          
 927                  /* set broadcast entry  */
 928                  
 929                  qstruct = &arp_table[0];
 930                  qstruct->pradr = IP_BROADCAST_ADDRESS;
 931                  qstruct->state = ARP_RESOLVED;
 932                  qstruct->type = ARP_FIXED_IP;
 933                  qstruct->ttl = ARP_TIMEOUT;
 934                  qstruct->retries = ARP_MAXRETRY;        
 935                  
 936                  for(i=0; i<MAXHWALEN; i++)
 937                          qstruct->hwadr[i] = 0xFF;                                                       
 938                  
 939                  ARP_DEBUGOUT("\n\r");
 940                  
 941          }
 942          /** \brief Checks if a given IP address belongs to the subnet of a
 943                          given machine
 944           *      \author 
 945           *              \li Jari Lahti (jari.lahti@violasystems.com)
 946           *      \date 05.11.2001
 947           *      \param ipadr - IP address under check
 948           *      \param machine - pointer to configuration of network parameters used
 949           *      \return
 950           *              \li #TRUE - ipadr belongs to subnet of given machine
 951           *              \li #FALSE - ipadr is NOT a part of subnet of given machine 
 952           *
 953           *      Based on information supplied in ipadr and machine parameters this
 954           *      function performs basic check if IP address is on the same subnet as
 955           *      the one defined for the machine. 
 956           *
 957           */
 958          BYTE is_subnet (LWORD ipadr, struct netif* machine)
 959          {
 960          
 961                  UINT32 ltemp;
 962          
 963                  ltemp = ipadr & machine->netmask;                                               /* Get Subnet part      */
 964                  
 965                  ltemp ^= (machine->localip & machine->netmask);                 /* Compare to my IP     */
 966                  
 967                  if( ltemp )
 968                          return(FALSE);
 969                  
 970                  return(TRUE);
 971          
 972          }

C51 COMPILATION COMPLETE.  7 WARNING(S),  3 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -