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

📄 tcpserver.lst

📁 cf8020+cp2200(网络)的驱动实现
💻 LST
字号:
C51 COMPILER V7.09   TCPSERVER                                                             07/27/2007 15:11:26 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE TCPSERVER
OBJECT MODULE PLACED IN TCPSERVER.obj
COMPILER INVOKED BY: F:\Keil\C51\BIN\C51.EXE tcp\TCPSERVER.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\TCPSERVER.lst) OBJE
                    -CT(TCPSERVER.obj)

line level    source

   1          #include <stdlib.h>
   2          #include <ctype.h>              // toupper
   3          #include "net.h"
   4           
   5          #include "cksum.h"
   6          #include "ip.h"
   7          #include "tcp.h"
   8          #include "udp.h"
   9          #include "tcpserver.h"
  10          
  11          #include "utils.h"
  12          
  13          
  14          // These structures keep track of connection information
  15          extern CONNECTION  conxn[];
  16           
  17          extern ulong  my_ipaddr;
  18          extern char  text[];
  19          extern UCHAR  rcve_buf_allocated;
  20          extern UCHAR  debug;
  21          extern UCHAR TFTP_BUF[];
  22          char cnt = 0;
  23          
  24          
  25          //------------------------------------------------------------------------
  26          // This sends an TCP segment to the ip layer.  The segment is 
  27          // is normally either a web page or a graphic.
  28          // See "TCP/IP Illustrated, Volume 1" Sect 17.3
  29          //------------------------------------------------------------------------
  30          void tcp_server_send(UCHAR  * outbuf, uint len, UCHAR nr)
  31          {
  32   1         TCP_HEADER  * tcp;
  33   1         IP_HEADER  * ip;
  34   1         ulong  sum;
  35   1         uint  result;
  36   1                
  37   1         // Fill in TCP segment header
  38   1         tcp = (TCP_HEADER  *)(outbuf + 34);
  39   1         ip = (IP_HEADER  *)(outbuf + 14);
  40   1      
  41   1         tcp->source_port = HTTP_PORT;
  42   1         tcp->dest_port = conxn[nr].port;
  43   1         tcp->sequence = conxn[nr].my_sequence;
  44   1         tcp->ack_number = conxn[nr].his_sequence;
  45   1            
  46   1              // Header is always 20 bytes long
  47   1         tcp->flags = 0x5000 | FLG_ACK | FLG_PSH;
  48   1         tcp->window = 1024;
  49   1      
  50   1         tcp->checksum = 0;
  51   1         tcp->urgent_ptr = 0;
  52   1         
  53   1         // Compute checksum including 12 bytes of pseudoheader
  54   1              // Must pre-fill 2 items in ip header to do this
C51 COMPILER V7.09   TCPSERVER                                                             07/27/2007 15:11:26 PAGE 2   

  55   1              ip->dest_ipaddr = conxn[nr].ipaddr;
  56   1              ip->source_ipaddr = my_ipaddr;
  57   1      
  58   1      #ifdef __LITTLEENDIAN__
                      tcp->flags = ntohs(tcp->flags);
                      tcp->window = ntohs(tcp->window);
                      tcp->source_port = ntohs(tcp->source_port);
                      tcp->sequence = ntohl(tcp->sequence);   
                      tcp->dest_port = ntohs(tcp->dest_port);
                      tcp->ack_number = ntohl(tcp->ack_number);
                      ip->source_ipaddr = ntohl(my_ipaddr);
              #endif
  67   1                      
  68   1              // Sum source_ipaddr, dest_ipaddr, and entire TCP message 
  69   1              sum = (ulong)cksum(outbuf + 26, 8 + len);
  70   1                                      
  71   1              // Add in the rest of pseudoheader which is
  72   1              // protocol id and TCP segment length
  73   1              sum += (ulong)0x0006;
  74   1              sum += (ulong)len;
  75   1      
  76   1              // In case there was a carry, add it back around
  77   1              result = (uint)(sum + (sum >> 16));
  78   1              tcp->checksum = ~result;
  79   1         
  80   1      #ifdef __LITTLEENDIAN__
                              tcp->checksum = ntohs(tcp->checksum);
              //              ip_send(outbuf, ntohl(conxn[nr].ipaddr), TCP_TYPE, len);                
                              conxn[nr].ipaddr = ntohl(conxn[nr].ipaddr);
              #endif
  85   1      //   if (debug) serial_send("TCP: Sending msg to IP layer\r");
  86   1                      ip_send(outbuf, conxn[nr].ipaddr, TCP_TYPE, len);       
  87   1      #ifdef __LITTLEENDIAN__
                      free(outbuf);
              #endif
  90   1      
  91   1      
  92   1         // (Re)start TCP retransmit timer
  93   1         conxn[nr].timer = TCP_TIMEOUT;
  94   1      }
  95          
  96          
  97          
  98          //------------------------------------------------------------------------
  99          // This searches a web page looking for a specified tag.  If found,
 100          // it replaces the tag with the text in * sub.  Tags are fixed length -
 101          // The first 4 chars of the tag is always "TAG:" and the rest of it
 102          // is always 4 chars for a total of 8 chars. 
 103          //------------------------------------------------------------------------
 104          
 105          
 106          
 107          
 108          //------------------------------------------------------------------------
 109          //      This serves up either a HTML page, a JPEG image, or controls an 
 110          // LED,  depending what it gets from the browser.  The received header
 111          // must contain the word "GET" or "POST" to be considered a valid request.
 112          // With HTTP 1.1 where the connection is left open, the header I send
 113          // should include content length. With HTTP 1.0 you can just close the
 114          // connection after sending the page and the browser knows its done. 
 115          //
 116          // The HTTP protocol specification is at http://www.w3.org/Protocols/ 
