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

📄 ping.lst

📁 W3100是WIZnet公司专门为以太网互联和嵌入式设备推出的硬件TCP/IP协议栈芯片
💻 LST
📖 第 1 页 / 共 2 页
字号:
 120   2      
 121   2                      (*log).PingRequest++;                           // Increase PingRequest's value
 122   2      
 123   2                      if(sendto(s, (char xdata*)&PingRequest,size+8,(u_char*)&peerip,3000)==-1)       // Send Ping-Request to the sp
             -ecified peer. If fail, then it is occurred ARP Error.
 124   2                      {
 125   3                              (*log).ARPErr++;                        // Increase ARPErr
 126   3                              close(s);                               // close the pinging socket
 127   3                              /* Reopen pinging socket */
 128   3                              setIPprotocol(s,IPPROTO_ICMP);          
 129   3                              if(socket(s,SOCK_IPL_RAW,3000,0)==-1) return -1;
 130   3                              continue;
 131   3                      }
 132   2                      while(RemainTime-- > 0) // until wait_time is remaining 
 133   2                      {
 134   3                              if((len = select(s,SEL_RECV)) > 0)              // Is pinging socket  received a packet?
 135   3                              {
 136   4                                      len = recvfrom(s,(char xdata *)&PingReply,len,tempip,&port);    // receive a packet from unknown peer
 137   4                                      inet_ntoa((u_char*)&tempip,addrstr);                            // convert 32 bit unknown peer IP addr
             -ess into string of IP Address.
 138   4                                      PutString("Reply from ");PutString(addrstr);
 139   4                                      if(checksum((char xdata *)&PingReply,len) != 0)                 // if the packet's checksum value is correct
 140   4                                      {                                                               // not correct
 141   5                                              (*log).CheckSumErr++;                                   // checksum error
 142   5                                              if( *((u_long*)tempip) == peerip ) IsReceived = 1;       
 143   5                                              PutStringLn(" : Checksum Error"); 
 144   5                                      }
 145   4                                      else if(PingReply.Type == 0)                                    // if the received packet is ping-reply 
 146   4                                      {
 147   5                                              if((PingReply.ID != PingRequest.ID) || (PingReply.SeqNum != PingRequest.SeqNum) // verify id,sequence
             - nubmer, and ip address
 148   5                                                     || (*((u_long*)tempip) != peerip) )
 149   5                                              {                                                       // fail to verify 
 150   6                                                      PutStringLn(" : Unknown peer.");
 151   6                                                      (*log).UnknownMSG++;
 152   6                                              }
 153   5                                              else                                                    // success
 154   5                                              {
 155   6                                                      IsReceived = 1;
 156   6                                                      PutString(" : bytes=");PutString(ITOA(len-8,tempip,10));PutString(" time<");PutString(ITOA(time-Rema
             -inTime,tempip,10));PutStringLn("ms");
 157   6                                                      (*log).PingReply++;
 158   6                                              }
 159   5                                      }
 160   4                                      else if( PingReply.Type == 3)                                   // If the packet is unreachable message
 161   4                                      {                                                               
 162   5                                              IsReceived = 1;
 163   5                                              PutStringLn(" : Destination Unreachable.");
 164   5                                              (*log).UnreachableMSG++;
 165   5                                      }
 166   4                                      else if( PingReply.Type == 11)                                  // If the packet is time exceeded message
 167   4                                      {
 168   5                                              IsReceived = 1;
C51 COMPILER V8.02   PING                                                                  10/17/2006 16:47:04 PAGE 4   

 169   5                                              PutStringLn(" : TTL expired in transit.");
 170   5                                              (*log).TimeExceedMSG++;
 171   5                                      }
 172   4                                      else                                                            // if the packet is unknown message
 173   4                                      {
 174   5                                              PutString(" : Unknown Message. (type = ");PutString(ITOA(PingReply.Type,tempip,10));PutStringLn(")");
 175   5                                              (*log).UnknownMSG++;
 176   5                                      }
 177   4                              }
 178   3                              else if(select(s,SEL_CONTROL)==SOCK_CLOSED)                             // if it is occurred to fail to send arp packet
 179   3                              {
 180   4                                      (*log).ARPErr++;
 181   4                                      close(s);                                                       // close the pinging socket
 182   4                                      setIPprotocol(s,IPPROTO_ICMP);                                  // Reopen the pinging socket
 183   4                                      if(socket(s,SOCK_IPL_RAW,3000,0)==-1) return -1;
 184   4                                      break;
 185   4                              }
 186   3                              if(RemainTime == 0 && IsReceived == 0)                                  // If it is not received packet from the specified peer duri
             -ng waiting ping-reply packet.
 187   3                              {
 188   4                                      (*log).Loss++;
 189   4                                      PutStringLn("Request timed out.");
 190   4                              }
 191   3                              wait_1us(200);
 192   3                      }
 193   2              }
 194   1              PutStringLn("");
 195   1      
 196   1              /* Release pinging socket */
 197   1              setIPprotocol(s,0);
 198   1              close(s);
 199   1              return 1;
 200   1      }
 201          
 202          
 203          /*
 204          Description   :  Display result of ping 
 205          Argument      :  log - result of ping
 206          Return Value  :  None.
 207          Note          :  
 208          */
 209          void DisplayPingStatistics(PINGLOG log)
 210          {
 211   1              char Num[7];
 212   1              PutStringLn("Ping statistics :");
 213   1              PutString("\tPackets: Sent = ");PutString(ITOA(log.PingRequest,Num,10));
 214   1              PutString(", Received = ");PutString(ITOA(log.PingReply+log.CheckSumErr+log.UnknownMSG+log.UnreachableMSG
             -+log.TimeExceedMSG,Num,10));
 215   1              PutString(", Lost = ");PutStringLn(ITOA(log.Loss+log.ARPErr,Num,10));
 216   1              if(log.CheckSumErr > 0)
 217   1              {
 218   2                      PutString("\t\tChecksum Error Packets = ");PutStringLn(ITOA(log.CheckSumErr,Num,10));
 219   2              }
 220   1              if(log.UnreachableMSG > 0)
 221   1              {
 222   2                      PutString("\t\tUnreachable Message Packets = ");PutStringLn(ITOA(log.UnreachableMSG,Num,10));
 223   2              }
 224   1              if(log.TimeExceedMSG > 0)
 225   1              {
 226   2                      PutString("\t\tTime Exceeded Messsage Packets = ");PutStringLn(ITOA(log.TimeExceedMSG,Num,10));
 227   2              }
 228   1              if(log.UnknownMSG > 0)
C51 COMPILER V8.02   PING                                                                  10/17/2006 16:47:04 PAGE 5   

 229   1              {
 230   2                      PutString("\t\tUnknown Message Packets = ");PutStringLn(ITOA(log.UnknownMSG,Num,10));
 231   2              }
 232   1              if(log.ARPErr > 0)
 233   1              {
 234   2                      PutString("\t\tFail To Send ARP Packet  = ");PutStringLn(ITOA(log.ARPErr,Num,10));
 235   2              }
 236   1              if(log.Loss > 0)
 237   1              {
 238   2                      PutString("\t\tRequest timed out = ");PutStringLn(ITOA(log.Loss,Num,10));
 239   2              }
 240   1              if(log.PingReply > 0)
 241   1              {
 242   2                      PutString("\t\tPing Reply Packets = ");PutStringLn(ITOA(log.PingReply,Num,10));
 243   2              }
 244   1      }

C51 COMPILATION COMPLETE.  1 WARNING(S),  1 ERROR(S)

⌨️ 快捷键说明

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