这是Internet RFC包图中的预期位(非字节)顺序

时间:2016-10-11 02:23:12

标签: networking binary packet packet-capture rfc

我正在家庭有线网络上解析ICMPv6数据报,并且无法在特定RFC中找到明确提及的位排序约定。

多字节字段是网络顺序,但是字节内的位是什么?

计算机是字节可寻址的,但网络硬件序列化位。在图表中,8位字段的“左”位会在无符号字节的哪一位(最重要或最不重要)中结束?这是每个RFC,还是所有互联网RFC都无处不在?

示例读取多字节字段(Prf字段)

假设我将数据包数据存储在名为data的变量中:

data, remote_peer = sock.recvfrom(1024) #pseudocode

我发现包含标志的特定字节(不是位):

flag_byte = data[some_offset] #pseudocode

尝试解析此消息RFC4161 section 2.3,指定路由信息选项具有名为Prf的2位标志。

   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.

根据这个例子来说明我的问题,(flag_byte & 0x18) >> 3会得到两位。 b & 0x10会成为标志位吗?我也有兴趣找出指明这应该是它的标准。

1 个答案:

答案 0 :(得分:3)

正如之前的评论中指出的那样(感谢ron-maupin),RFC1700告诉一个消息(包括互联网协议)在左边用最高位描述。

#t

RFC1700被RFC3232取代,iana.org/protocols将最新的协议定义放在RouterAdvertisementFlags上。他们似乎保留了这种符号(例如{{3}})。

我假设这个重要约定也适用于n比特位字段(1 Whenever an octet represents a numeric quantity the left most bit in the diagram is the high order or most significant bit. That is, the bit labeled 0 is the most significant bit. For example, the following diagram represents the value 170 (decimal). 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |1 0 1 0 1 0 1 0| +-+-+-+-+-+-+-+-+ Significance of Bits Similarly, whenever a multi-octet field represents a numeric quantity the left most bit of the whole field is the most significant bit. )将是标志位。

应该由硬件对物理介质上的位进行反序列化,并将它们放在字节可寻址计算机上的一个字节内的正确位置。不同的物理层(物理以太网,wifi,同轴电缆,infiniband,光纤通道)可能会在" wire"上以不同顺序序列化位,但无论如何,数据包级别的各个字节位置都是相同的。