error_t tcpCheckSeqNum(Socket *socket, TcpHeader *segment, size_t length)
{
   //Acceptability test for an incoming segment
   bool_t acceptable = FALSE;

   //Case where both segment length and receive window are zero
   if(!length && !socket->rcvWnd)
   {
      //Make sure that SEG.SEQ = RCV.NXT
      if(segment->seqNum == socket->rcvNxt)
      {
         acceptable = TRUE;
      }
   }
   //Case where segment length is zero and receive window is non zero
   else if(!length && socket->rcvWnd)
   {
      //Make sure that RCV.NXT <= SEG.SEQ < RCV.NXT+RCV.WND
      if(TCP_CMP_SEQ(segment->seqNum, socket->rcvNxt) >= 0 &&
         TCP_CMP_SEQ(segment->seqNum, socket->rcvNxt + socket->rcvWnd) < 0)
      {
         acceptable = TRUE;
      }
   }
   //Case where both segment length and receive window are non zero
   else if(length && socket->rcvWnd)
   {
      //Check whether RCV.NXT <= SEG.SEQ < RCV.NXT+RCV.WND
      if(TCP_CMP_SEQ(segment->seqNum, socket->rcvNxt) >= 0 &&
         TCP_CMP_SEQ(segment->seqNum, socket->rcvNxt + socket->rcvWnd) < 0)
      {
         acceptable = TRUE;
      }
      //or RCV.NXT <= SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND
      else if(TCP_CMP_SEQ(segment->seqNum + length - 1, socket->rcvNxt) >= 0 &&
         TCP_CMP_SEQ(segment->seqNum + length - 1, socket->rcvNxt + socket->rcvWnd) < 0)
      {
         acceptable = TRUE;
      }
   }

   //Non acceptable sequence number?
   if(!acceptable)
   {
      //Debug message
      TRACE_WARNING("Sequence number is not acceptable!\r\n");

      //If an incoming segment is not acceptable, an acknowledgment
      //should be sent in reply (unless the RST bit is set)
      if(!(segment->flags & TCP_FLAG_RST))
         tcpSendSegment(socket, TCP_FLAG_ACK, socket->sndNxt, socket->rcvNxt, 0, FALSE);

      //Return status code
      return ERROR_FAILURE;
   }

   //Sequence number is acceptable
   return NO_ERROR;
}
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.