/* Translate the information from the head of the received TCP segment Nbuf contents and fill it into a TCP_SEG structure. */
TCP_SEG* TcpFormatNetbuf(IN TCP_CB *Tcb, IN OUT NET_BUF *Nbuf)
/* Translate the information from the head of the received TCP segment Nbuf contents and fill it into a TCP_SEG structure. */
TCP_SEG* TcpFormatNetbuf(IN TCP_CB *Tcb, IN OUT NET_BUF *Nbuf)
{
  TCP_SEG   *Seg;
  TCP_HEAD  *Head;
  Seg  = TCPSEG_NETBUF (Nbuf);
  Head = (TCP_HEAD *)NetbufGetByte (Nbuf, 0, NULL);
  ASSERT (Head != NULL);
  Nbuf->Tcp = Head;
  Seg->Seq = NTOHL (Head->Seq);
  Seg->Ack = NTOHL (Head->Ack);
  Seg->End = Seg->Seq + (Nbuf->TotalSize - (Head->HeadLen << 2));
  Seg->Urg  = NTOHS (Head->Urg);
  Seg->Wnd  = (NTOHS (Head->Wnd) << Tcb->SndWndScale);
  Seg->Flag = Head->Flag;
  if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) {
    Seg->Wnd = NTOHS (Head->Wnd);
    Seg->End++;
  }
  if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) {
    Seg->End++;
  }
  return Seg;
}