IpAddress
Immutable and safe representation of an IP address, either V4 or V6.
=== Construction ===
IpAddress
instances are constructed in a few different ways:- via
IpAddress("127.0.0.1")
, which parses a string representation of the IP and returns an Option[IpAddress]
- via
IpAddress.fromBytes(arr)
, which returns an IP address if the supplied array is either exactly 4 bytes or exactly 16 bytes- via literal syntax like
ip"127.0.0.1"
, which returns an IpAddress
and fails to compile if the IP is invalid.=== Type Hierarchy ===
There are two subtypes of
API than
It is safe to pattern match on
IpAddress
-- Ipv4Address and Ipv6Address. Each of these subtypes have a richerAPI than
IpAddress
and it is often useful to use those types directly, for example if your use case requires a V6 address.It is safe to pattern match on
IpAddress
to access Ipv4Address
or Ipv6Address
directly, or alternatively, you can use fold.=== JVM Specific API ===
If using
with networking libraries. This method does not exist on the Scala.js version.
IpAddress
on the JVM, you can call toInetAddress
to convert the address to a java.net.InetAddress
, for usewith networking libraries. This method does not exist on the Scala.js version.
- Companion
- object
Value members
Methods
Converts this address to a source specific multicast address, as long as it is in the source specific multicast address range.