From d926ce84920e03b150c60d842f8cd4c4cea671f5 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 5 Feb 2024 19:16:37 +0800
Subject: fix wrong namelen in getaddrname

---
 src/api/sockets.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/api/sockets.c b/src/api/sockets.c
index f3b8f8c..250c424 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -3063,7 +3063,8 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
     *namelen = IPADDR_SOCKADDR_GET_LEN(&saddr);
   }
 #else
-  *namelen = LWIP_MIN(*namelen, sizeof(saddr));
+  u8_t sa_len = IP_IS_V4_VAL(naddr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
+  *namelen = LWIP_MIN(*namelen, sa_len);
 #endif
   MEMCPY(name, &saddr, *namelen);
 
-- 
2.33.0

