Addresses v0.1.0
Ipv4Address
pub struct Ipv4Address {
pub octets: uint8[N];
}
An IPv4 address. Copy.
Fields
| Name | Type | Description |
|---|---|---|
octets | uint8[N] | The four octets, most significant first. |
Constructors
Ipv4Address
pub func Ipv4Address(
a: uint8,
b: uint8,
c: uint8,
d: uint8
) -> Ipv4Address
The address a.b.c.d.
| Name | Type | Description |
|---|---|---|
a | uint8 | the first octet |
b | uint8 | the second octet |
c | uint8 | the third octet |
d | uint8 | the fourth octet |
Returns: the address
Associated functions
Localhost
pub func Localhost() -> Ipv4Address
127.0.0.1, this machine.
Returns: the loopback address
Unspecified
pub func Unspecified() -> Ipv4Address
0.0.0.0, every address of this machine when binding.
Returns: the unspecified address
Parse
pub func Parse(text: char8[..]) -> Ipv4Address?
Reads dotted-decimal text such as 192.168.0.1, each octet without leading zeros.
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text |
Returns: the address, or none when the text is not one
Methods
IsLoopback
pub func IsLoopback(&self) -> bool
Whether this is a loopback address, in 127.0.0.0/8.
Returns: true for loopback
IsUnspecified
pub func IsUnspecified(&self) -> bool
Whether this is the unspecified address, 0.0.0.0, which binds every local address.
Returns: true for 0.0.0.0
IsPrivate
pub func IsPrivate(&self) -> bool
Whether this is a private address of RFC 1918: in 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16.
Returns: true for a private address
IsLinkLocal
pub func IsLinkLocal(&self) -> bool
Whether this is a link-local address, in 169.254.0.0/16.
Returns: true for a link-local address
IsMulticast
pub func IsMulticast(&self) -> bool
Whether this is a multicast address, in 224.0.0.0/4.
Returns: true for a multicast address
WriteText
pub func WriteText(&self, into: var char8[..]) -> uint
Writes the address in dotted-decimal form into into, at most 15 characters.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where to write |
Returns: how many characters the text takes, which is more than were written when into is too short
Equals
pub func Equals(&self, other: Ipv4Address) -> bool
Whether two addresses are the same.
| Name | Type | Description |
|---|---|---|
other | Ipv4Address | the address to compare with |
Returns: true when they are equal
Implements Display
Ipv4Address conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
Writes the address in dotted-decimal form, under the placeholder's width, fill and alignment. No style is
understood. Reports whatever the writer reported, and UnsupportedRequest for a style.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole address was accepted
Ipv6Address
pub struct Ipv6Address {
pub octets: uint8[N];
}
An IPv6 address. Copy.
Fields
| Name | Type | Description |
|---|---|---|
octets | uint8[N] | The sixteen octets, most significant first. |
Associated functions
Localhost
pub func Localhost() -> Ipv6Address
::1, this machine.
Returns: the loopback address
Unspecified
pub func Unspecified() -> Ipv6Address
::, every address of this machine when binding.
Returns: the unspecified address
Parse
pub func Parse(text: char8[..]) -> Ipv6Address?
Reads text such as 2001:db8::1 or ::ffff:192.0.2.1. A zone such as %eth0 is not accepted.
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text |
Returns: the address, or none when the text is not one
Methods
IsLoopback
pub func IsLoopback(&self) -> bool
Whether this is the loopback address, ::1.
Returns: true for loopback
IsUnspecified
pub func IsUnspecified(&self) -> bool
Whether this is the unspecified address, ::, which binds every local address.
Returns: true for ::
IsPrivate
pub func IsPrivate(&self) -> bool
Whether this is a unique local address of RFC 4193, in fc00::/7: the IPv6 counterpart of a private IPv4
address.
Returns: true for a unique local address
IsLinkLocal
pub func IsLinkLocal(&self) -> bool
Whether this is a link-local address, in fe80::/10.
Returns: true for a link-local address
IsMulticast
pub func IsMulticast(&self) -> bool
Whether this is a multicast address, in ff00::/8.
Returns: true for a multicast address
AsMappedIpv4
pub func AsMappedIpv4(&self) -> Ipv4Address?
The IPv4 address this one maps, for an address in ::ffff:0:0/96, or none for any other.
Returns: the mapped IPv4 address
WriteText
pub func WriteText(&self, into: var char8[..]) -> uint
Writes the address in the canonical form of RFC 5952 into into, at most 45 characters. An IPv4-mapped
address keeps its IPv4 tail in dotted-decimal form, as ::ffff:192.0.2.1.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where to write |
Returns: how many characters the text takes, which is more than were written when into is too short
Equals
pub func Equals(&self, other: Ipv6Address) -> bool
Whether two addresses are the same.
| Name | Type | Description |
|---|---|---|
other | Ipv6Address | the address to compare with |
Returns: true when they are equal
Implements Display
Ipv6Address conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
Writes the address in the canonical form of RFC 5952, under the placeholder's width, fill and alignment. No
style is understood. Reports whatever the writer reported, and UnsupportedRequest for a style.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole address was accepted
IpAddress
pub struct IpAddress {
// private fields
}
An IPv4 or IPv6 address. Copy.
Associated functions
FromIpv4
pub func FromIpv4(address: Ipv4Address) -> IpAddress
An IPv4 address as an IP address.
| Name | Type | Description |
|---|---|---|
address | Ipv4Address | the IPv4 address |
Returns: the IP address
FromIpv6
pub func FromIpv6(address: Ipv6Address) -> IpAddress
An IPv6 address as an IP address.
| Name | Type | Description |
|---|---|---|
address | Ipv6Address | the IPv6 address |
Returns: the IP address
Parse
pub func Parse(text: char8[..]) -> IpAddress?
Reads an IPv4 or IPv6 address.
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text |
Returns: the address, or none when the text is neither
Methods
IsIpv6
pub func IsIpv6(&self) -> bool
Whether this is an IPv6 address.
Returns: true for IPv6
AsIpv4
pub func AsIpv4(&self) -> Ipv4Address?
The IPv4 address, or none for an IPv6 one.
Returns: the IPv4 address
AsIpv6
pub func AsIpv6(&self) -> Ipv6Address?
The IPv6 address, or none for an IPv4 one.
Returns: the IPv6 address
IsLoopback
pub func IsLoopback(&self) -> bool
Whether this is a loopback address.
Returns: true for loopback
IsUnspecified
pub func IsUnspecified(&self) -> bool
Whether this is the unspecified address, 0.0.0.0 or ::.
Returns: true for the unspecified address
IsPrivate
pub func IsPrivate(&self) -> bool
Whether this is a private IPv4 address or a unique local IPv6 address.
Returns: true for a private address
IsLinkLocal
pub func IsLinkLocal(&self) -> bool
Whether this is a link-local address.
Returns: true for a link-local address
IsMulticast
pub func IsMulticast(&self) -> bool
Whether this is a multicast address.
Returns: true for a multicast address
WriteText
pub func WriteText(&self, into: var char8[..]) -> uint
Writes the address into into, at most 45 characters.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where to write |
Returns: how many characters the text takes
Equals
pub func Equals(&self, other: IpAddress) -> bool
Whether two addresses are the same, which an IPv4 and an IPv6 address never are.
| Name | Type | Description |
|---|---|---|
other | IpAddress | the address to compare with |
Returns: true when they are equal
Implements Display
IpAddress conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
Writes the address as its IPv4 or IPv6 form does, under the placeholder's width, fill and alignment. No
style is understood. Reports whatever the writer reported, and UnsupportedRequest for a style.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole address was accepted
SocketAddress
pub struct SocketAddress {
pub ip: IpAddress;
pub port: uint16;
}
An IP address and a port: where a socket is bound or connected. Copy.
Fields
| Name | Type | Description |
|---|---|---|
ip | IpAddress | The address. |
port | uint16 | The port. |
Constructors
SocketAddress
pub func SocketAddress(
ip: IpAddress,
port: uint16
) -> SocketAddress
An address and a port.
| Name | Type | Description |
|---|---|---|
ip | IpAddress | the address |
port | uint16 | the port |
Returns: the socket address
Associated functions
Parse
pub func Parse(text: char8[..]) -> SocketAddress?
Reads address:port, with an IPv6 address in brackets, as in [::1]:8080.
| Name | Type | Description |
|---|---|---|
text | char8[..] | the text |
Returns: the socket address, or none when the text is not one
Methods
WriteText
pub func WriteText(&self, into: var char8[..]) -> uint
Writes address:port into into, an IPv6 address in brackets, at most 47 characters.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where to write |
Returns: how many characters the text takes
ToString
pub func ToString(
&self,
allocator: Allocator
) -> String throws TextError
The text of the address, as WriteText writes it.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the text is kept in |
Returns: the text
Equals
pub func Equals(&self, other: SocketAddress) -> bool
Whether two socket addresses are the same.
| Name | Type | Description |
|---|---|---|
other | SocketAddress | the address to compare with |
Returns: true when they are equal
Implements Display
SocketAddress conforms to Display.
WriteDisplay
pub func WriteDisplay(
&self,
writer: &var TextWriter,
spec: FormatSpec
) throws FormatError
Writes the address and port, an IPv6 address in brackets, under the placeholder's width, fill and alignment.
No style is understood. Reports whatever the writer reported, and UnsupportedRequest for a style.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole address was accepted