at 25.11-pre 1.2 kB view raw
1{ lib }: 2let 3 inherit (import ./internal.nix { inherit lib; }) _ipv6; 4in 5{ 6 ipv6 = { 7 /** 8 Creates an `IPv6Address` object from an IPv6 address as a string. If 9 the prefix length is omitted, it defaults to 64. The parser is limited 10 to the first two versions of IPv6 addresses addressed in RFC 4291. 11 The form "x:x:x:x:x:x:d.d.d.d" is not yet implemented. Addresses are 12 NOT compressed, so they are not always the same as the canonical text 13 representation of IPv6 addresses defined in RFC 5952. 14 15 # Type 16 17 ``` 18 fromString :: String -> IPv6Address 19 ``` 20 21 # Examples 22 23 ```nix 24 fromString "2001:DB8::ffff/32" 25 => { 26 address = "2001:db8:0:0:0:0:0:ffff"; 27 prefixLength = 32; 28 } 29 ``` 30 31 # Arguments 32 33 - [addr] An IPv6 address with optional prefix length. 34 */ 35 fromString = 36 addr: 37 let 38 splittedAddr = _ipv6.split addr; 39 40 addrInternal = splittedAddr.address; 41 prefixLength = splittedAddr.prefixLength; 42 43 address = _ipv6.toStringFromExpandedIp addrInternal; 44 in 45 { 46 inherit address prefixLength; 47 }; 48 }; 49}