encode package:ip

Encode an IP as Text.
>>> encode (ipv4 10 0 0 25)
"10.0.0.25"
>>> encode (ipv6 0x3124 0x0 0x0 0xDEAD 0xCAFE 0xFF 0xFE00 0x1)
"3124::dead:cafe:ff:fe00:1"
Encode an IPv4 address to Text using dot-decimal notation:
>>> T.putStrLn (IPv4.encode (IPv4.ipv4 192 168 2 47))
192.168.2.47
Encodes the IPv6 address using zero-compression on the leftmost longest string of zeroes in the address. Per RFC 5952 Section 5, this uses mixed notation when encoding an IPv4-mapped IPv6 address:
>>> T.putStrLn $ IPv6.encode $ IPv6.fromWord16s 0xDEAD 0xBEEF 0x0 0x0 0x0 0x0 0x0 0x1234
dead:beef::1234

>>> T.putStrLn $ IPv6.encode $ IPv6.fromWord16s 0x0 0x0 0x0 0x0 0x0 0xFFFF 0x6437 0xA5B4
::ffff:100.55.165.180

>>> T.putStrLn $ IPv6.encode $ IPv6.fromWord16s 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
::
Per Section 4.2.2 of the same RFC, this does not use :: to shorten a single 16-bit 0 field. Only runs of multiple 0 fields are considered.
Encode a Mac address using the default MacCodec defCodec.
>>> T.putStrLn (Mac.encode (Mac 0xA47F247AB423))
a4:7f:24:7a:b4:23
Encode an IP as ShortText.
>>> encodeShort (ipv4 10 0 1 26)
"10.0.1.26"
>>> encodeShort (ipv6 0x3124 0x0 0x0 0xDEAD 0xCAFE 0xFF 0xFE01 0x0000)
"3124::dead:cafe:ff:fe01:0"
Encode an IPv4Range as Text.
>>> IPv4.encodeRange (IPv4.IPv4Range (IPv4.ipv4 172 16 0 0) 12)
"172.16.0.0/12"
Encode an IPv4 address as ShortText.
>>> IPv4.encodeShort (IPv4.ipv4 192 168 5 99)
"192.168.5.99"
Encode an IPv4 as a String.
Encode an IPv4 address to a UTF-8 encoded ByteString.
>>> IPv4.encodeUtf8 (IPv4.ipv4 192 168 2 47)
"192.168.2.47"
Encode an IPv6Range as Text.
>>> addr = IPv6.ipv6 0xDEAD 0xBEEF 0x3240 0xA426 0xBA68 0x1CD0 0x4263 0x109B

>>> T.putStrLn $ IPv6.encodeRange $ IPv6.IPv6Range addr 28
dead:beef:3240:a426:ba68:1cd0:4263:109b/28
Encodes the IPv6 address as ShortText using zero-compression on the leftmost longest string of zeroes in the address. Per RFC 5952 Section 5, this uses mixed notation when encoding an IPv4-mapped IPv6 address.
>>> IPv6.encodeShort $ IPv6.fromWord16s 0xDEAD 0xBEEF 0x0 0x0 0x0 0x0ABC 0x0 0x1234
"dead:beef::abc:0:1234"
Encode a Mac address as colon-separated hexadecimal octets, preferring lowercase for alphabetical characters.
Encode a Mac address using the default MacCodec defCodec.
>>> BC.putStrLn (Mac.encodeUtf8 (Mac.mac 0x64255A0F2C47))
64:25:5a:0f:2c:47
Encode a Mac address using the given MacCodec.
>>> m = Mac 0xA47F247AB423

>>> T.putStrLn $ Mac.encodeWith Mac.defCodec m
a4:7f:24:7a:b4:23
>>> T.putStrLn $ Mac.encodeWith (Mac.MacCodec (Mac.MacGroupingTriples '-') True) m
A47-F24-7AB-423
Encode a Mac address as a ByteString using the given MacCodec.
>>> m = Mac 0xA47F247AB423

>>> BC.putStrLn $ Mac.encodeWithUtf8 Mac.defCodec m
a4:7f:24:7a:b4:23
>>> BC.putStrLn $ Mac.encodeWithUtf8 (Mac.MacCodec (Mac.MacGroupingTriples '-') True) m
A47-F24-7AB-423