Sarthak-Pandey commented on code in PR #20627:
URL: https://github.com/apache/nuttx/pull/20627#discussion_r4282040730


##########
net/tcp/tcp_input.c:
##########
@@ -1570,38 +1573,57 @@ static void tcp_input(FAR struct net_driver_s *dev, 
uint8_t domain,
 
         if ((tcp->flags & TCP_URG) != 0)
           {
-            dev->d_urglen = (tcp->urgp[0] << 8) | tcp->urgp[1];
-            if (dev->d_urglen > dev->d_len)
+            uint16_t urgp = (tcp->urgp[0] << 8) | tcp->urgp[1];
+
+            /* BSD/Linux default semantics (tcp_stdurg=0):
+             * The urgent pointer points ONE BYTE PAST the urgent byte.
+             * The single urgent byte is at payload[urgp - 1].
+             *
+             * If urgp is within the current segment (1 <= urgp <= d_len):
+             * - Extract the single urgent byte into conn->urg_data from
+             *   the IOB chain.
+             * - Record state as TCP_URG_VALID.
+             * - Signal urgent data availability (flags |= TCP_URGDATA).
+             *
+             * If urgp > d_len:
+             * - The urgent byte is located in a future segment not yet
+             *   received; mark state as TCP_URG_AWAITING.
+             * - Signal urgent data (flags |= TCP_URGDATA).
+             */
+
+            if (urgp >= 1 && urgp <= dev->d_len)
               {
-                /* There is more urgent data in the next segment to come. */
+                int app_offset;
+
+                /* Payload is stored in an IOB chain starting at dev->d_iob.
+                 * Calculate the offset of d_appdata within dev->d_iob.
+                 */
 
-                dev->d_urglen = dev->d_len;
+                app_offset = (dev->d_appdata - dev->d_iob->io_data) -
+                             dev->d_iob->io_offset;
+
+                /* Copy the urgent byte safely from the IOB chain */
+
+                iob_copyout(&conn->urg_data, dev->d_iob, 1,
+                            app_offset + urgp - 1);

Review Comment:
   Thanks for pointing this out. When SO_OOBINLINE is not enabled, the urgent 
byte should not appear in the normal data stream. I have added 
tcp_remove_urgbyte() to strip the urgent byte from the IOB chain payload and 
advanced conn->rcvseq by 1 to acknowledge it. This ensures the application only 
reads the urgent byte via recv(..., MSG_OOB) and does not receive it twice in 
the normal stream. If SO_OOBINLINE is enabled, the urgent byte remains inline 
in the normal stream as expected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to