You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/06 13:09:37 UTC

[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4071: net/local: add AF_[UNIX|LOCAL] socketpair support

anchao commented on a change in pull request #4071:
URL: https://github.com/apache/incubator-nuttx/pull/4071#discussion_r664539949



##########
File path: net/inet/inet_sockif.c
##########
@@ -1328,6 +1342,147 @@ static int inet_ioctl(FAR struct socket *psock, int cmd,
   return -EINVAL;
 }
 
+/****************************************************************************
+ * Name: inet_socketpair
+ *
+ * Description:
+ *   Create a pair of connected sockets between psocks[2]
+ *
+ * Parameters:
+ *   psocks   A reference to the socket structure of the socket pair
+ *
+ ****************************************************************************/
+
+static int inet_socketpair(FAR struct socket *psocks[2])
+{
+#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
+  FAR struct socket *pserver = NULL;
+  union sockaddr_u addr[2];
+  socklen_t len;
+  int ret;
+
+  /* Set the sock address to localhost */
+
+#ifdef CONFIG_NET_IPv6
+  if (psocks[0]->s_domain == AF_INET6)
+    {
+      struct in6_addr init_sin6_addr = IN6ADDR_LOOPBACK_INIT;
+
+      len = sizeof(addr[0].in6addr);
+      memset(&addr[0], 0, len);
+      addr[0].in6addr.sin6_family = psocks[0]->s_domain;
+      addr[0].in6addr.sin6_addr = init_sin6_addr;
+    }
+  else
+#endif
+    {
+      len = sizeof(addr[0].inaddr);
+      memset(&addr[0], 0, len);
+      addr[0].inaddr.sin_family = psocks[0]->s_domain;
+      addr[0].inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+    }
+
+  memcpy(&addr[1], &addr[0], len);
+
+  ret = psock_bind(psocks[0], &addr[0].addr, len);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  psock_getsockname(psocks[0], &addr[0].addr, &len);
+
+  /* For SOCK_STREAM, Use proxy service handle to make temporary
+   * pserver process, psocks[1] will be replaced with a new accept handle
+   */
+
+#if defined(CONFIG_NET_TCP)
+  FAR struct socket server;
+
+  if (psocks[0]->s_type == SOCK_STREAM)
+    {
+      ret = psock_socket(psocks[1]->s_domain, psocks[1]->s_type,
+                         psocks[1]->s_proto, &server);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      pserver = &server;
+    }
+#endif /* CONFIG_NET_TCP */
+
+#if defined(CONFIG_NET_UDP)

Review comment:
       TCP / UDP is a completely independent scope. which can be enabled separately, so it is impossible to add else to above scope




-- 
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-unsubscribe@nuttx.apache.org

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