net::ip
net::ip provides tools for parsing and working with IPv4 and IPv6 addresses and CIDR subnets.
Index
Types
type addr = (addr4 | addr6);
type addr4 = [4]u8;
type addr6 = [16]u8;
type subnet = struct {
addr: addr,
mask: addr,
};
Errors
type invalid = !void;
Globals
const ANY_V4: addr4;
const ANY_V6: addr6;
const LOCAL_V4: addr4;
const LOCAL_V6: addr6;
Functions
fn equal(l: addr, r: addr) bool;
fn fmt(s: io::handle, item: (...addr | subnet)) (size | io::error);
fn parse(s: str) (addr | invalid);
fn parsecidr(st: str) (subnet | invalid);
fn parsev4(st: str) (addr4 | invalid);
fn parsev6(st: str) (addr6 | invalid);
fn string(item: (...addr | subnet)) str;
fn subnet_contains(sub: subnet, item: (addr | subnet)) bool;
fn from_native(a: rt::sockaddr) (addr, u16);
fn to_native(a: addr, port: u16) rt::sockaddr;
Types
type addr
type addr = (addr4 | addr6);
An IP address.
type addr4
type addr4 = [4]u8;
An IPv4 address.
type addr6
type addr6 = [16]u8;
An IPv6 address.
type subnet
type subnet = struct {
addr: addr,
mask: addr,
};
An IP subnet.
Errors
type invalid
type invalid = !void;
Invalid parse result.
Globals
let ANY_V4
const ANY_V4: addr4;
An IPv4 address which represents "any" address, i.e. "0.0.0.0". Binding to this address will listen on all available IPv4 interfaces on most systems.
let ANY_V6
const ANY_V6: addr6;
An IPv6 address which represents "any" address, i.e. "::". Binding to this address will listen on all available IPv6 interfaces on most systems.
let LOCAL_V4
const LOCAL_V4: addr4;
An IPv4 address which represents the loopback address, i.e. "127.0.0.1".
let LOCAL_V6
const LOCAL_V6: addr6;
An IPv6 address which represents the loopback address, i.e. "::1".
Functions
fn equal
fn equal(l: addr, r: addr) bool;
Test if two addrs are equal.
fn fmt
fn fmt(s: io::handle, item: (...addr | subnet)) (size | io::error);
Formats an addr or subnet and prints it to a stream.
fn parse
fn parse(s: str) (addr | invalid);
Parses an IP address.
fn parsecidr
fn parsecidr(st: str) (subnet | invalid);
Parse an IP subnet in CIDR notation e.g. 192.168.1.0/24
fn parsev4
fn parsev4(st: str) (addr4 | invalid);
Parses an IPv4 address.
fn parsev6
fn parsev6(st: str) (addr6 | invalid);
Parses an IPv6 address.
fn string
fn string(item: (...addr | subnet)) str;
Formats an addr or subnet as a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to extend its lifetime.
fn subnet_contains
fn subnet_contains(sub: subnet, item: (addr | subnet)) bool;
Returns whether an addr (or another subnet) is contained within a subnet.
fn from_native
Show undocumented member
fn from_native(a: rt::sockaddr) (addr, u16);
fn to_native
Show undocumented member
fn to_native(a: addr, port: u16) rt::sockaddr;