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

Function sys_connect

components/lwp/lwp_syscall.c:5508–5540  ·  view source on GitHub ↗

* @brief Establishes a connection to a remote socket. * * This system call attempts to establish a connection to a remote socket specified by the `name` parameter. * It is typically used for client-side socket operations to connect to a server. The connection is established * by using the specified socket descriptor and the address of the remote server. * * @param[in] socket The socket de

Source from the content-addressed store, hash-verified

5506 * The `name` parameter must point to a valid `sockaddr` structure that contains a correctly formatted address.
5507 */
5508sysret_t sys_connect(int socket, const struct musl_sockaddr *name, socklen_t namelen)
5509{
5510 int ret = 0;
5511 rt_uint16_t family = 0;
5512 struct sockaddr sa;
5513 struct musl_sockaddr kname;
5514 struct sockaddr_un addr_un;
5515
5516 if (!lwp_user_accessable((void *)name, namelen))
5517 {
5518 return -EFAULT;
5519 }
5520
5521 lwp_get_from_user(&family, (void *)name, 2);
5522 if (family == AF_UNIX)
5523 {
5524 if (!lwp_user_accessable((void *)name, sizeof(struct sockaddr_un)))
5525 {
5526 return -EFAULT;
5527 }
5528
5529 lwp_get_from_user(&addr_un, (void *)name, sizeof(struct sockaddr_un));
5530 ret = connect(socket, (struct sockaddr *)(&addr_un), namelen);
5531 }
5532 else
5533 {
5534 lwp_get_from_user(&kname, (void *)name, namelen);
5535 sockaddr_tolwip(&kname, &sa);
5536 ret = connect(socket, &sa, namelen);
5537 }
5538
5539 return ret;
5540}
5541
5542/**
5543 * @brief Prepares a socket to accept incoming connection requests.

Callers

nothing calls this directly

Calls 4

lwp_user_accessableFunction · 0.85
lwp_get_from_userFunction · 0.85
connectFunction · 0.85
sockaddr_tolwipFunction · 0.85

Tested by

no test coverage detected