I am parsing ICMPv6 datagrams on my home wired network, and can't find an explicit mention of the bit-ordering convention in the specific RFC.
Multi-byte fields are network order, but what about bits within a byte?
Machines are byte-addressible, but network hardware serializes bits. On diagrams, a bit to the "left" of a 8-bit field ends up in which bit of an unsigned byte (most significant, or least)? Is this per-RFC, or is it everywhere the same for all internet RFCs?
Example Reading a multi-byte field (Prf field)
Assume I have the packet data stored in a variable called data
:
data, remote_peer = sock.recvfrom(1024) #pseudocode
And that I find the particular byte (not bit) of interest containing the flags:
flag_byte = data[some_offset] #pseudocode
Trying to parse this message, RFC4161 section 2.3, specifies that the the Route information option has a 2-bit flag called Prf
.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length | Prefix Length |Resvd|Prf|Resvd|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Route Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Prefix (Variable Length) |
. .
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
...
Prf (Route Preference)
2-bit signed integer. The Route Preference indicates
whether to prefer the router associated with this prefix
over others, when multiple identical prefixes (for
different routers) have been received. If the Reserved
(10) value is received, the Route Information Option MUST
be ignored.
To phrase my question in terms of this example, (flag_byte & 0x18) >> 3
will get me the two bits. Will b & 0x10
be the sign bit? I'm also interested in figuring out the standard that specifies that this is the way it should be.