EtherSia
A minimal IPv6 Ethernet library for Arduino.
Public Member Functions | List of all members
IPv6Address Class Reference

Class for the storage and manipulation of IPv6 addresses. More...

#include <IPv6Address.h>

Public Member Functions

 IPv6Address ()
 Constructor for a new / all-zero IPv6 address (::)
 
 IPv6Address (const uint8_t *address)
 Constructor from a 128 bit (16-byte) array of bytes. More...
 
 IPv6Address (const char *addrstr)
 Constructor from a human readable IPv6 address string. More...
 
 IPv6Address (const __FlashStringHelper *addrstr)
 Constructor from a human readable IPv6 address Flash string (use the F() macro) More...
 
boolean fromString (const char *addrstr)
 Set address to the a human readable IPv6 string The address string can contain double colon :: notation to save space. More...
 
boolean fromString (const __FlashStringHelper *addrstr)
 Set address to the a human readable IPv6 Flash string (use the F() macro) The address string can contain double colon :: notation to save space. More...
 
uint8_t type ()
 Get the IPv6 address type. More...
 
 operator uint8_t * ()
 Cast the IPv6 address to an array of octets.
 
boolean operator== (const IPv6Address &address) const
 Check if the address equals another IPv6 address. More...
 
boolean operator!= (const IPv6Address &address) const
 Check if the address is not equal to another IPv6 address. More...
 
void setLinkLocalPrefix ()
 Set the first two bytes to the link-local prefix (FE80:) Note this only sets the first 64-bits of the address. More...
 
void setLinkLocalAllNodes ()
 Set address to multicast address for all nodes on the local network segment (FF02::1)
 
boolean isLinkLocalAllNodes () const
 Check if multicast address for all nodes on the local network segment (FF02::1) More...
 
void setLinkLocalAllRouters ()
 Set address to multicast address for all routers on the local network segment (FF02::2)
 
boolean isLinkLocalAllRouters () const
 Check if multicast address for all routers on the local network segment (FF02::2) More...
 
void setEui64 (const MACAddress &macAddress)
 Set the last 64-bits of the IPv6 address to a EUI-64 based on a 48-bit MAC Address Note this only sets the last 64-bits of the address. More...
 
void setSolicitedNodeMulticastAddress (const IPv6Address &address)
 Set the address to a Solicited Node Multicast Address For example the multicast address for fe80::2aa:ff:fe28:9c5a would be ff02::1:ff28:9c5a. More...
 
boolean isSolicitedNodeMulticastAddress (const IPv6Address &address) const
 Check if address is a specific node multicast address. More...
 
void setZero ()
 Set the address to all-zeros (::)
 
boolean isMulticast () const
 Check if the address is a multicast address (starts FF) More...
 
boolean isLinkLocal () const
 Check if the address is a link-local address (starts FE80) More...
 
boolean isZero () const
 Check if the address is empty / all-zeros (::) More...
 
boolean inSameSubnet (const IPv6Address &address) const
 Returns true if two addresses are in the same subnet. More...
 
void print (Print &print=Serial) const
 Print a IPv6 address to a stream as a human readable string. More...
 
void println (Print &print=Serial) const
 Print a IPv6 address to a stream with line ending. More...
 

Detailed Description

Class for the storage and manipulation of IPv6 addresses.

Constructor & Destructor Documentation

◆ IPv6Address() [1/3]

IPv6Address::IPv6Address ( const uint8_t *  address)

Constructor from a 128 bit (16-byte) array of bytes.

Parameters
addressan array of bytes

◆ IPv6Address() [2/3]

IPv6Address::IPv6Address ( const char *  addrstr)

Constructor from a human readable IPv6 address string.

Parameters
addrstrthe address to parse

References fromString().

◆ IPv6Address() [3/3]

IPv6Address::IPv6Address ( const __FlashStringHelper *  addrstr)

Constructor from a human readable IPv6 address Flash string (use the F() macro)

Parameters
addrstrthe address to parse

References fromString().

Member Function Documentation

◆ fromString() [1/2]

boolean IPv6Address::fromString ( const char *  addrstr)

Set address to the a human readable IPv6 string The address string can contain double colon :: notation to save space.

Parameters
addrstran IPv6 address as a null-terminated string
Returns
true if the string was parsed successfully

References asciiToHex(), and MAX_IPV6_ADDRESS_STR_LEN.

◆ fromString() [2/2]

