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

Function sys_getsockopt

components/lwp/lwp_syscall.c:5392–5430  ·  view source on GitHub ↗

* @brief Retrieves the value of a socket option. * * This system call retrieves the current value of a socket option for the specified socket. The socket * options allow fine-grained control over various aspects of socket behavior, such as timeouts, buffering, * and connection settings. The option value is stored in the `optval` buffer, and the size of the buffer * is specified by the `optlen

Source from the content-addressed store, hash-verified

5390 * Failing to provide a correctly sized buffer could result in undefined behavior or buffer overflows.
5391 */
5392sysret_t sys_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlen)
5393{
5394 int ret = 0;
5395 socklen_t koptlen = 0;
5396 void *koptval = RT_NULL;
5397
5398 if (!lwp_user_accessable((void *)optlen, sizeof(uint32_t)))
5399 return -EFAULT;
5400
5401 if (lwp_get_from_user(&koptlen, optlen, sizeof(uint32_t)) != sizeof(uint32_t))
5402 {
5403 return -EINVAL;
5404 }
5405
5406 if (!lwp_user_accessable((void *)optval, koptlen))
5407 return -EFAULT;
5408
5409 koptval = kmem_get(koptlen);
5410 if (koptval == RT_NULL)
5411 {
5412 return -ENOMEM;
5413 }
5414
5415 if (lwp_get_from_user(koptval, optval, koptlen) != koptlen)
5416 {
5417 kmem_put(koptval);
5418 return -EINVAL;
5419 }
5420
5421 convert_sockopt(&level, &optname);
5422 ret = getsockopt(socket, level, optname, koptval, &koptlen);
5423
5424 lwp_put_to_user((void *)optval, koptval, koptlen);
5425 lwp_put_to_user((void *)optlen, &koptlen, sizeof(uint32_t));
5426
5427 kmem_put(koptval);
5428
5429 return (ret < 0 ? GET_ERRNO() : ret);
5430}
5431
5432/**
5433 * @brief Sets the value of a socket option.

Callers

nothing calls this directly

Calls 7

lwp_user_accessableFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_getFunction · 0.85
kmem_putFunction · 0.85
convert_sockoptFunction · 0.85
getsockoptFunction · 0.85
lwp_put_to_userFunction · 0.85

Tested by

no test coverage detected