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

📄 uip.lst

📁 c51版本的uip(一个超小型的TCPIP栈,支持tcpudparpicmp.
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V7.08   UIP                                                                   12/26/2003 07:27:14 PAGE 1   


C51 COMPILER V7.08, COMPILATION OF MODULE UIP
OBJECT MODULE PLACED IN uip.OBJ
COMPILER INVOKED BY: C:\Keil708\C51\BIN\C51.EXE uip.c LARGE BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          * Copyright (c) 2001-2002, Adam Dunkels.
   3          * All rights reserved. 
   4          *
   5          * Redistribution and use in source and binary forms, with or without 
   6          * modification, are permitted provided that the following conditions 
   7          * are met: 
   8          * 1. Redistributions of source code must retain the above copyright 
   9          *    notice, this list of conditions and the following disclaimer. 
  10          * 2. Redistributions in binary form must reproduce the above copyright 
  11          *    notice, this list of conditions and the following disclaimer in the 
  12          *    documentation and/or other materials provided with the distribution. 
  13          * 3. All advertising materials mentioning features or use of this software
  14          *    must display the following acknowledgement:
  15          *      This product includes software developed by Adam Dunkels.
  16          * 4. The name of the author may not be used to endorse or promote
  17          *    products derived from this software without specific prior
  18          *    written permission.  
  19          *
  20          * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  21          * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22          * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23          * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  24          * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25          * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  26          * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27          * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28          * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29          * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30          * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  31          *
  32          * This file is part of the uIP TCP/IP stack.
  33          *
  34          * $Id: uip.c,v 1.2 2003/04/15 04:52:38 qs Exp $
  35          *
  36          */
  37          
  38          /*
  39          This is a small implementation of the IP and TCP protocols (as well as
  40          some basic ICMP stuff). The implementation couples the IP, TCP and the
  41          application layers very tightly. To keep the size of the compiled code
  42          down, this code also features heavy usage of the goto statement.
  43          
  44            The principle is that we have a small buffer, called the uip_buf, in which
  45            the device driver puts an incoming packet. The TCP/IP stack parses the
  46            headers in the packet, and calls upon the application. If the remote
  47            host has sent data to the application, this data is present in the uip_buf
  48            and the application read the data from there. It is up to the
  49            application to put this data into a byte stream if needed. The
  50            application will not be fed with data that is out of sequence.
  51            
  52                  If the application whishes to send data to the peer, it should put its
  53                  data into the uip_buf, 40 bytes from the start of the buffer. The TCP/IP
  54                  stack will calculate the checksums, and fill in the necessary header
  55          fields and finally send the packet back to the peer. */
C51 COMPILER V7.08   UIP                                                                   12/26/2003 07:27:14 PAGE 2   

  56          
  57          #include "uipopt.h"
  58          #include "uip.h"
  59          #include "uip_arch.h"
  60          
  61          /*-----------------------------------------------------------------------------------*/
  62          /* Variable definitions. */
  63          
  64          u8_t uip_buf[UIP_BUFSIZE];   /* The packet buffer that contains
  65          incoming packets. */
  66          volatile u8_t *uip_appdata;  /* The uip_appdata pointer points to
  67          application data. */
  68          
  69          #if UIP_BUFSIZE > 255
  70          volatile u16_t uip_len;      /* The uip_len is either 8 or 16 bits,
  71                                                                   depending on the maximum packet
  72          size. */
  73          #else
              volatile u8_t uip_len;
              #endif /* UIP_BUFSIZE > 255 */
  76          
  77          volatile u8_t uip_flags;     /* The uip_flags variable is used for
  78                                                                   communication between the TCP/IP stack
  79          and the application program. */
  80          struct uip_conn *uip_conn;   /* uip_conn always points to the current
  81          connection. */
  82          
  83          struct uip_conn uip_conns[UIP_CONNS];
  84          /* The uip_conns array holds all TCP
  85          connections. */
  86          u16_t uip_listenports[UIP_LISTENPORTS];
  87          /* The uip_listenports list all currently
  88          listning ports. */
  89          
  90          
  91          static u16_t ipid;           /* Ths ipid variable is an increasing
  92                                                                   number that is used for the IP ID
  93          field. */
  94          
  95          static u8_t iss[4];          /* The iss variable is used for the TCP
  96          initial sequence number. */
  97          
  98          #if UIP_ACTIVE_OPEN
              static u16_t lastport;       /* Keeps track of the last port used for
              a new connection. */
              #endif /* UIP_ACTIVE_OPEN */
 102          
 103          /* Temporary variables. */
 104          static u8_t c, opt;
 105          static u16_t tmpport;
 106          
 107          /* Structures and definitions. */
 108          typedef struct {
 109                  /* IP header. */
 110                  u8_t vhl,
 111                          tos,          
 112                          len[2],       
 113                          ipid[2],        
 114                          ipoffset[2],  
 115                          ttl,          
 116                          proto;     
 117                  u16_t ipchksum;
C51 COMPILER V7.08   UIP                                                                   12/26/2003 07:27:14 PAGE 3   

 118                  u16_t srcipaddr[2], 
 119                          destipaddr[2];
 120                  /* ICMP (echo) header. */
 121                  u8_t type, icode;
 122                  u16_t icmpchksum;
 123                  u16_t id, seqno;  
 124          } ipicmphdr;
 125          
 126          #define TCP_FIN 0x01
 127          #define TCP_SYN 0x02
 128          #define TCP_RST 0x04
 129          #define TCP_PSH 0x08
 130          #define TCP_ACK 0x10
 131          #define TCP_URG 0x20
 132          
 133          #define IP_PROTO_ICMP   1
 134          #define IP_PROTO_TCP    6
 135          
 136          #define ICMP_ECHO_REPLY 0
 137          #define ICMP_ECHO       8     
 138          
 139          /* Macros. */
 140          #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
 141          #define ICMPBUF ((ipicmphdr *)&uip_buf[UIP_LLH_LEN])
 142          
 143          #if UIP_STATISTICS == 1
 144          struct uip_stats uip_stat;
 145          #define UIP_STAT(s) s
 146          #else
              #define UIP_STAT(s)
              #endif /* UIP_STATISTICS == 1 */
 149          
 150          
 151          
 152          #if UIP_LOGGING == 1
              #ifdef DEBUG_TO_FILE
              extern FILE *dbgFile;
              #define UIP_LOG(m) fprintf(dbgFile,"%s\n", m)
              #else
              #define UIP_LOG(m) printf("%s\n", m) 
              #endif
              #else
 160          #define UIP_LOG(m)
 161          #endif /* UIP_LOGGING == 1 */
 162          
 163          /*-----------------------------------------------------------------------------------*/
 164          void
 165          uip_init(void)
 166          {
 167   1              for(c = 0; c < UIP_LISTENPORTS; ++c) {
 168   2                      uip_listenports[c] = 0;
 169   2              }
 170   1              for(c = 0; c < UIP_CONNS; ++c) {
 171   2                      uip_conns[c].tcpstateflags = CLOSED;
 172   2              }
 173   1      #if UIP_ACTIVE_OPEN
                      lastport = 1024;
              #endif /* UIP_ACTIVE_OPEN */
 176   1      }
 177          /*-----------------------------------------------------------------------------------*/
 178          #if UIP_ACTIVE_OPEN
              struct uip_conn *
C51 COMPILER V7.08   UIP                                                                   12/26/2003 07:27:14 PAGE 4   

              uip_connect(u16_t *ripaddr, u16_t rport)
              {
                      struct uip_conn *conn;
                      
                      /* Find an unused local port. */
              again:
                      ++lastport;
                      
                      if(lastport >= 32000) {
                              lastport = 4096;
                      }
                      
                      for(c = 0; c < UIP_CONNS; ++c) {
                              if(uip_conns[c].tcpstateflags != CLOSED &&
                                      uip_conns[c].lport == lastport)
                                      goto again;
                      }
                      
                      
                      for(c = 0; c < UIP_CONNS; ++c) {
                              if(uip_conns[c].tcpstateflags == CLOSED) 
                                      goto found_unused;
                      }
                      for(c = 0; c < UIP_CONNS; ++c) {
                              if(uip_conns[c].tcpstateflags == TIME_WAIT) 
                                      goto found_unused;
                      }
                      return (void *)0;
                      
              found_unused:
                      

⌨️ 快捷键说明

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