src/sys/sockets/addresses

Source   Edit  

Addresses and related utilities

Types

FlowId = distinct uint32

A 20-bit flow identifier. As RFC3493 does not specify an interpretation, the library treats this type as opaque and does not perform any byte-ordering conversions.

From testing, it appears that most operating systems use network byte ordering for values of this type.

Source   Edit  
IP4 = IP4Impl
An IPv4 address. Source   Edit  
IP4Endpoint = IP4EndpointImpl
An IPv4 endpoint, which is a combination of an IPv4 address and a port. Source   Edit  
IP6 = IP6Impl
An IPv6 address. Source   Edit  
IP6Endpoint = IP6EndpointImpl
An IPv6 endpoint, which is a combination of an IPv4 address, a port, a flow identifier and a scope identifier. Source   Edit  
IPEndpoint = object
  case kind*: IPEndpointKind
  of V4:
    v4*: IP4Endpoint
  of V6:
    v6*: IP6Endpoint
An object containing either IPv4 or IPv6 endpoint. Source   Edit  
IPEndpointKind {.pure.} = enum
  V4, V6
The address family of an endpoint. Source   Edit  
Port = distinct uint16
The port number type. Source   Edit  
ScopeId = distinct uint32

A 32-bit address scope identifier. As RFC3493 does not specify an interpretation, the library treats this type as opaque and does not perform any byte-ordering conversions.

From testing, it appears that most operating systems use host byte ordering for values of this type.

Source   Edit  

Consts

IP4Any = (s_addr: 0'u)
The IPv4 address used to signify binding to any address. Source   Edit  
IP4Broadcast = (s_addr: 4294967295'u)
The IPv4 address used to signify any host. Source   Edit  
IP4Loopback = (s_addr: 16777343'u)
The IPv4 loopback address. Source   Edit  
IP6Any = (s6_addr: [0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u,
                    0'u, 0'u, 0'u, 0'u])
The IPv6 address used to specify binding to any address. Source   Edit  
IP6Loopback = (s6_addr: [0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u, 0'u,
                         0'u, 0'u, 0'u, 0'u, 1'u])
The IPv6 loopback address. Source   Edit  
PortNone = 0'u
The port that means "no port". Different procedures will interpret this value differently. Source   Edit  

Procs

proc `$`(e: IP4Endpoint): string {....raises: [], tags: [], forbids: [].}
Source   Edit  
func `$`(ip: IP4): string {.inline, ...raises: [], tags: [], forbids: [].}
Returns the string representation of ip. Source   Edit  
func `$`(ip: IP6): string {....raises: [], tags: [], forbids: [].}
Returns the string representation of ip. Source   Edit  
func `$`(p: Port): string {.borrow, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func `==`(a, b: IP4): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns whether a and b points to the same address. Source   Edit  
func `==`(a, b: IP6): bool {....raises: [], tags: [], forbids: [].}
Returns whether a and b points to the same address. Source   Edit  
func `==`(a, b: Port): bool {.borrow, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func `[]`(ip: IP4; idx: Natural): byte {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns octet at position idx of ip.

Example:

let ip = ip4(127, 0, 0, 1)
doAssert ip[0] == 127
Source   Edit  
func `[]`(ip: IP6; idx: Natural): uint16 {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns the uint16 at position idx. Source   Edit  
func `[]=`(ip: var IP4; idx: Natural; val: byte) {.inline, ...raises: [], tags: [],
    forbids: [].}
Set the octet at position idx to val.

Example:

var ip = ip4(127, 0, 0, 1)
ip[0] = 10
doAssert ip == ip4(10, 0, 0, 1)
Source   Edit  
func `[]=`(ip: var IP6; idx: Natural; val: uint16) {.inline, ...raises: [],
    tags: [], forbids: [].}
Set the uint16 at position idx to val. Source   Edit  
proc flowId(e: IP6Endpoint): FlowId {....raises: [], tags: [], forbids: [].}
Returns the flow identifier of the endpoint. Source   Edit  
proc initEndpoint(ip: IP4; port: Port): IP4Endpoint {....raises: [], tags: [],
    forbids: [].}
Creates an endpoint from an IP address and a port. Source   Edit  
proc initEndpoint(ip: IP6; port: Port; flowId = 0.FlowId; scopeId = 0.ScopeId): IP6Endpoint {.
    ...raises: [], tags: [], forbids: [].}
Creates an IPv6 endpoint. Source   Edit  
proc ip(e: IP4Endpoint): IP4 {....raises: [], tags: [], forbids: [].}
Returns the IPv4 address of the endpoint. Source   Edit  
proc ip(e: IP6Endpoint): IP6 {....raises: [], tags: [], forbids: [].}
Returns the IPv6 address of the endpoint. Source   Edit  
func ip4(a, b, c, d: byte): IP4 {.inline, ...raises: [], tags: [], forbids: [].}
Returns the IP4 object of the IP address a.b.c.d. Source   Edit  
func ip6(a, b, c, d, e, f, g, h: uint16): IP6 {....raises: [], tags: [],
    forbids: [].}
Creates an IP4 object of the address a:b:c:d:e:f:g:h. Source   Edit  
func isV4Mapped(ip: IP6): bool {....raises: [], tags: [], forbids: [].}
Returns whether ip is an IPv4-mapped address as described in RFC4291. Source   Edit  
func len(ip: IP4): int {.inline, ...raises: [], tags: [], forbids: [].}
Returns the number of octets in ip. Source   Edit  
func len(ip: IP6): int {.inline, ...raises: [], tags: [], forbids: [].}
Returns the number of uint16 in ip. Source   Edit  
proc port(e: IP4Endpoint): Port {....raises: [], tags: [], forbids: [].}
Returns the port of the endpoint. Source   Edit  
proc port(e: IP6Endpoint): Port {....raises: [], tags: [], forbids: [].}
Returns the port of the endpoint. Source   Edit  
proc scopeId(e: IP6Endpoint): ScopeId {....raises: [], tags: [], forbids: [].}
Returns the scope identifier of the endpoint. Source   Edit