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 anOption[IpAddress]
via
IpAddress.fromBytes(arr)
, which returns an IP address if the supplied array is either exactly 4 bytes or exactly 16 bytesvia literal syntax like
ip"127.0.0.1"
, which returns anIpAddress
and fails to *compile* if the IP is invalid.
Type Hierarchy
There are two subtypes of IpAddress
-- Ipv4Address and Ipv6Address. Each of these subtypes have a richer API 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 IpAddress
on the JVM, you can call toInetAddress
to convert the address to a java.net.InetAddress
, for use with networking libraries. This method does not exist on the Scala.js version.
Attributes
- Companion
- object
- Source
- Host.scala
- Graph
-
- Supertypes
-
trait Serializabletrait Hosttrait Ordered[Host]trait Comparable[Host]class Objecttrait Matchableclass AnyShow all
- Known subtypes
-
class Ipv4Addressclass Ipv6Address
Members list
Value members
Abstract methods
Converts this address to a value of type A
using the supplied functions.
Converts this address to a value of type A
using the supplied functions.
Attributes
- Source
- Host.scala
Returns true if this address is in the multicast range.
Returns true if this address is in the source specific multicast range.
Returns true if this address is in the source specific multicast range.
Attributes
- Source
- Host.scala
Gets the IP address after this address, with overflow from the maximum value to the minimum value.
Gets the IP address after this address, with overflow from the maximum value to the minimum value.
Attributes
- Source
- Host.scala
Gets the IP address before this address, with underflow from minimum value to the maximum value.
Gets the IP address before this address, with underflow from minimum value to the maximum value.
Attributes
- Source
- Host.scala
Converts this address to a string form that is compatible for use in a URI per RFC3986 (namely, IPv6 addresses are rendered in condensed form and surrounded by brackets).
Converts this address to a string form that is compatible for use in a URI per RFC3986 (namely, IPv6 addresses are rendered in condensed form and surrounded by brackets).
Attributes
- Source
- Host.scala
Maps a type-preserving function across this IP address.
Concrete methods
Constructs a Cidr address from this address.
Narrows this address to an Ipv4Address if that is the underlying type.
Narrows this address to an Ipv6Address if that is the underlying type.
Converts this address to a multicast address, as long as it is in the multicast address range.
Converts this address to a multicast address, as long as it is in the multicast address range.
Attributes
- Source
- Host.scala
Converts this address to a source specific multicast address, as long as it is in the source specific multicast address range.
Converts this address to a source specific multicast address, as long as it is in the source specific multicast address range.
Attributes
- Source
- Host.scala
Like asSourceSpecificMulticast
but allows multicast addresses outside the source specific range.
Like asSourceSpecificMulticast
but allows multicast addresses outside the source specific range.
Attributes
- Source
- Host.scala
If this address is an IPv4 mapped IPv6 address, converts to an IPv4 address, otherwise returns this.
If this address is an IPv4 mapped IPv6 address, converts to an IPv4 address, otherwise returns this.
Attributes
- Source
- Host.scala
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance x
of type Any
, x.equals(x)
should return true
. - It is symmetric: for any instances x
and y
of type Any
, x.equals(y)
should return true
if and only if y.equals(x)
returns true
. - It is transitive: for any instances x
, y
, and z
of type Any
if x.equals(y)
returns true
and y.equals(z)
returns true
, then x.equals(z)
should return true
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
-
Any
- Source
- Host.scala
Calculate a hash code value for the object.
Calculate a hash code value for the object.
The default hashing algorithm is platform dependent.
Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)
) yet not be equal (o1.equals(o2)
returns false
). A degenerate implementation could always return 0
. However, it is required that if two objects are equal (o1.equals(o2)
returns true
) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)
). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals
method.
Attributes
- Returns
-
the hash code value for this object.
- Definition Classes
-
Any
- Source
- Host.scala
Returns true if this address is a V6 address containing a mapped V4 address.
Returns true if this address is a V6 address containing a mapped V4 address.
Attributes
- Source
- Host.scala
Returns the number of leading ones in this address.
Returns the number of leading ones in this address. When this address is a netmask, the result can be used to create a CIDR.
Attributes
- Example
-
scala> val address = ipv4"192.168.1.25" scala> val netmask = ipv4"255.255.0.0" scala> (address / netmask.prefixBits): Cidr[Ipv4Address] res0: Cidr[Ipv4Address] = 192.168.1.25/16
- Source
- Host.scala
Converts this address to a network order byte array of either 4 or 16 bytes.
Converts this address to a network order byte array of either 4 or 16 bytes.
Attributes
- Source
- Host.scala
Returns the version of this address.
Inherited methods
Attributes
- Inherited from:
- Host
- Source
- Host.scala
Resolves this host to an ip address using the platform DNS resolver.
Resolves this host to an ip address using the platform DNS resolver.
If the host cannot be resolved, the effect fails with a com.comcast.ip4s.UnknownHostException
.
Attributes
- Inherited from:
- Host
- Source
- Host.scala
Resolves this host to all ip addresses known to the platform DNS resolver.
Resolves this host to all ip addresses known to the platform DNS resolver.
If the host cannot be resolved, an empty list is returned.
Attributes
- Inherited from:
- Host
- Source
- Host.scala
Resolves this host to an ip address using the platform DNS resolver.
Resolves this host to an ip address using the platform DNS resolver.
If the host cannot be resolved, a None
is returned.
Attributes
- Inherited from:
- Host
- Source
- Host.scala