GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions
nat_stun.h File Reference

Message types for STUN server resolution. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stun_trans_id
 
struct  stun_header
 
struct  stun_attr
 
struct  stun_addr
 The format normally used for addresses carried by STUN messages. More...
 

Macros

#define STUN_IGNORE   (0)
 
#define STUN_ACCEPT   (1)
 
#define STUN_MAGIC_COOKIE   0x2112A442
 

Enumerations

enum  StunClasses {
  INVALID_CLASS = 0, STUN_REQUEST = 0x0000, STUN_INDICATION = 0x0001, STUN_RESPONSE = 0x0002,
  STUN_ERROR_RESPONSE = 0x0003
}
 STUN message classes. More...
 
enum  StunMethods {
  INVALID_METHOD = 0, STUN_BINDING = 0x0001, STUN_SHARED_SECRET = 0x0002, STUN_ALLOCATE = 0x0003,
  STUN_REFRESH = 0x0004, STUN_SEND = 0x0006, STUN_DATA = 0x0007, STUN_CREATE_PERMISSION = 0x0008,
  STUN_CHANNEL_BIND = 0x0009
}
 
enum  StunAttributes {
  STUN_MAPPED_ADDRESS = 0x0001, STUN_RESPONSE_ADDRESS = 0x0002, STUN_CHANGE_ADDRESS = 0x0003, STUN_SOURCE_ADDRESS = 0x0004,
  STUN_CHANGED_ADDRESS = 0x0005, STUN_USERNAME = 0x0006, STUN_PASSWORD = 0x0007, STUN_MESSAGE_INTEGRITY = 0x0008,
  STUN_ERROR_CODE = 0x0009, STUN_UNKNOWN_ATTRIBUTES = 0x000a, STUN_REFLECTED_FROM = 0x000b, STUN_REALM = 0x0014,
  STUN_NONCE = 0x0015, STUN_XOR_MAPPED_ADDRESS = 0x0020, STUN_MS_VERSION = 0x8008, STUN_MS_XOR_MAPPED_ADDRESS = 0x8020,
  STUN_SOFTWARE = 0x8022, STUN_ALTERNATE_SERVER = 0x8023, STUN_FINGERPRINT = 0x8028
}
 Basic attribute types in stun messages. More...
 

Functions

static enum StunClasses decode_class (int msg)
 Convert a message to a StunClass. More...
 
static enum StunMethods decode_method (int msg)
 Convert a message to a StunMethod. More...
 
static const char * stun_msg2str (int msg)
 Print a class and method from a STUN message. More...
 
static const char * stun_attr2str (enum StunAttributes msg)
 Print attribute name. More...
 

Detailed Description

Message types for STUN server resolution.

Testcase for STUN library

Author
Bruno Souza Cabral Mark Spencer (Original code borrowed from Asterisk)
Christian Grothoff

Definition in file nat_stun.h.

Macro Definition Documentation

◆ STUN_IGNORE

#define STUN_IGNORE   (0)

Definition at line 31 of file nat_stun.h.

◆ STUN_ACCEPT

#define STUN_ACCEPT   (1)

Definition at line 32 of file nat_stun.h.

◆ STUN_MAGIC_COOKIE

#define STUN_MAGIC_COOKIE   0x2112A442

Enumeration Type Documentation

◆ StunClasses

STUN message classes.

Enumerator
INVALID_CLASS 
STUN_REQUEST 
STUN_INDICATION 
STUN_RESPONSE 
STUN_ERROR_RESPONSE 

Definition at line 84 of file nat_stun.h.

84  {
85  INVALID_CLASS = 0,
86  STUN_REQUEST = 0x0000,
87  STUN_INDICATION = 0x0001,
88  STUN_RESPONSE = 0x0002,
89  STUN_ERROR_RESPONSE = 0x0003
90 };

◆ StunMethods

Enumerator
INVALID_METHOD 
STUN_BINDING 
STUN_SHARED_SECRET 
STUN_ALLOCATE 
STUN_REFRESH 
STUN_SEND 
STUN_DATA 
STUN_CREATE_PERMISSION 
STUN_CHANNEL_BIND 

Definition at line 92 of file nat_stun.h.