C51 COMPILER V7.09   TCPSERVER                                                             07/27/2007 15:11:26 PAGE 3   

 117          //------------------------------------------------------------------------
 118          uint tcp_server_recv(UCHAR  * inbuf, uint header_len, UCHAR nr, UCHAR resend, int data_len)
 119          {
 120   1              UCHAR  * outbuf;
 121   1              UCHAR  * tcp_data;
 122   1      
 123   1              // Make sure this is a valid connection
 124   1              if (nr == NO_CONNECTION) 
 125   1                      return 0;
 126   1              
 127   1              // Compute start of TCP data
 128   1              
 129   1         // Save first 20 chars and seq number just in case
 130   1         // we need to re-generate page
 131   1         // TODO: if post, then save switch state infomation
 132   1         
 133   1         if (!resend)
 134   1         {
 135   2            tcp_data = inbuf + 34 + header_len;
 136   2            memcpy((char*)conxn[nr].query, tcp_data, 20);
 137   2            conxn[nr].old_sequence = conxn[nr].my_sequence;
 138   2         }
 139   1         // If this is a resend, set sequence number to what it was
 140   1         // the last time we sent this
 141   1         else
 142   1         {
 143   2            tcp_data = inbuf;
 144   2            conxn[nr].my_sequence = conxn[nr].old_sequence;   
 145   2         } 
 146   1         if(data_len>0)
 147   1         {
 148   2                         // Free memory holding received message.  The message from the
 149   2                         // browser can be 500+ bytes long so this is a significant 
 150   2                         // chunk out of the available malloc space of 1500 bytes
 151   2                 if (!resend) {rcve_buf_allocated = FALSE;}
 152   2                         
 153   2                 outbuf = TX_BUFF;
 154   2                 if (outbuf == NULL)
 155   2                 {
 156   3                         return 0;
 157   3                 }
 158   2                 memcpy(outbuf + 54, tcp_data, data_len);
 159   2                 
 160   2                 tcp_server_send(outbuf, 20 + data_len, nr);                     
 161   2         
 162   2                 conxn[nr].my_sequence += data_len;     
 163   2                 
 164   2              //   udp_broadcast(TFTP_BUF, 7001, data_len);   
 165   2      
 166   2         }
 167   1         return 0;   
 168   1      
 169   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    982    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      1      31
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
C51 COMPILER V7.09   TCPSERVER                                                             07/27/2007 15:11:26 PAGE 4   

   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 + -