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

Function lwip_sendto

components/net/lwip/lwip-2.1.2/src/api/sockets.c:1606–1704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1604}
1605
1606ssize_t
1607lwip_sendto(int s, const void *data, size_t size, int flags,
1608 const struct sockaddr *to, socklen_t tolen)
1609{
1610 struct lwip_sock *sock;
1611 err_t err;
1612 u16_t short_size;
1613 u16_t remote_port;
1614 struct netbuf buf;
1615
1616 sock = get_socket(s);
1617 if (!sock) {
1618 return -1;
1619 }
1620
1621 if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) {
1622#if LWIP_TCP
1623 done_socket(sock);
1624 return lwip_send(s, data, size, flags);
1625#else /* LWIP_TCP */
1626 LWIP_UNUSED_ARG(flags);
1627 sock_set_errno(sock, err_to_errno(ERR_ARG));
1628 done_socket(sock);
1629 return -1;
1630#endif /* LWIP_TCP */
1631 }
1632
1633 if (size > LWIP_MIN(0xFFFF, SSIZE_MAX)) {
1634 /* cannot fit into one datagram (at least for us) */
1635 sock_set_errno(sock, EMSGSIZE);
1636 done_socket(sock);
1637 return -1;
1638 }
1639 short_size = (u16_t)size;
1640 LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
1641 (IS_SOCK_ADDR_LEN_VALID(tolen) &&
1642 ((to != NULL) && (IS_SOCK_ADDR_TYPE_VALID(to) && IS_SOCK_ADDR_ALIGNED(to))))),
1643 sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
1644 LWIP_UNUSED_ARG(tolen);
1645
1646 /* initialize a buffer */
1647 buf.p = buf.ptr = NULL;
1648#if LWIP_CHECKSUM_ON_COPY
1649 buf.flags = 0;
1650#endif /* LWIP_CHECKSUM_ON_COPY */
1651 if (to) {
1652 SOCKADDR_TO_IPADDR_PORT(to, &buf.addr, remote_port);
1653 } else {
1654 remote_port = 0;
1655 ip_addr_set_any(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)), &buf.addr);
1656 }
1657 netbuf_fromport(&buf) = remote_port;
1658
1659
1660 LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%"U16_F", flags=0x%x to=",
1661 s, data, short_size, flags));
1662 ip_addr_debug_print_val(SOCKETS_DEBUG, buf.addr);
1663 LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", remote_port));

Callers 7

lwip_sendFunction · 0.70
test_sockets_msgapi_cmsgFunction · 0.50
lwip_ping_sendFunction · 0.50
lwip_ping_sendFunction · 0.50
lwip_sendFunction · 0.50
udp_client_entryFunction · 0.50
udp_server_entryFunction · 0.50

Calls 9

done_socketFunction · 0.85
get_socketFunction · 0.70
netconn_typeEnum · 0.70
lwip_sendFunction · 0.70
err_to_errnoFunction · 0.70
netbuf_allocFunction · 0.70
netbuf_refFunction · 0.70
netconn_sendFunction · 0.70
netbuf_freeFunction · 0.70

Tested by 1

test_sockets_msgapi_cmsgFunction · 0.40