92  {
93  INVALID_METHOD = 0,
94  STUN_BINDING = 0x0001,
95  STUN_SHARED_SECRET = 0x0002,
96  STUN_ALLOCATE = 0x0003,
97  STUN_REFRESH = 0x0004,
98  STUN_SEND = 0x0006,
99  STUN_DATA = 0x0007,
100  STUN_CREATE_PERMISSION = 0x0008,
101  STUN_CHANNEL_BIND = 0x0009
102 };

◆ StunAttributes

Basic attribute types in stun messages.

Messages can also contain custom attributes (codes above 0x7fff)

Enumerator
STUN_MAPPED_ADDRESS 
STUN_RESPONSE_ADDRESS 
STUN_CHANGE_ADDRESS 
STUN_SOURCE_ADDRESS 
STUN_CHANGED_ADDRESS 
STUN_USERNAME 
STUN_PASSWORD 
STUN_MESSAGE_INTEGRITY 
STUN_ERROR_CODE 
STUN_UNKNOWN_ATTRIBUTES 
STUN_REFLECTED_FROM 
STUN_REALM 
STUN_NONCE 
STUN_XOR_MAPPED_ADDRESS 
STUN_MS_VERSION 
STUN_MS_XOR_MAPPED_ADDRESS 
STUN_SOFTWARE 
STUN_ALTERNATE_SERVER 
STUN_FINGERPRINT 

Definition at line 109 of file nat_stun.h.

109  {
110  STUN_MAPPED_ADDRESS = 0x0001,
111  STUN_RESPONSE_ADDRESS = 0x0002,
112  STUN_CHANGE_ADDRESS = 0x0003,
113  STUN_SOURCE_ADDRESS = 0x0004,
114  STUN_CHANGED_ADDRESS = 0x0005,
115  STUN_USERNAME = 0x0006,
116  STUN_PASSWORD = 0x0007,
117  STUN_MESSAGE_INTEGRITY = 0x0008,
118  STUN_ERROR_CODE = 0x0009,
119  STUN_UNKNOWN_ATTRIBUTES = 0x000a,
120  STUN_REFLECTED_FROM = 0x000b,
121  STUN_REALM = 0x0014,
122  STUN_NONCE = 0x0015,
123  STUN_XOR_MAPPED_ADDRESS = 0x0020,
124  STUN_MS_VERSION = 0x8008,
126  STUN_SOFTWARE = 0x8022,
127  STUN_ALTERNATE_SERVER = 0x8023,
128  STUN_FINGERPRINT = 0x8028
129 };

Function Documentation

◆ decode_class()

static enum StunClasses decode_class ( int  msg)
static

Convert a message to a StunClass.

Parameters
msgthe received message
Returns
the converted StunClass

Definition at line 139 of file nat_stun.h.

Referenced by stun_msg2str().

