Skip to content

Commit 4a6991e

Browse files
committed
Avoid referencing ns_msghdr_t::flags
This field member was wrongly named - it should have been msg_flags. I'm planning to correct it, which is a compatibility break. As this doesn't need to actually set any flags for sendmsg(), use designated initialiser to get it automatically zero-filled, so this code will work with both old and new naming. For recvmsg() the flags are output-only, so no need to set it when making the call.
1 parent a1982c1 commit 4a6991e

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

source/coap_connection_handler.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,16 @@ static internal_socket_t *int_socket_find(uint16_t port, bool is_secure, bool is
302302

303303
static int8_t send_to_real_socket(int8_t socket_id, const ns_address_t *address, const uint8_t source_address[static 16], const void *buffer, uint16_t length)
304304
{
305-
ns_iovec_t msg_iov;
306-
ns_msghdr_t msghdr;
307-
308-
msghdr.msg_name = (void*)address;
309-
msghdr.msg_namelen = sizeof(ns_address_t);
310-
msghdr.msg_iov = &msg_iov;
311-
msghdr.msg_iovlen = 1;
312-
msghdr.flags = 0;
305+
ns_iovec_t msg_iov = {
306+
.iov_base = (void *) buffer,
307+
.iov_len = length
308+
};
309+
ns_msghdr_t msghdr = {
310+
.msg_name = (void *) address,
311+
.msg_namelen = sizeof(ns_address_t),
312+
.msg_iov = &msg_iov,
313+
.msg_iovlen = 1
314+
};
313315

314316
if (memcmp(source_address, ns_in6addr_any, 16)) {
315317
uint8_t ancillary_databuffer[NS_CMSG_SPACE(sizeof(ns_in6_pktinfo_t))];
@@ -328,14 +330,8 @@ static int8_t send_to_real_socket(int8_t socket_id, const ns_address_t *address,
328330
pktinfo = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg);
329331
pktinfo->ipi6_ifindex = 0;
330332
memcpy(pktinfo->ipi6_addr, source_address, 16);
331-
} else {
332-
msghdr.msg_control = NULL;
333-
msghdr.msg_controllen = 0;
334333
}
335334

336-
msg_iov.iov_base = (void *)buffer;
337-
msg_iov.iov_len = length;
338-
339335
return socket_sendmsg(socket_id, &msghdr, 0);
340336
}
341337

@@ -483,7 +479,6 @@ static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_a
483479
msghdr.msg_iovlen = 1;
484480
msghdr.msg_control = ancillary_databuffer;
485481
msghdr.msg_controllen = sizeof(ancillary_databuffer);
486-
msghdr.flags = 0;
487482

488483
msg_iov.iov_base = sock->data;
489484
msg_iov.iov_len = sckt_data->d_len;

0 commit comments

Comments
 (0)