NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
mac_address类 参考

MAC地址封装类 更多...

#include <mac_address.hpp>

类 mac_address 继承关系图:
[图例]

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_typebytes () const noexcept
 获取MAC地址字节数组
Public 成员函数 继承自 istringify< mac_address >
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string () const
 转换为字符串

静态 Public 成员函数

static optional< mac_addressparse (string_view str)
 从字符串解析MAC地址
static optional< mac_addressparse (const ip_address &ip, const char *iface=nullptr)
 从IP地址获取MAC地址

静态 Public 属性

static constexpr size_t MAC_LEN = 6
 MAC地址字节长度

详细描述

MAC地址封装类

封装6字节的MAC地址,提供地址解析、格式化和ARP查询功能。

MAC地址格式:XX:XX:XX:XX:XX:XX(6组十六进制数,每组2位)

主要功能:

  • MAC地址字符串解析
  • MAC地址格式化输出
  • 通过ARP协议从IP地址获取MAC地址

在文件 mac_address.hpp39 行定义.

构造及析构函数说明

◆ mac_address() [1/3]

mac_address::mac_address ( )
defaultnoexcept

默认构造函数

创建全零的MAC地址。

被这些函数引用 mac_address(), operator!=() , 以及 operator==().

◆ mac_address() [2/3]

mac_address::mac_address ( const byte_t * bytes)
inlineexplicitnoexcept

从字节数组构造

参数
bytes指向6字节数据的指针

在文件 mac_address.hpp59 行定义.

引用了 bytes(), copy(), mac_address() , 以及 MAC_LEN.

◆ mac_address() [3/3]

mac_address::mac_address ( const bytes_type & bytes)
inlineexplicitnoexcept

从字节数组容器构造

参数
bytesMAC地址字节数组

在文件 mac_address.hpp65 行定义.

引用了 bytes().

成员函数说明

◆ bytes()

const bytes_type & mac_address::bytes ( ) const
inlinenoexcept

获取MAC地址字节数组

返回
6字节数组的常量引用

在文件 mac_address.hpp116 行定义.

被这些函数引用 mac_address() , 以及 mac_address().

◆ operator!=()

bool mac_address::operator!= ( const mac_address & other) const
inlinenoexcept

不等比较运算符

参数
other另一个MAC地址
返回
地址不同返回true

在文件 mac_address.hpp110 行定义.

引用了 mac_address().

◆ operator==()

bool mac_address::operator== ( const mac_address & other) const
inlinenoexcept

相等比较运算符

参数
other另一个MAC地址
返回
地址相同返回true

在文件 mac_address.hpp103 行定义.

引用了 mac_address().

◆ parse() [1/2]

optional< mac_address > mac_address::parse ( const ip_address & ip,
const char * iface = nullptr )
static

从IP地址获取MAC地址

参数
ipIP地址对象
iface网络接口名称(Linux可选)
返回
成功返回MAC地址,失败返回none

通过ARP查询指定IP对应的MAC地址。

注解
仅在本地网络中有效,需要目标主机在线且可达。
此操作可能需要适当的系统权限。

◆ parse() [2/2]

optional< mac_address > mac_address::parse ( string_view str)
static

从字符串解析MAC地址

参数
strMAC地址字符串
返回
解析成功返回MAC地址对象,失败返回none

支持的格式:

  • "00:11:22:33:44:55"(冒号分隔)
  • "00-11-22-33-44-55"(连字符分隔)

◆ to_string()

string mac_address::to_string ( ) const

转换为字符串表示

返回
格式化的MAC地址字符串

该类的文档由以下文件生成: