abstract class AddressAttribute extends Attribute
The different attributes are distinguished by the attributeType of
Attribute
.
Address attributes indicate the mapped IP address and port. They consist of an eight bit address family, and a sixteen bit port, followed by a fixed length value representing the IP address.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |x x x x x x x x| Family | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The port is a network byte ordered representation of the mapped port. The address family is always 0x01, corresponding to IPv4. The first 8 bits of the MAPPED-ADDRESS are ignored, for the purposes of aligning parameters on natural boundaries. The IPv4 address is 32 bits.
Modifier and Type | Field and Description |
---|---|
protected TransportAddress |
address
The address represented by this message;
|
(package private) static byte |
ADDRESS_FAMILY_IPV4
Indicates that this attribute is transporting an IPv4 address
|
(package private) static byte |
ADDRESS_FAMILY_IPV6
Indicates that this attribute is transporting an IPv6 address
|
private static char |
DATA_LENGTH_FOR_IPV4
The length of the data contained by this attribute in the case of an
IPv4 address.
|
private static char |
DATA_LENGTH_FOR_IPV6
The length of the data contained by this attribute in the case of an
IPv6 address.
|
ALTERNATE_SERVER, attributeType, CHANGE_REQUEST, CHANGED_ADDRESS, CHANNEL_NUMBER, CONNECTION_ID, DATA, DESTINATION_ADDRESS, DONT_FRAGMENT, ERROR_CODE, EVEN_PORT, FINGERPRINT, HEADER_LENGTH, ICE_CONTROLLED, ICE_CONTROLLING, LIFETIME, MAGIC_COOKIE, MAPPED_ADDRESS, MESSAGE_INTEGRITY, NONCE, PASSWORD, PRIORITY, REALM, REFLECTED_FROM, REMOTE_ADDRESS, REQUESTED_ADDRESS_FAMILY, REQUESTED_TRANSPORT, RESERVATION_TOKEN, RESPONSE_ADDRESS, SOFTWARE, SOURCE_ADDRESS, UNKNOWN_ATTRIBUTES, UNKNOWN_OPTIONAL_ATTRIBUTE, USE_CANDIDATE, USERNAME, XOR_MAPPED_ADDRESS, XOR_ONLY, XOR_PEER_ADDRESS, XOR_RELAYED_ADDRESS
Constructor and Description |
---|
AddressAttribute(char attributeType)
Constructs an address attribute with the specified type.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
decodeAttributeBody(byte[] attributeValue,
char offset,
char length)
Sets this attribute's fields according to attributeValue array.
|
byte[] |
encode()
Returns a binary representation of this attribute.
|
boolean |
equals(Object obj)
Compares two STUN Attributes.
|
TransportAddress |
getAddress()
Returns the address encapsulated by this attribute.
|
byte[] |
getAddressBytes()
Returns the bytes of the address.
|
char |
getDataLength()
Returns the length of this attribute's body.
|
byte |
getFamily()
Returns the family that the this.address belongs to.
|
String |
getName()
Returns the human readable name of this attribute.
|
int |
getPort()
Returns the port associated with the address contained by the attribute.
|
private boolean |
isTypeValid(char type)
Verifies that type is a valid address attribute type.
|
void |
setAddress(TransportAddress address)
Sets address to be the address transported by this attribute.
|
protected void |
setAttributeType(char type)
Sets it as this attribute's type.
|
getAttributeType, getLocationInMessage, setLocationInMessage
static final byte ADDRESS_FAMILY_IPV4
static final byte ADDRESS_FAMILY_IPV6
protected TransportAddress address
private static final char DATA_LENGTH_FOR_IPV6
private static final char DATA_LENGTH_FOR_IPV4
AddressAttribute(char attributeType)
attributeType
- the type of the address attribute.private boolean isTypeValid(char type)
type
- the type to testprotected void setAttributeType(char type)
setAttributeType
in class Attribute
type
- the new type of the attribute.public String getName()
public boolean equals(Object obj)
public char getDataLength()
getDataLength
in class Attribute
public byte[] encode()
public void setAddress(TransportAddress address)
address
- that this attribute should encapsulate.public TransportAddress getAddress()
public byte[] getAddressBytes()
public byte getFamily()
public int getPort()
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
decodeAttributeBody
in class Attribute
attributeValue
- a binary array containing this attribute's field
values and NOT containing the attribute header.offset
- the position where attribute values begin (most often
offset is equal to the index of the first byte after
length)length
- the length of the binary array.StunException
- if attrubteValue contains invalid data.Copyright © 2018. All rights reserved.