Copyright | Copyright © 2020 Lars Kuhtz <lakuhtz@gmail.com> |
---|---|
License | MIT |
Maintainer | Lars Kuhtz <lakuhtz@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Host addresses as described in RFC2396 section 3.2.2 with additional consideration of
- RFC1123 (additional restrictions for hostnames),
- RFC1034 (disambiguate domain names and IPv4 addresses),
- RFC4291 (parsing of IPv6 addresses), and
- RFC3986 and RFC5952 (IPv6 literals within host addresses).
Port numbers must be within the range [0,2^16-1]
.
All hostnames are considered fully qualified and thus the final dot is omitted.
For hostnames we follow the specification for "Server-based Naming Authority" for URIs from RFC2396 section 3.2.2.:
hostport = host [ ":" port ] host = hostname | IPv4address hostname = *( domainlabel "." ) toplabel [ "." ] domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum toplabel = alpha | alpha *( alphanum | "-" ) alphanum IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit port = *digit
1*digit
designates the decimal representation of an octet. The specification
takes the form of hostnames from section 2.1 RFC1123, but limiting the
rightmost (top-most) label to the from given in section 3 of RFC1034, which
allows to disambiguate domain names and IPv4 addresses.
IPv6 Addresses are partially supported. IPv6 address are parsed as described in RFC4291, but embedding of IPv4 addresses is not supported. IPv6 addresses are printed exactly as they where parsed. No normalization is performed. In particular the recommendations from RFC5952 are not considered. For host addresses RFC3986 and RFC5952 are followed by requiring that IPv6 literals are enclosed in square brackets. Anything else from RFC3986, which is concerning URIs is ignored.
Additional restriction for hostname apply from RFC1123: labels must have not more than 63 octets, letters are case-insensitive. The maximum length must not exceed 254 octets, excluding the (optional) terminating dot.
See https://cs.uwaterloo.ca/twiki/view/CF/HostNamingRules for an extensive overview of different standards for host names.
Non-ascii characters are encoded via Punycode and are of no concern in this implementation.
Synopsis
- data Port
- portToText :: Port -> Text
- portFromText :: MonadThrow m => Text -> m Port
- readPortBytes :: MonadThrow m => ByteString -> m Port
- data Hostname
- hostnameBytes :: Hostname -> ByteString
- readHostnameBytes :: MonadThrow m => ByteString -> m Hostname
- hostnameToText :: Hostname -> Text
- hostnameFromText :: MonadThrow m => Text -> m Hostname
- unsafeHostnameFromText :: HasCallStack => Text -> Hostname
- localhost :: Hostname
- localhostIPv4 :: Hostname
- localhostIPv6 :: Hostname
- anyIpv4 :: Hostname
- broadcast :: Hostname
- loopback :: Hostname
- isReservedHostname :: Hostname -> Bool
- isPrivateHostname :: Hostname -> Bool
- isLocalIp :: IPv4 -> Bool
- data HostAddress = HostAddress {}
- hostAddressPort :: Lens' HostAddress Port
- hostAddressHost :: Lens' HostAddress Hostname
- hostAddressBytes :: HostAddress -> ByteString
- readHostAddressBytes :: MonadThrow m => ByteString -> m HostAddress
- hostAddressToText :: HostAddress -> Text
- hostAddressFromText :: MonadThrow m => Text -> m HostAddress
- unsafeHostAddressFromText :: HasCallStack => Text -> HostAddress
- isPrivateHostAddress :: HostAddress -> Bool
- isReservedHostAddress :: HostAddress -> Bool
Port Numbers
Instances
Bounded Port Source # | |
Enum Port Source # | |
Eq Port Source # | |
Integral Port Source # | |
Num Port Source # | |
Ord Port Source # | |
Real Port Source # | |
Defined in Network.HostAddress toRational :: Port -> Rational # | |
Show Port Source # | |
Generic Port Source # | |
NFData Port Source # | |
Defined in Network.HostAddress | |
Hashable Port Source # | |
Defined in Network.HostAddress | |
type Rep Port Source # | |
Defined in Network.HostAddress |
portToText :: Port -> Text Source #
portFromText :: MonadThrow m => Text -> m Port Source #
readPortBytes :: MonadThrow m => ByteString -> m Port Source #
Hostnames
Instances
Eq Hostname Source # | |
Ord Hostname Source # | |
Defined in Network.HostAddress | |
Show Hostname Source # | |
Generic Hostname Source # | |
NFData Hostname Source # | |
Defined in Network.HostAddress | |
Hashable Hostname Source # | |
Defined in Network.HostAddress | |
type Rep Hostname Source # | |
Defined in Network.HostAddress type Rep Hostname = D1 (MetaData "Hostname" "Network.HostAddress" "hostaddress-0.1.0.0-F3mdNZ0s3Us5jbXgpRWOxN" False) (C1 (MetaCons "HostnameName" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CI ByteString))) :+: (C1 (MetaCons "HostnameIPv4" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CI ByteString))) :+: C1 (MetaCons "HostnameIPv6" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CI ByteString))))) |
hostnameBytes :: Hostname -> ByteString Source #
readHostnameBytes :: MonadThrow m => ByteString -> m Hostname Source #
hostnameToText :: Hostname -> Text Source #
hostnameFromText :: MonadThrow m => Text -> m Hostname Source #
unsafeHostnameFromText :: HasCallStack => Text -> Hostname Source #
Special Host Names
localhostIPv4 :: Hostname Source #
Using explicit IP addresses and not to "localhost" greatly improves networking performance and Mac OS X.
localhostIPv6 :: Hostname Source #
Using explicit IP addresses and not to "localhost" greatly improves networking performance and Mac OS X.
isReservedHostname :: Hostname -> Bool Source #
isPrivateHostname :: Hostname -> Bool Source #
HostAddresses
data HostAddress Source #
Instances
readHostAddressBytes :: MonadThrow m => ByteString -> m HostAddress Source #
hostAddressToText :: HostAddress -> Text Source #
hostAddressFromText :: MonadThrow m => Text -> m HostAddress Source #