IPv6Addr-0.1: Library to deal with the IPv6 address's text representation.

Stabilityprovisional
Maintainermichel.boucey@gmail.com

Text.IPv6Addr

Contents

Description

Dealing with IPv6 address's text representation. Main features are validation against RFC 4291 and canonization in conformation with RFC 5952.

Synopsis

Documentation

data IPv6AddrToken Source

Constructors

SixteenBits Text

A four hexadecimal digits group representing a 16-Bit chunk

AllZeros

An all zeros 16-Bit chunk

Colon

A separator between 16-Bit chunks

DoubleColon

A double-colon stands for a unique compression of many consecutive 16-Bit chunks

IPv4Addr Text

An embedded IPv4 address as representation of the last 32-Bit

Validating and canonizing an IPv6 Address

isIPv6Addr :: [IPv6AddrToken] -> BoolSource

Returns True if a list of IPv6AddrToken constitutes a valid IPv6 Address.

maybeIPv6Addr :: Text -> Maybe IPv6AddrSource

Returns Just an IPv6Addr, or Nothing.

 maybeIPv6Addr "D045::00Da:0fA9:0:0:230.34.110.80" == Just "d045:0:da:fa9::e622:6e50"

maybeTokIPv6Addr :: Text -> Maybe [IPv6AddrToken]Source

This is the main function which returns Just the list of a tokenized IPv6 address's text representation validated against RFC 4291 and canonized (rewritten) in conformation with RFC 5952, or Nothing.

maybeExpIPv6Addr :: Text -> Maybe IPv6AddrSource

Returns Just an expanded IPv6 address, or Nothing.

getIPv6AddrOf :: String -> IO (Maybe IPv6Addr)Source

Given a valid name of a local network interface, e.g. getIPv6AddrOf "eth0", return Just the interface's IPv6 address.

Manipulating IPv6 address tokens

To IPv6 Address token(s)

maybeIPv6AddrTokens :: Text -> Maybe [IPv6AddrToken]Source

Returns Just a list of IPv6AddrToken, or Nothing.

macAddrToIPv6AddrTokens :: Text -> [IPv6AddrToken]Source

Given a MAC address, returns the corresponding IPv6AddrToken list, or an empty list.

 macAddrToIPv6AddrTokens "fa:1d:58:cc:95:16" == [SixteenBits "fa1d",Colon,SixteenBits "58cc",Colon,SixteenBits "9516"]

getTokIPv6AddrOf :: String -> IO (Maybe [IPv6AddrToken])Source

Given a valid name of a local network interface, returns Just the list of tokens of the interface's IPv6 address.

getTokMacAddrOf :: String -> IO (Maybe [IPv6AddrToken])Source

Given the valid name of a local network interface, returns the corresponding list of IPv6AddrToken of the interface's MAC Address.

sixteenBitsRand :: String -> IO IPv6AddrTokenSource

Returns a random SixteenBits token. E.g. sixteenBitsRand "d" may produce SixteenBits "d7b5".

ipv4AddrToIPv6AddrTokens :: IPv6AddrToken -> [IPv6AddrToken]Source

Rewrites Just an embedded IPv4Addr into the corresponding list of pure IPv6Addr tokens, or returns an empty list.

 ipv4AddrToIPv6AddrTokens (IPv4Addr "127.0.0.1") == [SixteenBits "7f0",Colon,SixteenBits "1"]

Back to Text

ipv6TokensToText :: [IPv6AddrToken] -> TextSource

Given an arbitrary list of IPv6AddrToken, returns the corresponding Text.