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

Class for getting and setting the fields of an IPv6 Packet and its Ethernet header. More...

#include <IPv6Packet.h>

Public Member Functions

 IPv6Packet ()
 Constructor for new empty IPv6 packet.
 
void init ()
 Initialise default values for IPv6 packet and Ethernet frame header. More...
 
uint8_t * payload ()
 Get a pointer to the start of the IPv6 packet payload May be used to get or change the contents of the packet. More...
 
boolean isValid ()
 Check if the Ethernet and IPv6 headers are valid Also verifies the checksum of the packet. More...
 
void invalidate ()
 Marks the packet as being invalid, so that isValid() returns false.
 
MACAddressetherSource ()
 Get the Ethernet source MAC address of the packet. More...
 
void setEtherSource (MACAddress &address)
 Set the Ethernet source of the packet to a new address. More...
 
MACAddressetherDestination ()
 Get the Ethernet destination MAC address of the packet. More...
 
void setEtherDestination (MACAddress &address)
 Set the Ethernet destination of the packet to a new address. More...
 
uint16_t etherType () const
 Get the EtherType (Ethernet frame type) More...
 
uint8_t version () const
 Get the IP version number from the IPv6 header. More...
 
uint16_t length () const
 Get total length of this packet, including the Ethernet header, IPv6 header and payload. More...
 
uint16_t payloadLength () const
 Get length of this payload of the packet in bytes. More...
 
void setPayloadLength (uint16_t length)
 Set the length of this payload of the packet in bytes. More...
 
uint8_t protocol ()
 Get the protocol number for the packet For example IP6_PROTO_UDP = 17. More...
 
void setProtocol (uint8_t protocol)
 Set the protocol number for the packet For example IP6_PROTO_UDP = 17. More...
 
uint8_t hopLimit ()
 Get the hop limit for the packet This is the number of router hops a packet is allowed before being discarded. More...
 
void setHopLimit (uint8_t hopLimit)
 Set the hop limit for the packet This is the number of router hops a packet is allowed before being discarded. More...
 
IPv6Addresssource ()
 Get the IPv6 source address of the packet. More...
 
void setSource (IPv6Address &address)
 Set the IPv6 source of the packet to a new address. More...
 
IPv6Addressdestination ()
 Get the IPv6 destination address of the packet. More...
 
void setDestination (IPv6Address &address)
 Set the IPv6 destination of the packet to a new address. More...
 
uint16_t calculateChecksum ()
 Calculate the 16-bit checksum for the IPv6 packet. More...
 

Detailed Description

Class for getting and setting the fields of an IPv6 Packet and its Ethernet header.

Examples:
PacketPrinter.ino.

Member Function Documentation

◆ calculateChecksum()

uint16_t IPv6Packet::calculateChecksum ( )

Calculate the 16-bit checksum for the IPv6 packet.

Returns
the checksum of the packet

References chksum(), destination(), payload(), payloadLength(), protocol(), and source().

◆ destination()

IPv6Address & IPv6Packet::destination ( )

Get the IPv6 destination address of the packet.

Returns
the destination address of the packet
Examples:
PacketPrinter.ino.

◆ etherDestination()

MACAddress & IPv6Packet::etherDestination ( )

Get the Ethernet destination MAC address of the packet.

Returns
the destination address of the packet
Examples:
PacketPrinter.ino.

◆ etherSource()

MACAddress & IPv6Packet::etherSource ( )

Get the Ethernet source MAC address of the packet.

Returns
the source address of the packet
Examples:
PacketPrinter.ino.

◆ etherType()

uint16_t IPv6Packet::etherType ( ) const

Get the EtherType (Ethernet frame type)

Note
This should always be 86dd for IPv6
Returns
the 16-bit EtherType of the frame

◆ hopLimit()

uint8_t IPv6Packet::hopLimit ( )

Get the hop limit for the packet This is the number of router hops a packet is allowed before being discarded.

Returns
the hop limit for the packet
Examples:
PingClient.ino.

◆ init()

void IPv6Packet::init ( )

Initialise default values for IPv6 packet and Ethernet frame header.

Sets:

  • EtherType to IPv6
  • IP version to 6
  • Traffic Class to 0
  • Flow Label to 0
  • Hop Limit to default value

References ETHER_TYPE_IPV6, and IP6_DEFAULT_HOP_LIMIT.

◆ isValid()

boolean IPv6Packet::isValid ( )

Check if the Ethernet and IPv6 headers are valid Also verifies the checksum of the packet.

Returns
true if the packets fields are valid

References calculateChecksum(), ETHER_TYPE_IPV6, and version().

◆ length()

uint16_t IPv6Packet::length ( ) const

Get total length of this packet, including the Ethernet header, IPv6 header and payload.

Returns
the total length of the IPv6 packet in bytes

References ETHER_HEADER_LEN, IP6_HEADER_LEN, and payloadLength().

◆ payload()

uint8_t * IPv6Packet::payload ( )

Get a pointer to the start of the IPv6 packet payload May be used to get or change the contents of the packet.

Returns
a pointer to the memory containing the packet payload

◆ payloadLength()

uint16_t IPv6Packet::payloadLength ( ) const

Get length of this payload of the packet in bytes.

This should include everything after the IPv6 header.

Returns
the total length of the packet payload in bytes
Examples:
PacketPrinter.ino, and PingClient.ino.

◆ protocol()

uint8_t IPv6Packet::protocol ( )

Get the protocol number for the packet For example IP6_PROTO_UDP = 17.

See also
http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
Returns
the protocol number
Examples:
PacketPrinter.ino.

◆ setDestination()

void IPv6Packet::setDestination ( IPv6Address address)

Set the IPv6 destination of the packet to a new address.

Parameters
addressthe new destination address

◆ setEtherDestination()

void IPv6Packet::setEtherDestination ( MACAddress address)

Set the Ethernet destination of the packet to a new address.

Parameters
addressthe new destination address

◆ setEtherSource()

void IPv6Packet::setEtherSource ( MACAddress address)

Set the Ethernet source of the packet to a new address.

Parameters
addressthe new source address

◆ setHopLimit()

void IPv6Packet::setHopLimit ( uint8_t  hopLimit)

Set the hop limit for the packet This is the number of router hops a packet is allowed before being discarded.

Parameters
hopLimitthe new hop limit for the packet

References hopLimit().

◆ setPayloadLength()

void IPv6Packet::setPayloadLength ( uint16_t  length)

Set the length of this payload of the packet in bytes.

This should include everything after the IPv6 header.

Parameters
lengththe length of the payload in bytes

References length().

◆ setProtocol()

void IPv6Packet::setProtocol ( uint8_t  protocol)

Set the protocol number for the packet For example IP6_PROTO_UDP = 17.

See also
http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
Parameters
protocolthe new protocol number

References protocol().

◆ setSource()

void IPv6Packet::setSource ( IPv6Address address)

Set the IPv6 source of the packet to a new address.

Parameters
addressthe new source address

◆ source()

IPv6Address & IPv6Packet::source ( )

Get the IPv6 source address of the packet.

Returns
the source address of the packet
Examples:
PacketPrinter.ino, and PingClient.ino.

◆ version()

uint8_t IPv6Packet::version ( ) const

Get the IP version number from the IPv6 header.

This should always return 6 for a valid packet.

Returns
the version number of the IPv6 header