anchao commented on code in PR #7616:
URL: https://github.com/apache/nuttx/pull/7616#discussion_r1037778456


##########
net/icmp/icmp_reply.c:
##########
@@ -119,20 +119,75 @@ void icmp_reply(FAR struct net_driver_s *dev, int type, 
int code)
   if (datalen > ICMP_MAXMSGLEN - ipicmplen)
     {
       datalen = ICMP_MAXMSGLEN - ipicmplen;
+      iob_trimtail(dev->d_iob, dev->d_iob->io_pktlen - datalen);
     }
 
-  dev->d_len = ipicmplen + datalen;
+  /* Save the original datagram */
+
+  if (CONFIG_IOB_BUFSIZE >= datalen + ipicmplen +
+                           CONFIG_NET_LL_GUARDSIZE)
+    {
+      /* Reuse current iob */
+
+      memmove((FAR char *)ipv4 + ipicmplen, ipv4, datalen);
+
+      /* Skip icmp header from iob */
+
+      iob_update_pktlen(dev->d_iob, datalen + ipicmplen);
+    }
+  else
+    {
+      FAR struct iob_s *iob;
+
+      /* Save the original datagram to iob chain */
+
+      iob = dev->d_iob;
+      dev->d_iob = NULL;
+
+      /* Re-prepare device buffer */
 
-  /* Copy fields from original packet */
+      if (netdev_iob_prepare(dev, false, 0) != OK)
+        {
+          dev->d_len = 0;
+          dev->d_iob = iob;
+          netdev_iob_release(dev);
+          return;
+        }
 
-  memmove(icmp + 1, ipv4, datalen);
+      /* Copy ipv4 header to device buffer */
+
+      if (iob_trycopyin(dev->d_iob, (FAR void *)ipv4,

Review Comment:
   parameter prototype conflict, cast is needed
   
   int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
                     unsigned int len, unsigned int offset, bool throttled)
   



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to