FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Enumerations | Functions
switch_stun.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_stun_packet_header_t
 
struct  switch_stun_packet_attribute_t
 
struct  switch_stun_packet_t
 
struct  switch_stun_ip_t
 
struct  switch_stun_error_code_t
 

Macros

#define SWITCH_STUN_DEFAULT_PORT   3478
 
#define SWITCH_STUN_PACKET_MIN_LEN   20
 
#define SWITCH_STUN_ATTRIBUTE_MIN_LEN   8
 
#define STUN_MAGIC_COOKIE   0x2112A442
 
#define switch_stun_attribute_padded_length(attribute)   (int16_t)((attribute->length & 0x3) ? 0x4 + (attribute->length & ~0x3) : attribute->length)
 Obtain the padded length of an attribute's value. More...
 
#define switch_stun_attribute_padded_length_hbo(attribute)   (int16_t)((ntohs(attribute->length) & 0x3) ? 0x4 + (ntohs(attribute->length) & ~0x3) : ntohs(attribute->length))
 
#define switch_stun_packet_first_attribute(packet, attribute)   attribute = (switch_stun_packet_attribute_t *)(&packet->first_attribute);
 set a switch_stun_packet_attribute_t pointer to point at the first attribute in a packet More...
 
#define switch_stun_packet_next_attribute(attribute, end)   (attribute && (attribute = (switch_stun_packet_attribute_t *) (attribute->value + switch_stun_attribute_padded_length(attribute))) && ((void *)attribute < end) && attribute->type && (((switch_byte_t *)attribute + switch_stun_attribute_padded_length(attribute)) < (switch_byte_t *)end))
 Increment an attribute pointer to the next attribute in it's packet. More...
 
#define switch_stun_packet_next_attribute_hbo(attribute, end)   (attribute && (attribute = (switch_stun_packet_attribute_t *) (attribute->value + switch_stun_attribute_padded_length_hbo(attribute))) && ((void *)attribute < end) && attribute->type && (((switch_byte_t *)attribute + switch_stun_attribute_padded_length_hbo(attribute)) < (switch_byte_t *)end))
 
#define switch_stun_packet_length(packet)   ntohs(packet->header.length) + (sizeof(switch_stun_packet_header_t))
 Obtain the correct length in bytes of a stun packet. More...
 

Enumerations

enum  switch_stun_message_t {
  SWITCH_STUN_BINDING_REQUEST = 0x0001, SWITCH_STUN_BINDING_RESPONSE = 0x0101, SWITCH_STUN_BINDING_ERROR_RESPONSE = 0x0111, SWITCH_STUN_SHARED_SECRET_REQUEST = 0x0002,
  SWITCH_STUN_SHARED_SECRET_RESPONSE = 0x0102, SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112, SWITCH_STUN_ALLOCATE_REQUEST = 0x0003, SWITCH_STUN_ALLOCATE_RESPONSE = 0x0103,
  SWITCH_STUN_ALLOCATE_ERROR_RESPONSE = 0x0113, SWITCH_STUN_SEND_REQUEST = 0x0004, SWITCH_STUN_SEND_RESPONSE = 0x0104, SWITCH_STUN_SEND_ERROR_RESPONSE = 0x0114,
  SWITCH_STUN_DATA_INDICATION = 0x0115
}
 
enum  switch_stun_attribute_t {
  SWITCH_STUN_ATTR_MAPPED_ADDRESS = 0x0001, SWITCH_STUN_ATTR_RESPONSE_ADDRESS = 0x0002, SWITCH_STUN_ATTR_CHANGE_REQUEST = 0x0003, SWITCH_STUN_ATTR_SOURCE_ADDRESS = 0x0004,
  SWITCH_STUN_ATTR_CHANGED_ADDRESS = 0x0005, SWITCH_STUN_ATTR_USERNAME = 0x0006, SWITCH_STUN_ATTR_PASSWORD = 0x0007, SWITCH_STUN_ATTR_MESSAGE_INTEGRITY = 0x0008,
  SWITCH_STUN_ATTR_ERROR_CODE = 0x0009, SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES = 0x000a, SWITCH_STUN_ATTR_REFLECTED_FROM = 0x000b, SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES = 0x000c,
  SWITCH_STUN_ATTR_LIFETIME = 0x000d, SWITCH_STUN_ATTR_ALTERNATE_SERVER = 0x000e, SWITCH_STUN_ATTR_MAGIC_COOKIE = 0x000f, SWITCH_STUN_ATTR_BANDWIDTH = 0x0010,
  SWITCH_STUN_ATTR_DESTINATION_ADDRESS = 0x0011, SWITCH_STUN_ATTR_SOURCE_ADDRESS2 = 0x0012, SWITCH_STUN_ATTR_DATA = 0x0013, SWITCH_STUN_ATTR_OPTIONS = 0x8001,
  SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS = 0x0020, SWITCH_STUN_ATTR_PRIORITY = 0x0024, SWITCH_STUN_ATTR_USE_CAND = 0x0025, SWITCH_STUN_ATTR_PADDING = 0x0026,
  SWITCH_STUN_ATTR_RESP_PORT = 0x0027, SWITCH_STUN_ATTR_SOFTWARE = 0x8022, SWITCH_STUN_ATTR_ALT_SERVER = 0x8023, SWITCH_STUN_ATTR_FINGERPRINT = 0x8028,
  SWITCH_STUN_ATTR_CONTROLLED = 0x8029, SWITCH_STUN_ATTR_CONTROLLING = 0x802a, SWITCH_STUN_ATTR_RESP_ORIGIN = 0x802b, SWITCH_STUN_ATTR_OTHER_ADDR = 0x802c
}
 
