LingaoM commented on code in PR #19456:
URL: https://github.com/apache/nuttx/pull/19456#discussion_r3620917562


##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -248,34 +317,67 @@ static int host_usrsock_sockopt(int sockfd, int level, 
int optname,
 int host_usrsock_socket(int domain, int type, int protocol)
 {
   int opt = 1;
+  int sockflags = 0;
   int ret;
 
   if (domain == NUTTX_PF_INET)

Review Comment:
   Done



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -92,26 +94,93 @@ static void host_usrsock_set_fd(int fd, fd_set *fds)
     }
 }
 
-static void sockaddr_to_native(const struct nuttx_sockaddr *addr,
-                               const nuttx_socklen_t addrlen,
-                               struct sockaddr *naddr,
-                               socklen_t *naddrlen)
+static int sockaddr_to_native(const struct nuttx_sockaddr *addr,
+                              const nuttx_socklen_t addrlen,
+                              struct sockaddr_storage *naddr,
+                              socklen_t *naddrlen)
 {
-  naddr->sa_family = addr->sa_family;
-  memcpy(naddr->sa_data, addr->sa_data, sizeof(naddr->sa_data));
+  if (addr == NULL || naddr == NULL || naddrlen == NULL)
+    {
+      return -EINVAL;
+    }
+
+  memset(naddr, 0, sizeof(*naddr));
+
+  if (addr->sa_family == NUTTX_AF_LOCAL)
+    {
+      const struct nuttx_sockaddr_un *un =
+        (const struct nuttx_sockaddr_un *)addr;
+      struct sockaddr_un *native = (struct sockaddr_un *)naddr;
+      size_t pathlen;
 
+      if (addrlen < offsetof(struct nuttx_sockaddr_un, sun_path) + 1)
+        {
+          return -EINVAL;
+        }
+
+      pathlen = strnlen(un->sun_path, sizeof(un->sun_path));
+      if (pathlen >= sizeof(native->sun_path))
+        {
+          return -ENAMETOOLONG;
+        }
+
+      native->sun_family = AF_UNIX;
+      memcpy(native->sun_path, un->sun_path, pathlen + 1);
+      *naddrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;
+
+      return 0;
+    }
+
+  if (addrlen > sizeof(*naddr))
+    {
+      return -ENOSPC;
+    }
+
+  memcpy(naddr, addr, addrlen);
   *naddrlen = addrlen;
+
+  return 0;
 }
 
-static void sockaddr_to_nuttx(const struct sockaddr *naddr,
-                              const socklen_t naddrlen,
-                              struct nuttx_sockaddr *addr,
-                              nuttx_socklen_t *addrlen)
+static int sockaddr_to_nuttx(const struct sockaddr_storage *naddr,
+                             const socklen_t naddrlen,

Review Comment:
   Done



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -92,26 +94,93 @@ static void host_usrsock_set_fd(int fd, fd_set *fds)
     }
 }
 
-static void sockaddr_to_native(const struct nuttx_sockaddr *addr,
-                               const nuttx_socklen_t addrlen,
-                               struct sockaddr *naddr,
-                               socklen_t *naddrlen)
+static int sockaddr_to_native(const struct nuttx_sockaddr *addr,
+                              const nuttx_socklen_t addrlen,

Review Comment:
   Done



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -248,34 +317,67 @@ static int host_usrsock_sockopt(int sockfd, int level, 
int optname,
 int host_usrsock_socket(int domain, int type, int protocol)
 {
   int opt = 1;
+  int sockflags = 0;
   int ret;
 
   if (domain == NUTTX_PF_INET)
     {
       domain = PF_INET;
     }
+#ifdef CONFIG_NET_IPv6
+  else if (domain == NUTTX_PF_INET6)
+    {
+      domain = PF_INET6;
+    }
+#endif
+  else if (domain == NUTTX_PF_LOCAL)
+    {
+      domain = PF_UNIX;
+    }
   else
     {
       return -EINVAL;
     }
 
-  if (type == NUTTX_SOCK_STREAM)
+  if ((type & NUTTX_SOCK_TYPE_MASK) == NUTTX_SOCK_STREAM)

Review Comment:
   Done



-- 
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