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

Function sys_setsockopt

components/lwp/lwp_syscall.c:5458–5484  ·  view source on GitHub ↗

* @brief Sets the value of a socket option. * * This system call sets a socket option for the specified socket. Socket options control various aspects * of socket behavior, such as timeouts, buffer sizes, or connection parameters. The option value is * provided in the `optval` buffer, and its length is specified by the `optlen` parameter. * * @param[in] socket The socket descriptor for w

Source from the content-addressed store, hash-verified

5456 * sized buffer could result in undefined behavior or errors.
5457 */
5458sysret_t sys_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen)
5459{
5460 int ret;
5461 void *koptval = RT_NULL;
5462
5463 if (!lwp_user_accessable((void *)optval, optlen))
5464 return -EFAULT;
5465
5466 koptval = kmem_get(optlen);
5467 if (koptval == RT_NULL)
5468 {
5469 return -ENOMEM;
5470 }
5471
5472 if (lwp_get_from_user(koptval, (void *)optval, optlen) != optlen)
5473 {
5474 kmem_put(koptval);
5475 return -EINVAL;
5476 }
5477
5478 convert_sockopt(&level, &optname);
5479 ret = setsockopt(socket, level, optname, koptval, optlen);
5480
5481 kmem_put(koptval);
5482
5483 return (ret < 0 ? GET_ERRNO() : ret);
5484}
5485
5486/**
5487 * @brief Establishes a connection to a remote socket.

Callers

nothing calls this directly

Calls 6

lwp_user_accessableFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_putFunction · 0.85
convert_sockoptFunction · 0.85
setsockoptFunction · 0.85

Tested by

no test coverage detected