RFC 5389 STUN October 2008
The message type field is decomposed further into the following
structure:
0 1
2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+-+-+-+-+-+-+-+-+-+-+-+-+
|M |M |M|M|M|C|M|M|M|C|M|M|M|M|
|11|10|9|8|7|1|6|5|4|0|3|2|1|0|
+--+--+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 3: Format of STUN Message Type Field
Here the bits in the message type field are shown as most significant
(M11) through least significant (M0). M11 through M0 represent a 12-
bit encoding of the method. C1 and C0 represent a 2-bit encoding of
the class. A class of 0b00 is a request, a class of 0b01 is an
indication, a class of 0b10 is a success response, and a class of
0b11 is an error response. This specification defines a single
method, Binding. The method and class are orthogonal, so that for
each method, a request, success response, error response, and
indication are possible for that method. Extensions defining new
methods MUST indicate which classes are permitted for that method.
For example, a Binding request has class=0b00 (request) and
method=0b000000000001 (Binding) and is encoded into the first 16 bits
as 0x0001. A Binding response has class=0b10 (success response) and
method=0b000000000001, and is encoded into the first 16 bits as
0x0101.
Note: This unfortunate encoding is due to assignment of values in
[RFC3489] that did not consider encoding Indications, Success, and
Errors using bit fields.
The magic cookie field MUST contain the fixed value 0x2112A442 in
network byte order. In RFC 3489 [RFC3489], this field was part of
the transaction ID; placing the magic cookie in this location allows
a server to detect if the client will understand certain attributes
that were added in this revised specification. In addition, it aids
in distinguishing STUN packets from packets of other protocols when
STUN is multiplexed with those other protocols on the same port.
The transaction ID is a 96-bit identifier, used to uniquely identify
STUN transactions. For request/response transactions, the
transaction ID is chosen by the STUN client for the request and
echoed by the server in the response. For indications, it is chosen
by the agent sending the indication. It primarily serves to
correlate requests with responses, though it also plays a small role
Rosenberg, et al. Standards Track [Page 11]