【发布时间】:2012-12-10 19:37:54
【问题描述】:
我有两个与我的实施有关的问题 -
我需要一个函数,它可以将给定的链路层地址从文本转换为标准格式,就像我们在 n/w 层有一个类似的函数,用于 IP 地址
inet_pton(),它将给定的 IP 地址从文本转换为标准 IPv4/IPv6 格式。-
b/w 链路层地址和 48 位 mac 地址有什么区别吗 (特别是在 IPv6 的情况下)?
如果不是,那么链路层地址也应该总是 48 位的长度,如果我没记错的话。
提前致谢。如果我遗漏了一些琐碎的事情,请原谅。
编辑:
好的.. 我很清楚黑白链路层地址和以太网 MAC 地址的区别。数据链路层地址有多种类型,以太网MAC地址只是其中一种。
现在,这又出现了一个问题……正如我在第一个问题中所说,我需要将从命令行给出的链路层地址转换为其标准形式。此处提供的解决方案仅适用于以太网 MAC 地址。
没有任何标准功能用于此目的吗?我想做的是创建一个应用程序,用户将在其中输入 ICMP 路由器广告消息中存在的不同选项的值,如RFC 4861 中所述。
Option Formats
Neighbor Discovery messages include zero or more options, some of
which may appear multiple times in the same message. Options should
be padded when necessary to ensure that they end on their natural
64-bit boundaries. All options are of the form:
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 | ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ ... ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Fields:
Type 8-bit identifier of the type of option. The
options defined in this document are:
Option Name Type
Source Link-Layer Address 1
Target Link-Layer Address 2
Prefix Information 3
Redirected Header 4
MTU 5
Length 8-bit unsigned integer. The length of the option
(including the type and length fields) in units of
8 octets. The value 0 is invalid. Nodes MUST
silently discard an ND packet that contains an
option with length zero.
4.6.1. Source/Target Link-layer Address
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 | Link-Layer Address ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Fields:
Type
1 for Source Link-layer Address
2 for Target Link-layer Address
Length The length of the option (including the type and
length fields) in units of 8 octets. For example,
the length for IEEE 802 addresses is 1
[IPv6-ETHER].
Link-Layer Address
The variable length link-layer address.
The content and format of this field (including
byte and bit ordering) is expected to be specified
in specific documents that describe how IPv6
operates over different link layers. For instance,
[IPv6-ETHER].
还有一件事我对 C++ 不太方便,你能提供一个 C 替代方案吗? 谢谢。
【问题讨论】:
-
第一个问题完全重复,您的第二个问题没有建设性。您是在谈论 IEEE 802 的数据链路层吗?还是别的什么?
标签: c linux sockets networking mac-address