This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 94baea911c515091bde0b1d4093106ce5566902c
Author: wangchen <[email protected]>
AuthorDate: Wed Aug 6 19:51:23 2025 +0800

    pkt: support raw pkt in tun driver
    
    Fix code logic errors
    
    Signed-off-by: wangchen <[email protected]>
---
 net/pkt/pkt_conn.c             | 14 ++++++++++++++
 net/pkt/pkt_sendmsg_buffered.c |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c
index ab44c012668..a6b24bd04fa 100644
--- a/net/pkt/pkt_conn.c
+++ b/net/pkt/pkt_conn.c
@@ -191,9 +191,23 @@ FAR struct pkt_conn_s *pkt_active(FAR struct net_driver_s 
*dev,
   if (dev->d_lltype == NET_LL_ETHERNET || dev->d_lltype == NET_LL_IEEE80211)
     {
       FAR struct eth_hdr_s *ethhdr = NETLLBUF;
+
       ethertype = ethhdr->type;
     }
 
+#ifdef CONFIG_NET_IPv4
+  else if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION)
+    {
+      ethertype = HTONS(ETH_P_IP);
+    }
+#endif
+#ifdef CONFIG_NET_IPv6
+  else if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION)
+    {
+      ethertype = HTONS(ETH_P_IPV6);
+    }
+#endif
+
   while ((conn = pkt_nextconn(conn)) != NULL)
     {
       if (dev->d_ifindex != conn->ifindex)
diff --git a/net/pkt/pkt_sendmsg_buffered.c b/net/pkt/pkt_sendmsg_buffered.c
index 6a03310a9b2..5392d72e167 100644
--- a/net/pkt/pkt_sendmsg_buffered.c
+++ b/net/pkt/pkt_sendmsg_buffered.c
@@ -328,7 +328,9 @@ ssize_t pkt_sendmsg(FAR struct socket *psock, FAR const 
struct msghdr *msg,
       goto errout_with_iob;
     }
 
-  if (psock->s_type == SOCK_DGRAM)
+  if (psock->s_type == SOCK_DGRAM &&
+      (dev->d_lltype == NET_LL_ETHERNET ||
+       dev->d_lltype == NET_LL_IEEE80211))
     {
       FAR struct eth_hdr_s *ethhdr =
           (FAR struct eth_hdr_s *)(IOB_DATA(iob) - NET_LL_HDRLEN(dev));

Reply via email to