1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/net/grnc: implement sock_udp_sendv_aux()

This commit is contained in:
Benjamin Valentin 2022-01-07 14:10:51 +01:00 committed by Benjamin Valentin
parent 2a129fc327
commit 4cf94083de

View File

@ -278,19 +278,20 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
return res;
}
ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len,
const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
ssize_t sock_udp_sendv_aux(sock_udp_t *sock,
const iolist_t *snips,
const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
{
(void)aux;
int res;
gnrc_pktsnip_t *payload, *pkt;
gnrc_pktsnip_t *pkt, *payload = NULL;
uint16_t src_port = 0, dst_port;
sock_ip_ep_t local;
sock_udp_ep_t remote_cpy;
sock_ip_ep_t *rem;
uint8_t *payload_buf;
assert((sock != NULL) || (remote != NULL));
assert((len == 0) || (data != NULL)); /* (len != 0) => (data != NULL) */
if (remote != NULL) {
if (remote->port == 0) {
@ -362,11 +363,21 @@ ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len,
else if (local.family != rem->family) {
return -EINVAL;
}
/* generate payload and header snips */
payload = gnrc_pktbuf_add(NULL, (void *)data, len, GNRC_NETTYPE_UNDEF);
/* allocate snip for payload */
payload = gnrc_pktbuf_add(NULL, NULL, iolist_size(snips), GNRC_NETTYPE_UNDEF);
if (payload == NULL) {
return -ENOMEM;
}
/* copy payload data into payload snip */
payload_buf = payload->data;
while (snips) {
memcpy(payload_buf, snips->iol_base, snips->iol_len);
payload_buf += snips->iol_len;
snips = snips->iol_next;
}
pkt = gnrc_udp_hdr_build(payload, src_port, dst_port);
if (pkt == NULL) {
gnrc_pktbuf_release(payload);