You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/13 00:57:53 UTC

[incubator-nuttx] 02/02: getaddrinfo: support AF_RPMSG

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

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

commit c68880c0d7445474ec3caba540fa3a9d6789683e
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Tue Sep 7 14:59:13 2021 +0800

    getaddrinfo: support AF_RPMSG
    
    The hostname is as rp_cpu, the servname is as rp_name
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 libs/libc/netdb/lib_getaddrinfo.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c
index 87068ef..7a801eb 100644
--- a/libs/libc/netdb/lib_getaddrinfo.c
+++ b/libs/libc/netdb/lib_getaddrinfo.c
@@ -28,6 +28,7 @@
 
 #include <arpa/inet.h>
 #include <nuttx/net/loopback.h>
+#include <netpacket/rpmsg.h>
 #include <netdb.h>
 #include <sys/un.h>
 
@@ -46,6 +47,7 @@ struct ai_s
     struct sockaddr_un sun;
     struct sockaddr_in sin;
     struct sockaddr_in6 sin6;
+    struct sockaddr_rpmsg srp;
   } sa;
 };
 
@@ -94,6 +96,14 @@ FAR static struct ai_s *alloc_ai(int family, int socktype, int protocol,
         memcpy(&ai->sa.sin6.sin6_addr, addr, sizeof(ai->sa.sin6.sin6_addr));
         break;
 #endif
+#ifdef CONFIG_NET_RPMSG
+      case AF_RPMSG:
+        ai->ai.ai_addrlen       = sizeof(struct sockaddr_rpmsg);
+        ai->sa.srp.rp_family    = AF_RPMSG;
+        strncpy(ai->sa.srp.rp_cpu, addr, sizeof(ai->sa.srp.rp_cpu));
+        snprintf(ai->sa.srp.rp_name, sizeof(ai->sa.srp.rp_name), "%d", port);
+        break;
+#endif
     }
 
   return ai;
@@ -145,6 +155,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
       if (family != AF_INET &&
           family != AF_INET6 &&
           family != AF_LOCAL &&
+          family != AF_RPMSG &&
           family != AF_UNSPEC)
         {
           return EAI_FAMILY;
@@ -272,10 +283,10 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
 #endif /* CONFIG_NET_LOOPBACK */
     }
 
-#ifdef CONFIG_NET_LOCAL
-  if (family == AF_LOCAL)
+#if defined(CONFIG_NET_LOCAL) || defined(CONFIG_NET_RPMSG)
+  if (family == AF_LOCAL || family == AF_RPMSG)
     {
-      ai = alloc_ai(AF_LOCAL, socktype, proto, port, hostname);
+      ai = alloc_ai(family, socktype, proto, port, hostname);
       if (ai != NULL)
         {
           *res = (FAR struct addrinfo *)ai;