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

Function sys_gethostbyname2_r

components/lwp/lwp_syscall.c:7249–7405  ·  view source on GitHub ↗

* @brief Resolves a host name to an address, with support for specifying the address family. * * This function performs a lookup of the specified host name, and resolves it to an address, * while allowing the caller to specify the desired address family (e.g., IPv4 or IPv6). It is * a reentrant version of `gethostbyname2`, meaning it is safe for use in multi-threaded applications. * The resul

Source from the content-addressed store, hash-verified

7247 * @see gethostbyname2(), sys_gethostbyname(), sys_socket(), sys_connect(), sys_getaddrinfo()
7248 */
7249sysret_t sys_gethostbyname2_r(const char *name, int af, struct hostent *ret,
7250 char *buf, size_t buflen,
7251 struct hostent **result, int *err)
7252{
7253 int ret_val = -1;
7254 int sal_ret = -1 , sal_err = -1;
7255 struct hostent sal_he, sal_tmp;
7256 struct hostent *sal_result = NULL;
7257 char *sal_buf = NULL;
7258 char *k_name = NULL;
7259 int len = 0;
7260
7261#ifdef ARCH_MM_MMU
7262 if (!lwp_user_accessable((void *)err, sizeof(*err)))
7263 {
7264 SET_ERRNO(EFAULT);
7265 goto __exit;
7266 }
7267
7268 if (!lwp_user_accessable((void *)result, sizeof(*result))
7269 || !lwp_user_accessable((void *)ret, sizeof(*ret))
7270 || !lwp_user_accessable((void *)buf, buflen))
7271 {
7272 /* not all arguments given */
7273 *err = EFAULT;
7274 SET_ERRNO(EFAULT);
7275 goto __exit;
7276 }
7277
7278 len = lwp_user_strlen(name);
7279 if (len <= 0)
7280 {
7281 *err = EFAULT;
7282 SET_ERRNO(EFAULT);
7283 goto __exit;
7284 }
7285
7286 k_name = (char *)kmem_get(len + 1);
7287 if (!k_name)
7288 {
7289 SET_ERRNO(ENOMEM);
7290 goto __exit;
7291 }
7292
7293 if (lwp_get_from_user(k_name, (void *)name, len + 1) < 0)
7294 {
7295 SET_ERRNO(EFAULT);
7296 goto __exit;
7297 }
7298#else
7299 k_name = rt_strdup(name);
7300 if (k_name == NULL)
7301 {
7302 SET_ERRNO(ENOMEM);
7303 goto __exit;
7304 }
7305#endif
7306

Callers

nothing calls this directly

Calls 13

lwp_user_accessableFunction · 0.85
lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
rt_strdupFunction · 0.85
sal_gethostbyname_rFunction · 0.85
lwp_put_to_userFunction · 0.85
lwp_memcpyFunction · 0.85
rt_strlenFunction · 0.85
rt_strncpyFunction · 0.85
kmem_putFunction · 0.85
mallocFunction · 0.50

Tested by

no test coverage detected