140 {
141  /* Sorry for the magic, but this maps the class according to rfc5245 */
142  return (enum StunClasses) ((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7);
143 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
StunClasses
STUN message classes.
Definition: nat_stun.h:84
Here is the caller graph for this function:

◆ decode_method()

static enum StunMethods decode_method ( int  msg)
static

Convert a message to a StunMethod.

Parameters
msgthe received message
Returns
the converted StunMethod

Definition at line 153 of file nat_stun.h.

References GNUNET_UNUSED.

Referenced by stun_msg2str().

154 {
155  return (enum StunMethods) (msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2);
156 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
StunMethods
Definition: nat_stun.h:92
Here is the caller graph for this function:

◆ stun_msg2str()

static const char* stun_msg2str ( int  msg)
static

Print a class and method from a STUN message.

Parameters
msg
Returns
string with the message class and method

Definition at line 167 of file nat_stun.h.

References decode_class(), decode_method(), GNUNET_snprintf(), GNUNET_UNUSED, INVALID_CLASS, INVALID_METHOD, name, result, STUN_BINDING, STUN_ERROR_RESPONSE, STUN_INDICATION, STUN_REQUEST, STUN_RESPONSE, and value.

Referenced by GNUNET_NAT_stun_handle_packet_().

168 {
169  static const struct {
170  enum StunClasses value;
171  const char *name;
172  } classes[] = {
173  { STUN_REQUEST, "Request" },
174  { STUN_INDICATION, "Indication" },
175  { STUN_RESPONSE, "Response" },
176  { STUN_ERROR_RESPONSE, "Error Response" },
177  { INVALID_CLASS, NULL }
178  };
179  static const struct {
180  enum StunMethods value;
181  const char *name;
182  } methods[] = {
183  { STUN_BINDING, "Binding" },
184  { INVALID_METHOD, NULL }
185  };
186  static char result[64];
187  const char *msg_class = NULL;
188  const char *method = NULL;
189  enum StunClasses cvalue;
190  enum StunMethods mvalue;
191 
192  cvalue = decode_class (msg);
193  for (unsigned int i = 0; classes[i].name; i++)
194  if (classes[i].value == cvalue)
195  {
196  msg_class = classes[i].name;
197  break;
198  }
199  mvalue = decode_method (msg);
200  for (unsigned int i = 0; methods[i].name; i++)
201  if (methods[i].value == mvalue)
202  {
203  method = methods[i].name;
204  break;
205  }
206  GNUNET_snprintf (result,
207  sizeof(result),
208  "%s %s",
209  method ? : "Unknown Method",
210  msg_class ? : "Unknown Class Message");
211  return result;
212 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static enum StunClasses decode_class(int msg)
Convert a message to a StunClass.
Definition: nat_stun.h:139
StunMethods
Definition: nat_stun.h:92
static char * value
Value of the record to add/remove.
static int result
Global testing status.
const char * name
StunClasses
STUN message classes.
Definition: nat_stun.h:84
static enum StunMethods decode_method(int msg)
Convert a message to a StunMethod.
Definition: nat_stun.h:153
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stun_attr2str()

static const char* stun_attr2str ( enum StunAttributes  msg)
static

Print attribute name.

Parameters
msgwith a attribute type
Returns
string with the attribute name

Definition at line 223 of file nat_stun.h.

References name, STUN_ALTERNATE_SERVER, STUN_CHANGE_ADDRESS, STUN_CHANGED_ADDRESS, STUN_ERROR_CODE, STUN_FINGERPRINT, STUN_MAPPED_ADDRESS, STUN_MESSAGE_INTEGRITY, STUN_MS_VERSION, STUN_MS_XOR_MAPPED_ADDRESS, STUN_NONCE, STUN_PASSWORD, STUN_REALM, STUN_REFLECTED_FROM, STUN_RESPONSE_ADDRESS, STUN_SOFTWARE, STUN_SOURCE_ADDRESS, STUN_UNKNOWN_ATTRIBUTES, STUN_USERNAME, STUN_XOR_MAPPED_ADDRESS, and value.

224 {
225  static const struct {
226  enum StunAttributes value;
227  const char *name;
228  } attrs[] = {
229  { STUN_MAPPED_ADDRESS, "Mapped Address" },
230  { STUN_RESPONSE_ADDRESS, "Response Address" },
231  { STUN_CHANGE_ADDRESS, "Change Address" },
232  { STUN_SOURCE_ADDRESS, "Source Address" },
233  { STUN_CHANGED_ADDRESS, "Changed Address" },
234  { STUN_USERNAME, "Username" },
235  { STUN_PASSWORD, "Password" },
236  { STUN_MESSAGE_INTEGRITY, "Message Integrity" },
237  { STUN_ERROR_CODE, "Error Code" },
238  { STUN_UNKNOWN_ATTRIBUTES, "Unknown Attributes" },
239  { STUN_REFLECTED_FROM, "Reflected From" },
240  { STUN_REALM, "Realm" },
241  { STUN_NONCE, "Nonce" },
242  { STUN_XOR_MAPPED_ADDRESS, "XOR Mapped Address" },
243  { STUN_MS_VERSION, "MS Version" },
244  { STUN_MS_XOR_MAPPED_ADDRESS, "MS XOR Mapped Address" },
245  { STUN_SOFTWARE, "Software" },
246  { STUN_ALTERNATE_SERVER, "Alternate Server" },
247  { STUN_FINGERPRINT, "Fingerprint" },
248  { 0, NULL }
249  };
250 
251  for (unsigned int i = 0; attrs[i].name; i++)
252  if (attrs[i].value == msg)
253  return attrs[i].name;
254  return "Unknown Attribute";
255 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char * value
Value of the record to add/remove.
StunAttributes
Basic attribute types in stun messages.
Definition: nat_stun.h:109
const char * name