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

📄 icmp.lst

📁 一个通过8051来控制8019上网的程序 该程序已经通过并成功用于键盘
💻 LST
字号:
C51 COMPILER V7.06   ICMP                                                                  06/26/2004 13:41:25 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE ICMP
OBJECT MODULE PLACED IN ICMP.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ICMP.C LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          // Net ICMP.C
   3          //
   4          // This module handles ICMP messages
   5          // Refer to RFC 792, 896, 950, 1122, and 1191
   6          //-----------------------------------------------------------------------------
   7          #include <string.h>
   8          #include <stdlib.h>
   9          #include <stdio.h>
  10          #include <reg89C58.h>
  11          #include "net.h"
  12          #include "cksum.h"
  13          #include "ip.h"
  14          //#include "serial.h"
  15          #include "icmp.h"
  16          
  17          extern UCHAR idata debug;
  18          
  19          
  20          //------------------------------------------------------------------------
  21          // This builds a ping response message.  It allocates memory for the
  22          // entire outgoing message, including Eth and IP headers.  See "TCP/IP
  23          // Illustrated, Volume 1" Sect 7.2 for info on Ping messages
  24          //------------------------------------------------------------------------
  25          void ping_send(UCHAR xdata * inbuf, ULONG ipaddr, UINT len)
  26          {
  27   1         PING_HEADER xdata * ping_in;
  28   1         PING_HEADER xdata * ping_out;
  29   1         UCHAR xdata * outbuf;
  30   1                  
  31   1         ping_in = (PING_HEADER xdata *)(inbuf + 34);
  32   1            
  33   1         // Allocate memory for entire outgoing message
  34   1         outbuf = (UCHAR xdata *)malloc(len + 34);
  35   1         if (outbuf == NULL)
  36   1         {
  37   2         //   if (debug) printf("PING: Oops, out of memory\n");
  38   2            return;
  39   2         }      
  40   1            
  41   1         // Ping response message payload starts at offset 34
  42   1         ping_out = (PING_HEADER xdata *)(outbuf + 34);
  43   1      
  44   1         ping_out->msg_type = 0;
  45   1         ping_out->msg_code = 0;
  46   1         ping_out->checksum = 0;
  47   1         ping_out->identifier = ping_in->identifier;
  48   1         ping_out->sequence = ping_in->sequence;
  49   1         
  50   1         memcpy(&ping_out->echo_data, &ping_in->echo_data, len - 8);
  51   1                  
  52   1         // Compute checksum over the ICMP header plus
  53   1              // optional data and insert complement
  54   1         ping_out->checksum = ~cksum(outbuf + 34, len);
  55   1                              
C51 COMPILER V7.06   ICMP                                                                  06/26/2004 13:41:25 PAGE 2   

  56   1       //  if (debug) printf("ICMP: Sending response to IP layer\n");
  57   1      
  58   1         ip_send(outbuf, ipaddr, ICMP_TYPE, len);
  59   1      }
  60          
  61          
  62          /*
  63          //------------------------------------------------------------------------
  64          // This builds an outgoing ICMP destination port unreachable response
  65          // message.  See See "TCP/IP Illustrated, Volume 1" Sect 6.5.  This
  66          // message is typically sent in response to a UDP message directed
  67          // to a port that has no corresponding application running. 
  68          // Todo: The spec says we should return all options that were in
  69          // the original incoming IP header.  Right now we cut off everything
  70          // after the first 20 bytes. 
  71          //------------------------------------------------------------------------
  72          void dest_unreach_send(UCHAR xdata * inbuf, ULONG ipaddr)
  73          {
  74             UCHAR xdata * outbuf;
  75             ICMP_ERR_HEADER xdata * icmp;
  76                      
  77             // Allocate memory for entire outgoing message
  78             // including eth and IP haders.  Always 70 bytes
  79             outbuf = (UCHAR xdata *)malloc(70);
  80             if (outbuf == NULL)
  81             {
  82           //     if (debug) printf("ICMP: Oops, out of memory\n");
  83                return;
  84             }      
  85                
  86             icmp = (ICMP_ERR_HEADER xdata *)(outbuf + 34);
  87             
  88             // Fill in ICMP error message header
  89             icmp->msg_type = 3;   // destination unreachable
  90             icmp->msg_code = 3;   // port unreachable
  91             icmp->checksum = 0;
  92                
  93             // Fill in ICMP error message data
  94             icmp->msg_data = 0;
  95                     
  96             // Copy in 20 byte original incoming IP header
  97             // plus 8 bytes of data
  98             memcpy(&icmp->echo_data, inbuf + 14, 28);
  99                                         
 100             // Compute checksum over the 36 byte long ICMP
 101             // header plus data and insert complement
 102             icmp->checksum = ~cksum(outbuf + 34, 36);
 103                
 104             // Forward message to the IP layer
 105           //  if (debug) printf("ICMP: Sending dest unreach to IP layer\n");
 106             ip_send(outbuf, ipaddr, ICMP_TYPE, 36);
 107          }
 108          */
 109          
 110          
 111          
 112          //------------------------------------------------------------------------
 113          // This handles incoming ICMP messages.  See "TCP/IP Illustrated,
 114          // Volume 1" Sect 6.2 for discussion of the various ICMP messages
 115          //------------------------------------------------------------------------
 116          void icmp_rcve(UCHAR xdata * inbuf, UINT len)
 117          {
C51 COMPILER V7.06   ICMP                                                                  06/26/2004 13:41:25 PAGE 3   

 118   1         IP_HEADER * ip;
 119   1         UCHAR idata msg_type;
 120   1         UINT idata temp;
 121   1         
 122   1         // Allow for 14 bytes eth header
 123   1         ip = (IP_HEADER *)(inbuf + 14);
 124   1              
 125   1         // IP header has been adjusted if necessary to always be 
 126   1              // 20 bytes so message starts at an offset of 34
 127   1         // Validate checksum of entire ICMP message incl data 
 128   1              temp = cksum(inbuf + 34, len);
 129   1              
 130   1              if (temp != 0xFFFF)
 131   1              {
 132   2      //              if (debug) printf("ICMP: Error, cksum bad\n");
 133   2            return; 
 134   2         }
 135   1            
 136   1         // Switch on the message type
 137   1         msg_type = *(inbuf + 34);
 138   1         switch(msg_type)
 139   1         {
 140   2            case 3:
 141   2        //    if (debug) printf("ICMP: Dest unreachable rcvd\n");
 142   2            break;
 143   2      
 144   2                 case 8:
 145   2        //    if (debug) printf("ICMP: Ping rcvd\n");
 146   2            ping_send(inbuf, ip->source_ipaddr, len); 
 147   2            break;
 148   2      
 149   2            default:
 150   2       //     if (debug) printf("ICMP: Error, unknown msg rcvd\n");
 151   2            break;
 152   2         }
 153   1      }
 154          
 155          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    466    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----      21
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----       3
   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 + -