Commit a05f0f3f authored by Florian Grandel's avatar Florian Grandel Committed by Carles Cufi
Browse files

net: ip: document endianness



To maintain POSIX compatibility, link-layer addresses are encoded in big
endian in the IP stack and socket API.

The intended endianness was however not documented everywhere which led
to bugs and inconsistencies. The IEEE 802.15.4 L2 stack, for example,
sometimes stores addresses in little endian in structures that intend
them to be stored in POSIX-compliant big endian byte order.

This change documents intended endianness within the realm of the
IP and sockets stack. Conversion bugs are fixed in a separate commit.

Signed-off-by: default avatarFlorian Grandel <jerico.dev@gmail.com>
parent 631f117e
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ struct sockaddr_ll {
	uint16_t    sll_hatype;   /* ARP hardware type                  */
	uint8_t     sll_pkttype;  /* Packet type                        */
	uint8_t     sll_halen;    /* Length of address                  */
	uint8_t     sll_addr[8];  /* Physical-layer address  */
	uint8_t     sll_addr[8];  /* Physical-layer address, big endian */
};

struct sockaddr_ll_ptr {
@@ -217,7 +217,7 @@ struct sockaddr_ll_ptr {
	uint16_t    sll_hatype;   /* ARP hardware type                  */
	uint8_t     sll_pkttype;  /* Packet type                        */
	uint8_t     sll_halen;    /* Length of address                  */
	uint8_t     *sll_addr;    /* Physical-layer address  */
	uint8_t     *sll_addr;    /* Physical-layer address, big endian */
};

struct sockaddr_can_ptr {
@@ -233,7 +233,7 @@ struct iovec {
#endif

struct msghdr {
	void         *msg_name;       /* optional socket address */
	void         *msg_name;       /* optional socket address, big endian */
	socklen_t     msg_namelen;    /* size of socket address */
	struct iovec *msg_iov;        /* scatter/gather array */
	size_t        msg_iovlen;     /* number of elements in msg_iov */
+2 −2
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ enum net_link_type {
 */
struct net_linkaddr {
	/** The array of byte representing the address */
	uint8_t *addr;
	uint8_t *addr; /* in big endian */

	/** Length of that address array */
	uint8_t len;
@@ -93,7 +93,7 @@ struct net_linkaddr_storage {
	uint8_t len;

	/** The array of bytes representing the address */
	uint8_t addr[NET_LINK_ADDR_MAX_LENGTH];
	uint8_t addr[NET_LINK_ADDR_MAX_LENGTH]; /* in big endian */
};

/**