MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_getaddrinfo

Function sys_getaddrinfo

components/lwp/lwp_syscall.c:7051–7215  ·  view source on GitHub ↗

* @brief Resolves network addresses and service names into a list of address structures. * * This function provides a mechanism for resolving a host name and service name (or port number) * into a list of address structures suitable for use with socket-based communication. The function * can handle both IPv4 and IPv6 addresses and provides a flexible way to specify different types * of addres

Source from the content-addressed store, hash-verified

7049 * @see freeaddrinfo(), sys_socket(), sys_connect(), sys_gethostbyname(), sys_gethostbyaddr()
7050 */
7051sysret_t sys_getaddrinfo(const char *nodename,
7052 const char *servname,
7053 const struct musl_addrinfo *hints,
7054 struct musl_addrinfo *res)
7055{
7056 int ret = -1;
7057 struct addrinfo *k_res = NULL;
7058 char *k_nodename = NULL;
7059 char *k_servname = NULL;
7060 struct addrinfo *k_hints = NULL;
7061#ifdef ARCH_MM_MMU
7062 int len = 0;
7063#endif
7064
7065#ifdef ARCH_MM_MMU
7066 if (!lwp_user_accessable((void *)res, sizeof(*res)))
7067 {
7068 SET_ERRNO(EFAULT);
7069 goto exit;
7070 }
7071#endif
7072 if (nodename)
7073 {
7074#ifdef ARCH_MM_MMU
7075 len = lwp_user_strlen(nodename);
7076 if (len <= 0)
7077 {
7078 SET_ERRNO(EFAULT);
7079 goto exit;
7080 }
7081
7082 k_nodename = (char *)kmem_get(len + 1);
7083 if (!k_nodename)
7084 {
7085 SET_ERRNO(ENOMEM);
7086 goto exit;
7087 }
7088
7089 if (lwp_get_from_user(k_nodename, (void *)nodename, len + 1) != len + 1)
7090 {
7091 SET_ERRNO(EFAULT);
7092 goto exit;
7093 }
7094#else
7095 k_nodename = rt_strdup(nodename);
7096 if (!k_nodename)
7097 {
7098 SET_ERRNO(ENOMEM);
7099 goto exit;
7100 }
7101#endif
7102 }
7103 if (servname)
7104 {
7105#ifdef ARCH_MM_MMU
7106 len = lwp_user_strlen(servname);
7107 if (len <= 0)
7108 {

Callers

nothing calls this directly

Calls 12

lwp_user_accessableFunction · 0.85
lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
rt_strdupFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
sal_getaddrinfoFunction · 0.85
sockaddr_tomuslFunction · 0.85
sal_freeaddrinfoFunction · 0.85
kmem_putFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected