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

📄 uip.lst

📁 c8051f020_uip1.0.rar
💻 LST
📖 第 1 页 / 共 5 页
字号:
 811   6                     label). */
 812   6                  uip_flags = UIP_REXMIT;
 813   6                  UIP_APPCALL();
 814   6                  goto apprexmit;
 815   6                  
 816   6                case UIP_FIN_WAIT_1:
 817   6                case UIP_CLOSING:
 818   6                case UIP_LAST_ACK:
 819   6                  /* In all these states we should retransmit a FINACK. */
 820   6                  goto tcp_send_finack;
 821   6                  
 822   6                }
 823   5              }
 824   4            } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
 825   4              /* If there was no need for a retransmission, we poll the
 826   4                 application for new data. */
 827   4              uip_flags = UIP_POLL;
 828   4              UIP_APPCALL();
 829   4              goto appsend;
 830   4            }
 831   3          }
 832   2          goto drop;
 833   2        }
 834   1      #endif /* UIP_TCP */
 835   1      #if UIP_UDP
 836   1        if(flag == UIP_UDP_TIMER) {
 837   2          if(uip_udp_conn->lport != 0) {
 838   3      #if UIP_TCP
 839   3            uip_conn = NULL;
 840   3      #endif /* UIP_TCP */
 841   3            uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
 842   3            uip_len = uip_slen = 0;
 843   3            uip_flags = UIP_POLL;
 844   3            UIP_UDP_APPCALL();
 845   3            goto udp_send;
 846   3          } else {
 847   3            goto drop;
 848   3          }
 849   2        }
 850   1      #endif
 851   1      
 852   1        /* This is where the input processing starts. */
 853   1        UIP_STAT(++uip_stat.ip.recv);
 854   1      
 855   1        /* Start of IP input header processing code. */
 856   1        
 857   1      #if UIP_CONF_IPV6
                /* Check validity of the IP header. */
                if((BUF->vtc & 0xf0) != 0x60)  { /* IP version and header length. */
                  UIP_STAT(++uip_stat.ip.drop);
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 15  

                  UIP_STAT(++uip_stat.ip.vhlerr);
                  UIP_LOG("ipv6: invalid version.");
                  goto drop;
                }
              #else /* UIP_CONF_IPV6 */
 866   1        /* Check validity of the IP header. */
 867   1        if(BUF->vhl != 0x45)  { /* IP version and header length. */
 868   2          UIP_STAT(++uip_stat.ip.drop);
 869   2          UIP_STAT(++uip_stat.ip.vhlerr);
 870   2          UIP_LOG("ip: invalid version or header length.");
 871   2          goto drop;
 872   2        }
 873   1      #endif /* UIP_CONF_IPV6 */
 874   1        
 875   1        /* Check the size of the packet. If the size reported to us in
 876   1           uip_len is smaller the size reported in the IP header, we assume
 877   1           that the packet has been corrupted in transit. If the size of
 878   1           uip_len is larger than the size reported in the IP packet header,
 879   1           the packet has been padded and we set uip_len to the correct
 880   1           value.. */
 881   1      
 882   1        if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
 883   2          uip_len = (BUF->len[0] << 8) + BUF->len[1];
 884   2      #if UIP_CONF_IPV6
                  uip_len += 40; /* The length reported in the IPv6 header is the
                                    length of the payload that follows the
                                    header. However, uIP uses the uip_len variable
                                    for holding the size of the entire packet,
                                    including the IP header. For IPv4 this is not a
                                    problem as the length field in the IPv4 header
                                    contains the length of the entire packet. But
                                    for IPv6 we need to add the size of the IPv6
                                    header (40 bytes). */
              #endif /* UIP_CONF_IPV6 */
 895   2        } else {
 896   2          UIP_LOG("ip: packet shorter than reported in IP header.");
 897   2          goto drop;
 898   2        }
 899   1      
 900   1      #if !UIP_CONF_IPV6
 901   1        /* Check the fragment flag. */
 902   1        if((BUF->ipoffset[0] & 0x3f) != 0 ||
 903   1           BUF->ipoffset[1] != 0) {
 904   2      #if UIP_REASSEMBLY
                  uip_len = uip_reass();
                  if(uip_len == 0) {
                    goto drop;
                  }
              #else /* UIP_REASSEMBLY */
 910   2          UIP_STAT(++uip_stat.ip.drop);
 911   2          UIP_STAT(++uip_stat.ip.fragerr);
 912   2          UIP_LOG("ip: fragment dropped.");
 913   2          goto drop;
 914   2      #endif /* UIP_REASSEMBLY */
 915   2        }
 916   1      #endif /* UIP_CONF_IPV6 */
 917   1      
 918   1        if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) {
 919   2          /* If we are configured to use ping IP address configuration and
 920   2             hasn't been assigned an IP address yet, we accept all ICMP
 921   2             packets. */
 922   2      #if UIP_PINGADDRCONF && !UIP_CONF_IPV6
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 16  

                  if(BUF->proto == UIP_PROTO_ICMP) {
                    UIP_LOG("ip: possible ping config packet received.");
                    goto icmp_input;
                  } else {
                    UIP_LOG("ip: packet dropped since no address assigned.");
                    goto drop;
                  }
              #endif /* UIP_PINGADDRCONF */
 931   2      
 932   2        } else {
 933   2          /* If IP broadcast support is configured, we check for a broadcast
 934   2             UDP packet, which may be destined to us. */
 935   2      #if UIP_BROADCAST
                  DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
                  if(BUF->proto == UIP_PROTO_UDP &&
                     uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr)
                     /*&&
                       uip_ipchksum() == 0xffff*/) {
                    goto udp_input;
                  }
              #endif /* UIP_BROADCAST */
 944   2          
 945   2          /* Check if the packet is destined for our IP address. */
 946   2      #if !UIP_CONF_IPV6
 947   2          if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
 948   3            UIP_STAT(++uip_stat.ip.drop);
 949   3            goto drop;
 950   3          }
 951   2      #else /* UIP_CONF_IPV6 */
                  /* For IPv6, packet reception is a little trickier as we need to
                     make sure that we listen to certain multicast addresses (all
                     hosts multicast address, and the solicited-node multicast
                     address) as well. However, we will cheat here and accept all
                     multicast packets that are sent to the ff02::/16 addresses. */
                  if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) &&
                     BUF->destipaddr[0] != HTONS(0xff02)) {
                    UIP_STAT(++uip_stat.ip.drop);
                    goto drop;
                  }
              #endif /* UIP_CONF_IPV6 */
 963   2        }
 964   1      
 965   1      #if !UIP_CONF_IPV6
 966   1        if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
 967   2                                          checksum. */
 968   2          UIP_STAT(++uip_stat.ip.drop);
 969   2          UIP_STAT(++uip_stat.ip.chkerr);
 970   2          UIP_LOG("ip: bad checksum.");
 971   2          goto drop;
 972   2        }
 973   1      #endif /* UIP_CONF_IPV6 */
 974   1      
 975   1      #if UIP_TCP
 976   1        if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,
 977   2                                             proceed with TCP input
 978   2                                             processing. */
 979   2          goto tcp_input;
 980   2        }
 981   1      #endif /* UIP_TCP */
 982   1      
 983   1      #if UIP_UDP
 984   1        if(BUF->proto == UIP_PROTO_UDP) {
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 17  

 985   2          goto udp_input;
 986   2        }
 987   1      #endif /* UIP_UDP */
 988   1      
 989   1      #if !UIP_CONF_IPV6
 990   1        /* ICMPv4 processing code follows. */
 991   1        if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from
 992   2                                              here. */
 993   2          UIP_STAT(++uip_stat.ip.drop);
 994   2          UIP_STAT(++uip_stat.ip.protoerr);
 995   2          UIP_LOG("ip: neither tcp nor icmp.");
 996   2          goto drop;
 997   2        }
 998   1      
 999   1      #if UIP_PINGADDRCONF
               icmp_input:
              #endif /* UIP_PINGADDRCONF */
