|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
IP地址封装类 更多...
#include <ip_address.hpp>
Public 类型 | |
| enum class | family : int32_t { UNDEF = AF_UNSPEC , UNIX = AF_UNIX , INET4 = AF_INET , INET6 = AF_INET6 , PACKET = AF_PACKET , NETLINK = AF_NETLINK , BLUETOOTH = AF_BLUETOOTH , CAN = AF_CAN , ALG = AF_ALG , VSOCK = AF_VSOCK , NFC = AF_NFC , XDP = AF_XDP } |
| 网络地址族类型枚举 更多... | |
| using | address_type = variant<none_t, ::sockaddr_in, ::sockaddr_in6> |
| 地址存储类型 | |
Public 成员函数 | |
| ip_address () noexcept=default | |
| 默认构造函数 | |
| ip_address (const ::sockaddr_in &addr4) noexcept | |
| 从IPv4地址构造 | |
| ip_address (const ::sockaddr_in6 &addr6) noexcept | |
| 从IPv6地址构造 | |
| bool | is_valid () const noexcept |
| 检查地址是否有效 | |
| bool | is_ipv4 () const noexcept |
| 检查是否为IPv4地址 | |
| bool | is_ipv6 () const noexcept |
| 检查是否为IPv6地址 | |
| const ::sockaddr * | data () const noexcept |
| 获取底层指针 | |
| ::sockaddr * | data () noexcept |
| 获取底层指针 | |
| int | size () const noexcept |
| 获取地址结构大小 | |
| const address_type & | address () const noexcept |
| 获取内部地址存储的常量引用 | |
| family | address_family () const noexcept |
| 获取地址族 | |
| ports | port () const noexcept |
| 获取端口号 | |
| string | to_string () const |
| 转换为字符串表示 | |
| bool | operator== (const ip_address &other) const |
| 相等比较运算符 | |
| bool | operator!= (const ip_address &other) const |
| 不等比较运算符 | |
| Public 成员函数 继承自 neforce::istringify< ip_address > | |
| constexpr string | to_string () const |
| 转换为字符串 | |
静态 Public 成员函数 | |
| static ip_address | any (ports port=ports::UNDEF, family f=family::INET4) noexcept |
| 获取通配地址 | |
| static ip_address | loopback (ports port=ports::UNDEF, family f=family::INET4) noexcept |
| 获取回环地址 | |
| static optional< ip_address > | parse (const string &host, ports port=ports{}) noexcept |
| 从字符串解析IP地址 | |
IP地址封装类
封装IPv4和IPv6地址,提供统一的访问接口。
主要功能:
在文件 ip_address.hpp 第 49 行定义.
|
strong |
网络地址族类型枚举
| 枚举值 | |
|---|---|
| UNDEF | 未指定地址族,通常用于通配或自动选择 |
| UNIX | Unix 域套接字 |
| INET4 | IPv4 互联网协议族 |
| INET6 | IPv6 互联网协议族 |
| PACKET | 链路层数据包套接字 |
| NETLINK | 内核用户空间通信 |
| BLUETOOTH | 蓝牙通信协议族 |
| CAN | CAN 总线协议族 |
| ALG | 内核加密 API 接口 |
| VSOCK | 虚拟机套接字 |
| NFC | 近场通信协议族 |
| XDP | 高性能数据路径 |
在文件 ip_address.hpp 第 56 行定义.
|
defaultnoexcept |
默认构造函数
创建无效的IP地址对象。
被这些函数引用 any(), ip_address(), loopback(), operator!=(), operator==() , 以及 parse().
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlinenodiscardnoexcept |
|
nodiscardnoexcept |
获取地址族
|
staticnodiscardnoexcept |
获取通配地址
| port | 端口号 |
| f | 地址族,默认为INET4 |
通配地址用于绑定到所有网络接口。
引用了 INET4, ip_address(), port() , 以及 neforce::ports::UNDEF.
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
staticnodiscardnoexcept |
获取回环地址
| port | 端口号 |
| f | 地址族,默认为INET4 |
引用了 INET4, ip_address(), port() , 以及 neforce::ports::UNDEF.
|
inlinenodiscard |
|
nodiscard |
|
staticnodiscardnoexcept |
从字符串解析IP地址
| host | IP地址字符串 |
| port | 端口号 |
支持IPv4点分十进制和IPv6十六进制格式。 不支持域名解析(如有需要请使用dns_client)。
引用了 ip_address(), parse() , 以及 port().
被这些函数引用 parse().
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscard |
转换为字符串表示
IPv4格式:192.168.1.1:8080 IPv6格式:[2001:db8::1]:443
引用了 to_string().
被这些函数引用 to_string().