FreeSWITCH API Documentation  1.7.0
Data Structures | Functions | Variables
switch_stun.c File Reference
#include <switch.h>
#include <switch_stun.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
+ Include dependency graph for switch_stun.c:

Go to the source code of this file.

Data Structures

struct  value_mapping
 

Functions

static void v6_xor (uint8_t *addr, const uint8_t *transaction_id)
 
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...
 
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_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_priority (switch_stun_packet_t *packet, uint32_t priority)
 
uint8_t switch_stun_packet_attribute_add_integrity (switch_stun_packet_t *packet, const char *pass)
 
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_username (switch_stun_packet_t *packet, char *username, uint16_t ulen)
 Add a username packet attribute. More...
 
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_password (switch_stun_packet_t *packet, char *password, uint16_t ulen)
 
char * switch_stun_host_lookup (const char *host, switch_memory_pool_t *pool)
 
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...
 
uint32_t switch_crc32_8bytes (const void *data, size_t length)
 

Variables

static const struct value_mapping PACKET_TYPES []
 
static const struct value_mapping ATTR_TYPES []
 
static const struct value_mapping ERROR_TYPES []
 
const uint32_t crc32Lookup [8][256]
 look-up table, already defined in line 18 More...
 

Function Documentation

static void v6_xor ( uint8_t *  addr,
const uint8_t *  transaction_id 
)
static

Definition at line 110 of file switch_stun.c.

Referenced by switch_stun_packet_attribute_add_xor_binded_address(), and switch_stun_packet_attribute_get_xor_mapped_address().

111 {
112  int i;
113 
114  addr[0] ^= 0x21;
115  addr[1] ^= 0x12;
116  addr[2] ^= 0xa4;
117  addr[3] ^= 0x42;
118 
119  for (i = 0; i < 12; i++) {
120  addr[i + 4] ^= transaction_id[i];
121  }
122 }

Variable Documentation

const struct value_mapping ATTR_TYPES[]
static

Definition at line 61 of file switch_stun.c.

Referenced by switch_stun_value_to_name().

const uint32_t crc32Lookup[8][256]

look-up table, already defined in line 18

Definition at line 849 of file switch_stun.c.

Referenced by switch_crc32_8bytes().

const struct value_mapping ERROR_TYPES[]
static
const struct value_mapping PACKET_TYPES[]
static
Initial value:
= {
{SWITCH_STUN_BINDING_REQUEST, "BINDING_REQUEST"},
{SWITCH_STUN_BINDING_RESPONSE, "BINDING_RESPONSE"},
{SWITCH_STUN_BINDING_ERROR_RESPONSE, "BINDING_ERROR_RESPONSE"},
{SWITCH_STUN_SHARED_SECRET_REQUEST, "SHARED_SECRET_REQUEST"},
{SWITCH_STUN_SHARED_SECRET_RESPONSE, "SHARED_SECRET_RESPONSE"},
{SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE, "SHARED_SECRET_ERROR_RESPONSE"},
{SWITCH_STUN_ALLOCATE_REQUEST, "ALLOCATE_REQUEST"},
{SWITCH_STUN_ALLOCATE_RESPONSE, "ALLOCATE_RESPONSE"},
{SWITCH_STUN_ALLOCATE_ERROR_RESPONSE, "ALLOCATE_ERROR_RESPONSE"},
{SWITCH_STUN_SEND_REQUEST, "SEND_REQUEST"},
{SWITCH_STUN_SEND_RESPONSE, "SEND_RESPONSE"},
{SWITCH_STUN_SEND_ERROR_RESPONSE, "SEND_ERROR_RESPONSE"},
{SWITCH_STUN_DATA_INDICATION, "DATA_INDICATION"},
{0, 0}
}

Definition at line 44 of file switch_stun.c.

Referenced by switch_stun_value_to_name().