STUN module (rfc5389)

Attribute

The virtual base class for all STUN/TURN attributes.

Attribute

#include <icy/stun/attributes.h>

Subclassed by: AddressAttribute, ErrorCode, FlagAttribute, MessageIntegrity, StringAttribute, UInt16ListAttribute, UInt32Attribute, UInt64Attribute, UInt8Attribute

The virtual base class for all STUN/TURN attributes.

Public Methods

ReturnNameDescription
std::unique_ptr< Attribute >cloneReturns a deep copy of this attribute.
voidreadReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite constWrites the body (not the type or size) to the given buffer.
uint16_ttype const#### Returns
uint16_tsize const#### Returns
uint16_tpaddingBytes const inline#### Returns
uint16_tpaddedBytes const inline#### Returns
voidconsumePadding constAdvances the reader past any 4-byte alignment padding that follows this attribute's body.
voidwritePadding constWrites zero-fill padding bytes to align this attribute to a 4-byte boundary.
std::stringtypeString#### Returns

clone

std::unique_ptr< Attribute > clone()

Returns a deep copy of this attribute.


read

void read(BitReader & reader)

Reads the body (not the type or size) for this type of attribute from the given buffer.

Parameters

  • reader Source bit reader positioned at the attribute body.

write

const

void write(BitWriter & writer) const

Writes the body (not the type or size) to the given buffer.

Parameters

  • writer Destination bit writer.

type

const

uint16_t type() const

Returns

The wire type code for this attribute.


size

const

uint16_t size() const

Returns

The body length of this attribute in bytes (before padding).


paddingBytes

const inline

inline uint16_t paddingBytes() const

Returns

The 4-byte alignment padding required for this attribute body.


paddedBytes

const inline

inline uint16_t paddedBytes() const

Returns

The body length including 4-byte alignment padding.


consumePadding

const

void consumePadding(BitReader & reader) const

Advances the reader past any 4-byte alignment padding that follows this attribute's body.

Parameters

  • reader Reader to advance.

writePadding

const

void writePadding(BitWriter & writer) const

Writes zero-fill padding bytes to align this attribute to a 4-byte boundary.

Parameters

  • writer Writer to append padding to.

typeString

std::string typeString()

Returns

Human-readable name for this attribute's type.

Public Static Attributes

ReturnNameDescription
constexpr uint16_tTypeID static

TypeID

static

constexpr uint16_t TypeID = 0

Public Static Methods

ReturnNameDescription
std::unique_ptr< Attribute >create staticCreates an attribute of the given wire type and body size. Returns nullptr if the type is unknown or the size is invalid.
constexpr uint16_tpaddingBytes static inlineReturns the 4-byte alignment padding required for a body of size bytes.
constexpr uint16_tpaddedBytes static inlineReturns the body length including 4-byte alignment padding.
std::stringtypeString static#### Parameters

create

static

static std::unique_ptr< Attribute > create(uint16_t type, uint16_t size)

Creates an attribute of the given wire type and body size. Returns nullptr if the type is unknown or the size is invalid.

Parameters

  • type Wire type code (one of Attribute::Type).

  • size Body length in bytes as read from the wire header.

Returns

Owning pointer to the new attribute, or nullptr on failure.


paddingBytes

static inline

static inline constexpr uint16_t paddingBytes(uint16_t size)

Returns the 4-byte alignment padding required for a body of size bytes.


paddedBytes

static inline

static inline constexpr uint16_t paddedBytes(uint16_t size)

Returns the body length including 4-byte alignment padding.


typeString

static

static std::string typeString(uint16_t type)

Parameters

  • type Wire type code.

Returns

Human-readable name for the given type code.

Protected Attributes

ReturnNameDescription
uint16_t_type
uint16_t_size

_type

uint16_t _type

_size

uint16_t _size

Protected Methods

ReturnNameDescription
Attribute#### Parameters
voidsetLengthUpdates the stored body length.

Attribute

Attribute(uint16_t type, uint16_t size)

Parameters

  • type Wire type code for this attribute.

  • size Initial body length in bytes.


setLength

void setLength(uint16_t size)

Updates the stored body length.

Parameters

  • size New body length in bytes.

Public Types

NameDescription
Type

Type

enum Type
ValueDescription
NotExist
MappedAddress
ResponseAddress
ChangeRequest
SourceAddress
ChangedAddress
Username
Password
MessageIntegrity
ErrorCode
Bandwidth
DestinationAddress
UnknownAttributes
ReflectedFrom
MagicCookie
Realm
Nonce
XorMappedAddress
Software
Options
AlternateServer
Fingerprint
ChannelNumberTURN.
Lifetime
XorPeerAddress
Data
XorRelayedAddress
EventPort
RequestedTransport
DontFragment
ReservationToken0x0021: Reserved (was TIMER-VAL)
ConnectionIDTURN TCP.
ICEControlledICE.
ICEControlling
ICEPriority
ICEUseCandidate