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

📄 uip.lst

📁 c8051f020_uip1.0.rar
💻 LST
📖 第 1 页 / 共 5 页
字号:
 265   2          ++uip_acc32[1];
 266   2          if(uip_acc32[1] == 0) {
 267   3            ++uip_acc32[0];
 268   3          }
 269   2        }
 270   1        
 271   1        
 272   1        if(uip_acc32[3] < (op16 & 0xff)) {
 273   2          ++uip_acc32[2];
 274   2          if(uip_acc32[2] == 0) {
 275   3            ++uip_acc32[1];
 276   3            if(uip_acc32[1] == 0) {
 277   4              ++uip_acc32[0];
 278   4            }
 279   3          }
 280   2        }
 281   1      }
 282          
 283          #endif /* ! UIP_ARCH_ADD32 && UIP_TCP */
 284          
 285          #if ! UIP_ARCH_CHKSUM
 286          /*---------------------------------------------------------------------------*/
 287          static u16_t
 288          chksum(u16_t sum, const u8_t *sdata, u16_t len)
 289          {
 290   1        u16_t t;
 291   1        const u8_t *dataptr;
 292   1        const u8_t *last_byte;
 293   1      
 294   1        dataptr = sdata;
 295   1        last_byte = sdata + len - 1;
 296   1        
 297   1        while(dataptr < last_byte) {  /* At least two more bytes */
 298   2          t = (dataptr[0] << 8) + dataptr[1];
 299   2          sum += t;
 300   2          if(sum < t) {
 301   3            sum++;            /* carry */
 302   3          }
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 6   

 303   2          dataptr += 2;
 304   2        }
 305   1        
 306   1        if(dataptr == last_byte) {
 307   2          t = (dataptr[0] << 8) + 0;
 308   2          sum += t;
 309   2          if(sum < t) {
 310   3            sum++;            /* carry */
 311   3          }
 312   2        }
 313   1      
 314   1        /* Return sum in host byte order. */
 315   1        return sum;
 316   1      }
 317          /*---------------------------------------------------------------------------*/
 318          u16_t
 319          uip_chksum(u16_t *sdata, u16_t len)
 320          {
 321   1        return htons(chksum(0, (u8_t *)sdata, len));
 322   1      }
 323          /*---------------------------------------------------------------------------*/
 324          #ifndef UIP_ARCH_IPCHKSUM
 325          u16_t
 326          uip_ipchksum(void)
 327          {
 328   1        u16_t sum;
 329   1      
 330   1        sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
 331   1        DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
 332   1        return (sum == 0) ? 0xffff : htons(sum);
 333   1      }
 334          #endif
 335          /*---------------------------------------------------------------------------*/
 336          #if UIP_CONF_IPV6 || UIP_TCP || UIP_UDP_CHECKSUMS
 337          static u16_t
 338          upper_layer_chksum(u8_t proto)
 339          {
 340   1        u16_t upper_layer_len;
 341   1        u16_t sum;
 342   1        
 343   1      #if UIP_CONF_IPV6
                upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
              #else /* UIP_CONF_IPV6 */
 346   1        upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
 347   1      #endif /* UIP_CONF_IPV6 */
 348   1        
 349   1        /* First sum pseudoheader. */
 350   1        
 351   1        /* IP protocol and length fields. This addition cannot carry. */
 352   1        sum = upper_layer_len + proto;
 353   1        /* Sum IP source and destination addresses. */
 354   1        sum = chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));
 355   1      
 356   1        /* Sum TCP header and data. */
 357   1        sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
 358   1                     upper_layer_len);
 359   1          
 360   1        return (sum == 0) ? 0xffff : htons(sum);
 361   1      }
 362          #endif /* UIP_CONF_IPV6 || UIP_TCP || UIP_UDP_CHECKSUMS */
 363          /*---------------------------------------------------------------------------*/
 364          #if UIP_CONF_IPV6
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 7   

              u16_t
              uip_icmp6chksum(void)
              {
                return upper_layer_chksum(UIP_PROTO_ICMP6);
                
              }
              #endif /* UIP_CONF_IPV6 */
 372          /*---------------------------------------------------------------------------*/
 373          #if UIP_TCP
 374          u16_t
 375          uip_tcpchksum(void)
 376          {
 377   1        return upper_layer_chksum(UIP_PROTO_TCP);
 378   1      }
 379          #endif /* UIP_TCP */
 380          /*---------------------------------------------------------------------------*/
 381          #if UIP_UDP_CHECKSUMS
              u16_t
              uip_udpchksum(void)
              {
                return upper_layer_chksum(UIP_PROTO_UDP);
              }
              #endif /* UIP_UDP_CHECKSUMS */
 388          #endif /* UIP_ARCH_CHKSUM */
 389          /*---------------------------------------------------------------------------*/
 390          void
 391          uip_init(void)
 392          {
 393   1      #if UIP_TCP
 394   1        for(c = 0; c < UIP_LISTENPORTS; ++c) {
 395   2          uip_listenports[c] = 0;
 396   2        }
 397   1        for(c = 0; c < UIP_CONNS; ++c) {
 398   2          uip_conns[c].tcpstateflags = UIP_CLOSED;
 399   2        }
 400   1      #endif /* UIP_TCP */
 401   1      #if UIP_ACTIVE_OPEN
 402   1        lastport = 1024;
 403   1      #endif /* UIP_ACTIVE_OPEN */
 404   1      
 405   1      #if UIP_UDP
 406   1        for(c = 0; c < UIP_UDP_CONNS; ++c) {
 407   2          uip_udp_conns[c].lport = 0;
 408   2        }
 409   1      #endif /* UIP_UDP */
 410   1        
 411   1      
 412   1        /* IPv4 initialization. */
 413   1      #if UIP_FIXEDADDR == 0
 414   1        /*  uip_hostaddr[0] = uip_hostaddr[1] = 0;*/
 415   1      #endif /* UIP_FIXEDADDR */
 416   1      
 417   1      }
 418          /*---------------------------------------------------------------------------*/
 419          #if UIP_ACTIVE_OPEN && UIP_TCP
 420          struct uip_conn *
 421          uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
 422          {
 423   1        register struct uip_conn *conn, *cconn;
 424   1        
 425   1        /* Find an unused local port. */
 426   1       again:
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 8   

 427   1        ++lastport;
 428   1      
 429   1        if(lastport >= 32000) {
 430   2          lastport = 4096;
 431   2        }
 432   1      
 433   1        /* Check if this port is already in use, and if so try to find
 434   1           another one. */
 435   1        for(c = 0; c < UIP_CONNS; ++c) {
 436   2          conn = &uip_conns[c];
 437   2          if(conn->tcpstateflags != UIP_CLOSED &&
 438   2             conn->lport == htons(lastport)) {
 439   3            goto again;
 440   3          }
 441   2        }
 442   1      
 443   1        conn = 0;
 444   1        for(c = 0; c < UIP_CONNS; ++c) {
 445   2          cconn = &uip_conns[c];
 446   2          if(cconn->tcpstateflags == UIP_CLOSED) {
 447   3            conn = cconn;
 448   3            break;
 449   3          }
 450   2          if(cconn->tcpstateflags == UIP_TIME_WAIT) {
 451   3            if(conn == 0 ||
 452   3               cconn->timer > conn->timer) {
 453   4              conn = cconn;
 454   4            }
 455   3          }
 456   2        }
 457   1      
 458   1        if(conn == 0) {
 459   2          return 0;
 460   2        }
 461   1        
 462   1        conn->tcpstateflags = UIP_SYN_SENT;
 463   1      
 464   1        conn->snd_nxt[0] = iss[0];
 465   1        conn->snd_nxt[1] = iss[1];
 466   1        conn->snd_nxt[2] = iss[2];
 467   1        conn->snd_nxt[3] = iss[3];
 468   1      
 469   1        conn->initialmss = conn->mss = UIP_TCP_MSS;
 470   1        
 471   1        conn->len = 1;   /* TCP length of the SYN is one. */
 472   1        conn->nrtx = 0;
 473   1        conn->timer = 1; /* Send the SYN next time around. */
 474   1        conn->rto = UIP_RTO;
 475   1        conn->sa = 0;
 476   1        conn->sv = 16;   /* Initial value of the RTT variance. */
 477   1        conn->lport = htons(lastport);
 478   1        conn->rport = rport;
 479   1        uip_ipaddr_copy(&conn->ripaddr, ripaddr);
 480   1        
 481   1        return conn;
 482   1      }
 483          #endif /* UIP_ACTIVE_OPEN && UIP_TCP */
 484          /*---------------------------------------------------------------------------*/
 485          #if UIP_UDP
 486          struct uip_udp_conn *
 487          uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)
 488          {
C51 COMPILER V9.00   UIP                                                                   02/08/2010 20:58:31 PAGE 9   

 489   1        register struct uip_udp_conn *conn;
 490   1        
 491   1        /* Find an unused local port. */
 492   1       again:
 493   1        ++lastport;
 494   1      
 495   1        if(lastport >= 32000) {
 496   2          lastport = 4096;
 497   2        }
 498   1        
 499   1        for(c = 0; c < UIP_UDP_CONNS; ++c) {
 500   2          if(uip_udp_conns[c].lport == htons(lastport)) {
 501   3            goto again;
 502   3          }
 503   2        }
 504   1      
 505   1      
 506   1        conn = 0;
 507   1        for(c = 0; c < UIP_UDP_CONNS; ++c) {
 508   2          if(uip_udp_conns[c].lport == 0) {
 509   3            conn = &uip_udp_conns[c];
 510   3            break;
 511   3          }
 512   2        }
 513   1      
 514   1        if(conn == 0) {
 515   2          return 0;
 516   2        }
 517   1        
 518   1        conn->lport = HTONS(lastport);
 519   1        conn->rport = rport;
 520   1        if(ripaddr == NULL) {
 521   2          memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t));
 522   2        } else {
 523   2          uip_ipaddr_copy(&conn->ripaddr, ripaddr);
 524   2        }
 525   1        conn->ttl = UIP_TTL;
 526   1        
 527   1        return conn;
 528   1      }
 529          #endif /* UIP_UDP */
 530          /*---------------------------------------------------------------------------*/
 531          #if UIP_TCP
 532          void
 533          uip_unlisten(u16_t port)
 534          {
 535   1        for(c = 0; c < UIP_LISTENPORTS; ++c) {
 536   2          if(uip_listenports[c] == port) {
 537   3            uip_listenports[c] = 0;
 538   3            return;

⌨️ 快捷键说明

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