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

Class for the storage and manipulation of 48-bit Ethernet addresses. More...

#include <MACAddress.h>

Public Member Functions

 MACAddress ()
 Constructor for a new / all-zero MAC address (00:00:00:00:00:00)
 
 MACAddress (const char *macstr)
 Constructor for MAC address from a string. More...
 
 MACAddress (const __FlashStringHelper *macstr)
 Constructor for MAC address from a Flash string (use the F() macro) More...
 
 MACAddress (const byte macaddr[6])
 Constructor for MAC address from an array of 6 bytes. More...
 
 MACAddress (uint8_t one, uint8_t two, uint8_t three, uint8_t four, uint8_t five, uint8_t six)
 Constructor for MAC address from 6-octets. More...
 
boolean fromString (const char *macstr)
 Parse a human readable MAC address into a MACAddress object. More...
 
boolean fromString (const __FlashStringHelper *macstr)
 Parse a flash string MAC address into a MACAddress object (use the F() macro) More...
 
 operator uint8_t * ()
 Cast the MAC address to an array of octets.
 
boolean operator== (const MACAddress &address) const
 Check if the address equals another MAC address. More...
 
boolean operator!= (const MACAddress &address) const
 Check if the address is not equal to another MAC address. More...
 
void setIPv6Multicast (const uint8_t *address)
 Calculate the multicast MAC address for an IPv6 address. More...
 
boolean isIPv6Multicast ()
 Check if the MAC address is an IPv6 multicast address. More...
 
uint8_t operator[] (int index) const
 Get an individual octet from the MAC address. More...
 
void print (Print &print=Serial) const
 Print a MAC address to a stream as a human readable string. More...
 
void println (Print &print=Serial) const
 Print a MAC address to a stream with line ending. More...
 

Detailed Description

Class for the storage and manipulation of 48-bit Ethernet addresses.

Examples:
MiniHTTPServer.ino, Minimal.ino, MinimalStatic.ino, NanodeUDPClient.ino, NanodeUDPServer.ino, PacketPrinter.ino, PingClient.ino, SNTPClient.ino, Syslog.ino, TFTPServer.ino, and WebToggler.ino.

Constructor & Destructor Documentation

◆ MACAddress() [1/4]

MACAddress::MACAddress ( const char *  macstr)

Constructor for MAC address from a string.

Parameters
macstra human readable string containing a 17 character MAC address

References fromString().

◆ MACAddress() [2/4]

MACAddress::MACAddress ( const __FlashStringHelper *  macstr)

Constructor for MAC address from a Flash string (use the F() macro)

Parameters
macstra human readable string containing a 17 character MAC address

References fromString().

◆ MACAddress() [3/4]

MACAddress::MACAddress ( const byte  macaddr[6])

Constructor for MAC address from an array of 6 bytes.

Parameters
macaddra 48-bit (6 byte) MAC address

◆ MACAddress() [4/4]

MACAddress::MACAddress ( uint8_t  one,
uint8_t  two,
uint8_t  three,
uint8_t  four,
uint8_t  five,
uint8_t  six 
)

Constructor for MAC address from 6-octets.

Parameters
oneThe first octet of the address
twoThe second octet of the address
threeThe third octet of the address
fourThe fourth octet of the address
fiveThe fifth octet of the address
sixThe sixth octet of the address

Member Function Documentation

◆ fromString() [1/2]

boolean MACAddress::fromString ( const char *  macstr)

Parse a human readable MAC address into a MACAddress object.

Parameters
macstra human readable string containing a 17 character MAC address
Returns
true if successful, false if parsing failed

References asciiToHex().

◆ fromString() [2/2]

boolean MACAddress::fromString ( const __FlashStringHelper *  macstr)

Parse a flash string MAC address into a MACAddress object (use the F() macro)

Parameters
macstra human readable string containing a 17 character MAC address
Returns
true if successful, false if parsing failed

References fromString().

◆ isIPv6Multicast()

boolean MACAddress::isIPv6Multicast ( )

Check if the MAC address is an IPv6 multicast address.

An IPv6 multicast MAC looks like the pattern: 33:33:xx:xx:xx:xx

Returns
true if it is an IPv6 multicast address

◆ operator!=()

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

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

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

◆ operator==()

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

Check if the address equals another MAC address.

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

◆ operator[]()

uint8_t MACAddress::operator[] ( int  index) const

Get an individual octet from the MAC address.

Indexed from 0 to 5.

Parameters
indexThe byte number from the address to get
Returns
The requested byte from the address

◆ print()

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

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

Parameters
printThe stream to print to (defaults to Serial)

References printPaddedHex().

◆ println()

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

Print a MAC address to a stream with line ending.

Parameters
printThe stream to print to (defaults to Serial)
Examples:
NanodeUDPClient.ino, NanodeUDPServer.ino, and PacketPrinter.ino.

References print().

◆ setIPv6Multicast()

void MACAddress::setIPv6Multicast ( const uint8_t *  address)

Calculate the multicast MAC address for an IPv6 address.

Parameters
addressAn IPv6 address as an array of 16-bytes