From c68880c0d7445474ec3caba540fa3a9d6789683e Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Tue, 7 Sep 2021 14:59:13 +0800 Subject: [PATCH] getaddrinfo: support AF_RPMSG The hostname is as rp_cpu, the servname is as rp_name Signed-off-by: Jiuzhu Dong --- 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 87068ef39f..7a801eb164 100644 --- a/libs/libc/netdb/lib_getaddrinfo.c +++ b/libs/libc/netdb/lib_getaddrinfo.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -46,6 +47,7 @@ struct ai_s struct sockaddr_un sun; struct sockaddr_in sin; struct sockaddr_in6 sin6; + struct sockaddr_rpmsg srp; } sa; }; @@ -93,6 +95,14 @@ FAR static struct ai_s *alloc_ai(int family, int socktype, int protocol, ai->sa.sin6.sin6_port = port; /* Already network order */ 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 } @@ -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;