* @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
| 7049 | * @see freeaddrinfo(), sys_socket(), sys_connect(), sys_gethostbyname(), sys_gethostbyaddr() |
| 7050 | */ |
| 7051 | sysret_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 | { |
nothing calls this directly
no test coverage detected