enum  switch_stun_error_t {
  SWITCH_STUN_ERROR_BAD_REQUEST = 400, SWITCH_STUN_ERROR_UNAUTHORIZED = 401, SWITCH_STUN_ERROR_UNKNOWN_ATTRIBUTE = 420, SWITCH_STUN_ERROR_STALE_CREDENTIALS = 430,
  SWITCH_STUN_ERROR_INTEGRITY_CHECK_FAILURE = 431, SWITCH_STUN_ERROR_MISSING_USERNAME = 432, SWITCH_STUN_ERROR_USE_TLS = 433, SWITCH_STUN_ERROR_SERVER_ERROR = 500,
  SWITCH_STUN_ERROR_GLOBAL_FAILURE = 600
}
 
enum  switch_stun_type_t { SWITCH_STUN_TYPE_PACKET_TYPE, SWITCH_STUN_TYPE_ATTRIBUTE, SWITCH_STUN_TYPE_ERROR }
 

Functions

void switch_stun_random_string (char *buf, uint16_t len, char *set)
 Writes random characters into a buffer. More...
 
switch_stun_packet_tswitch_stun_packet_parse (uint8_t *buf, uint32_t len)
 Prepare a raw packet for parsing. More...
 
const char * switch_stun_value_to_name (int32_t type, uint32_t value)
 Obtain a printable string form of a given value. More...
 
char * switch_stun_host_lookup (const char *host, switch_memory_pool_t *pool)
 
uint8_t switch_stun_packet_attribute_get_mapped_address (switch_stun_packet_attribute_t *attribute, char *ipstr, switch_size_t iplen, uint16_t *port)
 Extract a mapped address (IP:PORT) from a packet attribute. More...
 
uint8_t switch_stun_packet_attribute_get_xor_mapped_address (switch_stun_packet_attribute_t *attribute, switch_stun_packet_header_t *header, char *ipstr, switch_size_t iplen, uint16_t *port)
 
char * switch_stun_packet_attribute_get_username (switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
 Extract a username from a packet attribute. More...
 
switch_stun_packet_tswitch_stun_packet_build_header (switch_stun_message_t type, char *id, uint8_t *buf)
 Prepare a new outbound packet of a certian type and id. More...
 
uint8_t switch_stun_packet_attribute_add_username (switch_stun_packet_t *packet, char *username, uint16_t ulen)
 Add a username packet attribute. More...
 
uint8_t switch_stun_packet_attribute_add_password (switch_stun_packet_t *packet, char *password, uint16_t ulen)
 
uint8_t switch_stun_packet_attribute_add_software (switch_stun_packet_t *packet, char *software, uint16_t ulen)
 
uint8_t switch_stun_packet_attribute_add_binded_address (switch_stun_packet_t *packet, char *ipstr, uint16_t port, int family)
 Add a binded address packet attribute. More...
 
uint8_t switch_stun_packet_attribute_add_xor_binded_address (switch_stun_packet_t *packet, char *ipstr, uint16_t port, int family)
 
uint8_t switch_stun_packet_attribute_add_integrity (switch_stun_packet_t *packet, const char *pass)
 
uint32_t switch_crc32_8bytes (const void *data, size_t length)
 
uint8_t switch_stun_packet_attribute_add_fingerprint (switch_stun_packet_t *packet)
 
uint8_t switch_stun_packet_attribute_add_use_candidate (switch_stun_packet_t *packet)
 
uint8_t switch_stun_packet_attribute_add_controlling (switch_stun_packet_t *packet)
 
uint8_t switch_stun_packet_attribute_add_controlled (switch_stun_packet_t *packet)
 
uint8_t switch_stun_packet_attribute_add_priority (switch_stun_packet_t *packet, uint32_t priority)
 
switch_status_t switch_stun_lookup (char **ip, switch_port_t *port, char *stunip, switch_port_t stunport, char **err, switch_memory_pool_t *pool)
 Perform a stun lookup. More...