nrf_modem: nrf_sendto: undocumented and unexpected error code

The `nrf_sendto` function returns -1 and sets errno to 22 (NRF_EINVAL) when attempting to send data that does not fit in the network MTU.

On my local network (Telstra Australia) the IPv4 MTU is 1360. With the 28 byte UDP header, the expected maximum payload that can fit in a single packet is 1332.
Below is code which attempts to send this and one byte more:

		int l = 1360 - (sizeof(struct net_ipv4_hdr) + sizeof(struct net_udp_hdr));

		rc = zsock_send(state.socket, ram, l, 0);
		LOG_INF("Sendto %d bytes: %d %d", l, rc, errno);
		k_sleep(K_SECONDS(1));

		rc = zsock_send(state.socket, ram, l + 1, 0);
		LOG_INF("Sendto %d bytes: %d %d", l + 1, rc, errno);
		k_sleep(K_SECONDS(1));

Logs from that application:

[00:00:07.614,349] <inf> lte_manager: Network registration status: Connected - roaming (Unknown)
[00:00:07.615,173] <inf> lte_manager: 		MCC: 505 MNC: 1
[00:00:07.616,241] <inf> lte_manager: 		MTU: 1360
[00:00:08.259,674] <inf> uc_udp: UDP socket: 0
[00:00:08.260,681] <inf> uc_udp: Sendto 1332 bytes: 1332 0
[00:00:09.261,047] <inf> uc_udp: Sendto 1333 bytes: -1 22

As you can see, too large packets error out and set errno to 22. This is not one of the documented error codes on `nrf_sendto`.
It is also not the error code you would expect from the linked documentation, which would be EMSGSIZE (122).

Parents Reply Children
No Data
Related