|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
MAC地址封装类 更多...
#include <mac_address.hpp>
Public 类型 | |
| using | bytes_type = array<byte_t, MAC_LEN> |
| MAC地址字节数组类型 | |
Public 成员函数 | |
| mac_address () noexcept=default | |
| 默认构造函数 | |
| mac_address (const byte_t *bytes) noexcept | |
| 从字节数组构造 | |
| mac_address (const bytes_type &bytes) noexcept | |
| 从字节数组容器构造 | |
| string | to_string () const |
| 转换为字符串表示 | |
| bool | operator== (const mac_address &other) const noexcept |
| 相等比较运算符 | |
| bool | operator!= (const mac_address &other) const noexcept |
| 不等比较运算符 | |
| const bytes_type & | bytes () const noexcept |
| 获取MAC地址字节数组 | |
| Public 成员函数 继承自 istringify< mac_address > | |
| constexpr string | to_string () const |
| 转换为字符串 | |
静态 Public 成员函数 | |
| static optional< mac_address > | parse (string_view str) |
| 从字符串解析MAC地址 | |
| static optional< mac_address > | parse (const ip_address &ip, const char *iface=nullptr) |
| 从IP地址获取MAC地址 | |
静态 Public 属性 | |
| static constexpr size_t | MAC_LEN = 6 |
| MAC地址字节长度 | |
MAC地址封装类
支持MAC地址的解析、格式化和通过ARP协议从IP地址获取MAC地址。
本实现严格遵循以下网络寻址与协议相关标准规范:
MAC 地址标准(IEEE 802 系列):
地址表示格式标准:
根据 IEEE 802.3,MAC 地址(48 位 EUI-48)由以下部分组成:
| 字段 | 位数 | 说明 |
|---|---|---|
| OUI | 24 | 组织唯一标识符,由 IEEE 分配给制造商 |
| NIC Specific | 24 | 网络接口卡特定部分,由制造商分配 |
**地址类型标识**(第一个字节的最低位):
| 位值 | 类型 | 说明 |
|---|---|---|
| 0 | 单播地址 | 发送到单个网络接口 |
| 1 | 多播地址 | 发送到一组网络接口 |
**本地管理标识**(第一个字节的次低位):
| 位值 | 类型 | 说明 |
|---|---|---|
| 0 | 全局唯一地址 | IEEE 分配的 OUI |
| 1 | 本地管理地址 | 由网络管理员分配 |
根据 IEEE 802.3 §3.2.4 和 RFC 7042,MAC 地址的标准表示为:
**支持的格式示例**:
| 格式 | 示例 | 说明 |
|---|---|---|
| 冒号分隔(推荐) | 00:11:22:33:44:55 | 本实现默认格式 |
| 连字符分隔 | 00-11-22-33-44-55 | 常见于某些操作系统 |
| 无分隔符 | 001122334455 | 紧凑格式 |
在文件 mac_address.hpp 第 84 行定义.
|
defaultnoexcept |
|
inlineexplicitnoexcept |
从字节数组构造
| bytes | 指向6字节数据的指针 |
在文件 mac_address.hpp 第 104 行定义.
引用了 bytes(), copy(), mac_address() , 以及 MAC_LEN.
|
inlineexplicitnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
static |
从IP地址获取MAC地址
| ip | IP地址对象 |
| iface | 网络接口名称(Linux可选) |
通过ARP查询指定IP对应的MAC地址。
|
static |
从字符串解析MAC地址
| str | MAC地址字符串 |
支持的格式:
|
nodiscard |
转换为字符串表示