我不得不与我实现了两个问题 -inet_pton()对应为链路层地址
我需要它可以从文本转换给定链路层地址,以标准格式一样,我们也有类似的功能功能在n/w层的IP地址
inet_pton()
它将给定的IP地址从文本转换为标准的IPv4/IPv6格式。是否有任何区别b/w链路层地址和48位mac地址 (特别是在IPv6的情况下)?
如果不是,那么链路层地址应该总是48位长,如果我没有错的话。
在此先感谢。请原谅我是否缺少一些微不足道的东西。
编辑:
好吧..我上的区别清楚的B/W链路层地址和以太网MAC地址。有几种类型的数据链路层地址,以太网mac地址只是一个。
现在,这又出现了一个问题......正如我在第一个问题中所说的,我需要将从命令行给出的链接层地址转换为其标准格式。此处提供的解决方案仅适用于以太网MAC地址。
是否有任何标准功能用于此目的?我想要做的是创建一个应用程序,其中用户将输入如在RFC 4861
中所述的ICMP路由器广播消息中存在的不同选项的值。
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的替代品吗? 谢谢。
[C++将mac id字符串转换为uint8 \ _t数组]可能的重复(http://stackoverflow.com/questions/276099/c-converting-a-mac-id-string-into-an- array-of-uint8-t) – 2012-12-10 19:44:32
第一个问题是一个确切的重复,你的第二个问题不是建设性的。你在谈论IEEE 802的数据链路层吗?或者是其他东西? – 2012-12-10 19:48:28