Zephyr port: explicitly convert port# between host<->network byte order
This change adds byte order conversions on receive and send.
It was previously assumed that the network stack does this
conversion on both sides, but it was determined that it wasn't
the case.
@@ -96,7 +96,7 @@ oc_network_receive(struct net_context *context, struct net_buf *buf, int status,
message->endpoint.flags = IPV6;
memcpy(message->endpoint.addr.ipv6.address, &NET_IPV6_BUF(buf)->src, 16);
message->endpoint.addr.ipv6.scope = 0;
- message->endpoint.addr.ipv6.port = NET_UDP_BUF(buf)->src_port;
+ message->endpoint.addr.ipv6.port = ntohs(NET_UDP_BUF(buf)->src_port);
PRINT("oc_network_receive: received %d bytes\n", message->length);
PRINT("oc_network_receive: incoming message: ");
@@ -130,7 +130,7 @@ oc_send_buffer(oc_message_t *message)
memcpy(peer_addr.sin6_addr.in6_u.u6_addr8,
message->endpoint.addr.ipv6.address, 16);
peer_addr.sin6_family = AF_INET6;
- peer_addr.sin6_port = message->endpoint.addr.ipv6.port;
+ peer_addr.sin6_port = htons(message->endpoint.addr.ipv6.port);
/* Network buffer to hold data to be sent */
struct net_buf *send_buf;