boolean IPv6Address::fromString ( const __FlashStringHelper *  addrstr)

Set address to the a human readable IPv6 Flash string (use the F() macro) The address string can contain double colon :: notation to save space.

Parameters
addrstran IPv6 address as a null-terminated string
Returns
true if the string was parsed successfully

References fromString().

◆ inSameSubnet()

boolean IPv6Address::inSameSubnet ( const IPv6Address address) const

Returns true if two addresses are in the same subnet.

Note
assumes that local subnet is /64 (which is an assumption elsewhere too)
Parameters
addressthe address to
Returns
true if the addresses are in the same subnet

◆ isLinkLocal()

boolean IPv6Address::isLinkLocal ( ) const

Check if the address is a link-local address (starts FE80)

Returns
true if the address is a link-local address

◆ isLinkLocalAllNodes()

boolean IPv6Address::isLinkLocalAllNodes ( ) const

Check if multicast address for all nodes on the local network segment (FF02::1)

Returns
true if address if for the Link Local all nodes address

References setLinkLocalAllNodes().

◆ isLinkLocalAllRouters()

boolean IPv6Address::isLinkLocalAllRouters ( ) const

Check if multicast address for all routers on the local network segment (FF02::2)

Returns
true if address if for the Link Local all routers address

References setLinkLocalAllRouters().

◆ isMulticast()

boolean IPv6Address::isMulticast ( ) const

Check if the address is a multicast address (starts FF)

Returns
true if the address is a multicast address

◆ isSolicitedNodeMulticastAddress()

boolean IPv6Address::isSolicitedNodeMulticastAddress ( const IPv6Address address) const

Check if address is a specific node multicast address.

For example the multicast address for fe80::2aa:ff:fe28:9c5a would be ff02::1:ff28:9c5a

Parameters
addressThe IPv6 unicast address to calculate the multicast address from
Returns
true if address if the specific node multicast address

References setSolicitedNodeMulticastAddress().

◆ isZero()

boolean IPv6Address::isZero ( ) const

Check if the address is empty / all-zeros (::)

Returns
true if the address is empty / all-zeros (::)

◆ operator!=()

boolean IPv6Address::operator!= ( const IPv6Address address) const

Check if the address is not equal to another IPv6 address.

Parameters
addressthe second address to compare to
Returns
true if the two addresses are the same

◆ operator==()

boolean IPv6Address::operator== ( const IPv6Address address) const

Check if the address equals another IPv6 address.

Parameters
addressthe second address to compare to
Returns
true if the two addresses are the same

◆ print()

void IPv6Address::print ( Print &  print = Serial) const

Print a IPv6 address to a stream as a human readable string.

Parameters
printThe stream to print to (defaults to Serial)
Examples:
PingClient.ino.

References printPaddedHex().

◆ println()

void IPv6Address::println ( Print &  print = Serial) const

Print a IPv6 address to a stream with line ending.

Parameters
printThe stream to print to (defaults to Serial)
Examples:
MiniHTTPServer.ino, Minimal.ino, NanodeUDPClient.ino, NanodeUDPServer.ino, PacketPrinter.ino, PingClient.ino, SNTPClient.ino, TFTPServer.ino, and WebToggler.ino.

References print().

◆ setEui64()

void IPv6Address::setEui64 ( const MACAddress macAddress)

Set the last 64-bits of the IPv6 address to a EUI-64 based on a 48-bit MAC Address Note this only sets the last 64-bits of the address.

The first 64-bits are left unmodified.

Parameters
macAddressThe MAC address

◆ setLinkLocalPrefix()

void IPv6Address::setLinkLocalPrefix ( )

Set the first two bytes to the link-local prefix (FE80:) Note this only sets the first 64-bits of the address.

The last 64-bits are left unmodified.

◆ setSolicitedNodeMulticastAddress()

void IPv6Address::setSolicitedNodeMulticastAddress ( const IPv6Address address)

Set the address to a Solicited Node Multicast Address For example the multicast address for fe80::2aa:ff:fe28:9c5a would be ff02::1:ff28:9c5a.

Parameters
addressThe IPv6 unicast address

References setZero().

◆ type()

uint8_t IPv6Address::type ( )

Get the IPv6 address type.

Returns
a value from the IPv6AddressType enumeration

References ADDRESS_TYPE_GLOBAL, ADDRESS_TYPE_LINK_LOCAL, ADDRESS_TYPE_MULTICAST, isLinkLocal(), and isMulticast().