Translate the information from the head of the received TCP segment Nbuf contents and fill it into a TCP_SEG structure. @param[in] Tcb Pointer to the TCP_CB of this TCP instance. @param[in, out] Nbuf Pointer to the buffer contains the TCP segment. @return Pointer to the TCP_SEG that contains the translated TCP head information. **/
| 681 | |
| 682 | **/ |
| 683 | TCP_SEG * |
| 684 | TcpFormatNetbuf ( |
| 685 | IN TCP_CB *Tcb, |
| 686 | IN OUT NET_BUF *Nbuf |
| 687 | ) |
| 688 | { |
| 689 | TCP_SEG *Seg; |
| 690 | TCP_HEAD *Head; |
| 691 | |
| 692 | Seg = TCPSEG_NETBUF (Nbuf); |
| 693 | Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); |
| 694 | ASSERT (Head != NULL); |
| 695 | |
| 696 | Nbuf->Tcp = Head; |
| 697 | |
| 698 | Seg->Seq = NTOHL (Head->Seq); |
| 699 | Seg->Ack = NTOHL (Head->Ack); |
| 700 | Seg->End = Seg->Seq + (Nbuf->TotalSize - (Head->HeadLen << 2)); |
| 701 | |
| 702 | Seg->Urg = NTOHS (Head->Urg); |
| 703 | Seg->Wnd = (NTOHS (Head->Wnd) << Tcb->SndWndScale); |
| 704 | Seg->Flag = Head->Flag; |
| 705 | |
| 706 | // |
| 707 | // SYN and FIN flag occupy one sequence space each. |
| 708 | // |
| 709 | if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { |
| 710 | // |
| 711 | // RFC requires that the initial window not be scaled. |
| 712 | // |
| 713 | Seg->Wnd = NTOHS (Head->Wnd); |
| 714 | Seg->End++; |
| 715 | } |
| 716 | |
| 717 | if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { |
| 718 | Seg->End++; |
| 719 | } |
| 720 | |
| 721 | return Seg; |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | Initialize an active connection. |