1002   1        UIP_STAT(++uip_stat.icmp.recv);
1003   1      
1004   1        /* ICMP echo (i.e., ping) processing. This is simple, we only change
1005   1           the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
1006   1           checksum before we return the packet. */
1007   1        if(ICMPBUF->type != ICMP_ECHO) {
1008   2          UIP_STAT(++uip_stat.icmp.drop);
1009   2          UIP_STAT(++uip_stat.icmp.typeerr);
1010   2          UIP_LOG("icmp: not icmp echo.");
1011   2          goto drop;
1012   2        }
1013   1      
1014   1        /* If we are configured to use ping IP address assignment, we use
1015   1           the destination IP address of this ping packet and assign it to
1016   1           ourself. */
1017   1      #if UIP_PINGADDRCONF
                if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
                  uip_hostaddr[0] = BUF->destipaddr[0];
                  uip_hostaddr[1] = BUF->destipaddr[1];
                }
              #endif /* UIP_PINGADDRCONF */
1023   1      
1024   1        ICMPBUF->type = ICMP_ECHO_REPLY;
1025   1      
1026   1        if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
1027   2          ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
1028   2        } else {
1029   2          ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
1030   2        }
1031   1      
1032   1        /* Swap IP addresses. */
1033   1        uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
1034   1        uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
1035   1      
1036   1        UIP_STAT(++uip_stat.icmp.sent);
1037   1        goto send;
1038   1      
1039   1        /* End of IPv4 input header processing code. */
1040   1      #else /* !UIP_CONF_IPV6 */
              
                /* This is IPv6 ICMPv6 processing code. */
                DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
              
                if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from
                                                       here. */
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 18  

                  UIP_STAT(++uip_stat.ip.drop);
                  UIP_STAT(++uip_stat.ip.protoerr);
                  UIP_LOG("ip: neither tcp nor icmp6.");
                  goto drop;
                }
              
                UIP_STAT(++uip_stat.icmp.recv);
              
                /* If we get a neighbor solicitation for our address we should send
                   a neighbor advertisement message back. */
                if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
                  if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
              
                    if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
                      /* Save the sender's address in our neighbor list. */
                      uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
                    }
                    
                    /* We should now send a neighbor advertisement back to where the
                       neighbor solicication came from. */
                    ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
                    ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
                    
                    ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
                    
                    uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
                    uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr);
                    ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
                    ICMPBUF->options[1] = 1;  /* Options length, 1 = 8 bytes. */
                    memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
                    ICMPBUF->icmpchksum = 0;
                    ICMPBUF->icmpchksum = ~uip_icmp6chksum();
                    goto send;
                    
                  }
                  goto drop;
                } else if(ICMPBUF->type == ICMP6_ECHO) {
                  /* ICMP echo (i.e., ping) processing. This is simple, we only

⌨️ 快捷键说明

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