RTS API Documentation
1.10.11
|
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... | |
#define STUN_MAGIC_COOKIE 0x2112A442 |
Definition at line 60 of file switch_stun.h.
Referenced by switch_stun_packet_attribute_add_binded_address(), switch_stun_packet_attribute_add_xor_binded_address(), and switch_stun_packet_build_header().
#define SWITCH_STUN_ATTRIBUTE_MIN_LEN 8 |
Definition at line 43 of file switch_stun.h.
Referenced by switch_stun_packet_parse().
#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.
attribute | the attribute |
Definition at line 277 of file switch_stun.h.
Referenced by handle_ice(), switch_stun_lookup(), and switch_stun_packet_parse().
#define switch_stun_attribute_padded_length_hbo | ( | attribute | ) | (int16_t)((ntohs(attribute->length) & 0x3) ? 0x4 + (ntohs(attribute->length) & ~0x3) : ntohs(attribute->length)) |
Definition at line 278 of file switch_stun.h.
#define SWITCH_STUN_DEFAULT_PORT 3478 |
Definition at line 41 of file switch_stun.h.
Referenced by switch_core_media_ext_address_lookup(), and switch_stun_ip_lookup().
#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
packet | the packet in question |
attribute | the pointer to set up |
Definition at line 286 of file switch_stun.h.
Referenced by handle_ice(), switch_stun_lookup(), and switch_stun_packet_parse().
#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.
packet | the packet in question |
Definition at line 304 of file switch_stun.h.
Referenced by handle_ice(), ice_out(), and switch_stun_lookup().
#define SWITCH_STUN_PACKET_MIN_LEN 20 |
Definition at line 42 of file switch_stun.h.
Referenced by switch_stun_packet_parse().
#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.
attribute | the pointer to increment |
end | pointer to the end of the buffer |
Definition at line 295 of file switch_stun.h.
Referenced by handle_ice(), and switch_stun_lookup().
#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)) |
Definition at line 297 of file switch_stun.h.
Definition at line 62 of file switch_stun.h.
enum switch_stun_error_t |
Definition at line 101 of file switch_stun.h.
Definition at line 44 of file switch_stun.h.
enum switch_stun_type_t |
Enumerator | |
---|---|
SWITCH_STUN_TYPE_PACKET_TYPE | |
SWITCH_STUN_TYPE_ATTRIBUTE | |
SWITCH_STUN_TYPE_ERROR |
Definition at line 113 of file switch_stun.h.
uint32_t switch_crc32_8bytes | ( | const void * | data, |
size_t | length | ||
) |
Definition at line 1228 of file switch_stun.c.
References crc32Lookup.
Referenced by switch_stun_packet_attribute_add_fingerprint().
char* switch_stun_host_lookup | ( | const char * | host, |
switch_memory_pool_t * | pool | ||
) |
Definition at line 695 of file switch_stun.c.
References buf, switch_core_strdup, switch_get_addr(), switch_sockaddr_info_get(), switch_str_nil, and SWITCH_UNSPEC.
Referenced by switch_core_media_ext_address_lookup(), and switch_stun_ip_lookup().
switch_status_t switch_stun_ip_lookup | ( | char ** | external_ip, |
const char * | sourceip, | ||
switch_memory_pool_t * | external_pool | ||
) |
Perform a stun ip lookup.
external_ip | replaced with stun results |
sourceip | stun:, host: or an ip |
external_pool | the memory pool to use |
Definition at line 863 of file switch_stun.c.
References ip, switch_assert, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, switch_core_new_memory_pool, switch_core_strdup, switch_find_local_ip(), SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_STUN_DEFAULT_PORT, switch_stun_host_lookup(), switch_stun_lookup(), and zstr.
Referenced by preprocess_stun_set().
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.
ip | the local ip to use (replaced with stun results) |
port | the local port to use (replaced with stun results) |
stunip | the ip of the stun server |
stunport | the port of the stun server |
err | a pointer to describe errors |
pool | the memory pool to use |
Definition at line 708 of file switch_stun.c.
References switch_stun_ip_t::address, buf, switch_assert, switch_cond_next(), switch_core_strdup, switch_micro_time_now(), SWITCH_SHUTDOWN_READWRITE, SWITCH_SO_NONBLOCK, switch_sockaddr_info_get(), switch_socket_bind(), switch_socket_close(), switch_socket_create(), switch_socket_opt_set(), switch_socket_recvfrom(), switch_socket_sendto(), switch_socket_shutdown(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_STATUS_TIMEOUT, SWITCH_STUN_ATTR_MAPPED_ADDRESS, SWITCH_STUN_ATTR_USERNAME, SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, switch_stun_attribute_padded_length, SWITCH_STUN_BINDING_REQUEST, SWITCH_STUN_BINDING_RESPONSE, switch_stun_packet_attribute_add_username(), switch_stun_packet_attribute_get_mapped_address(), switch_stun_packet_attribute_get_username(), switch_stun_packet_attribute_get_xor_mapped_address(), switch_stun_packet_build_header(), switch_stun_packet_first_attribute, switch_stun_packet_length, switch_stun_packet_next_attribute, switch_stun_packet_parse(), switch_stun_random_string(), SWITCH_UNSPEC, TRUE, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by switch_core_media_ext_address_lookup(), and switch_stun_ip_lookup().
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.
packet | the packet to add the attribute to |
ipstr | the string representation of the ip |
port | the port of the mapped address |
Definition at line 458 of file switch_stun.c.
References switch_stun_ip_t::address, switch_stun_ip_t::family, switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, ip, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, switch_stun_ip_t::port, STUN_MAGIC_COOKIE, SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
uint8_t switch_stun_packet_attribute_add_controlled | ( | switch_stun_packet_t * | packet | ) |
Definition at line 607 of file switch_stun.c.
References buf, switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_CONTROLLED, switch_stun_random_string(), switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by ice_out().
uint8_t switch_stun_packet_attribute_add_controlling | ( | switch_stun_packet_t * | packet | ) |
Definition at line 592 of file switch_stun.c.
References buf, switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_CONTROLLING, switch_stun_random_string(), switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by ice_out().
uint8_t switch_stun_packet_attribute_add_fingerprint | ( | switch_stun_packet_t * | packet | ) |
Definition at line 559 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, switch_crc32_8bytes(), SWITCH_STUN_ATTR_FINGERPRINT, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and ice_out().
uint8_t switch_stun_packet_attribute_add_integrity | ( | switch_stun_packet_t * | packet, |
const char * | pass | ||
) |
Definition at line 542 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_MESSAGE_INTEGRITY, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and ice_out().
uint8_t switch_stun_packet_attribute_add_password | ( | switch_stun_packet_t * | packet, |
char * | password, | ||
uint16_t | ulen | ||
) |
Definition at line 671 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_PASSWORD, switch_stun_random_string(), switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
uint8_t switch_stun_packet_attribute_add_priority | ( | switch_stun_packet_t * | packet, |
uint32_t | priority | ||
) |
Definition at line 528 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_PRIORITY, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by ice_out().
uint8_t switch_stun_packet_attribute_add_software | ( | switch_stun_packet_t * | packet, |
char * | software, | ||
uint16_t | ulen | ||
) |
Definition at line 647 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_SOFTWARE, switch_stun_random_string(), switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by ice_out().
uint8_t switch_stun_packet_attribute_add_use_candidate | ( | switch_stun_packet_t * | packet | ) |
Definition at line 581 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_USE_CAND, and switch_stun_packet_attribute_t::type.
Referenced by ice_out().
uint8_t switch_stun_packet_attribute_add_username | ( | switch_stun_packet_t * | packet, |
char * | username, | ||
uint16_t | ulen | ||
) |
Add a username packet attribute.
packet | the packet to add the attribute to |
username | the string representation of the username |
ulen | the length of the username |
Definition at line 623 of file switch_stun.c.
References switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, SWITCH_STUN_ATTR_USERNAME, switch_stun_random_string(), switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), ice_out(), and switch_stun_lookup().
uint8_t switch_stun_packet_attribute_add_xor_binded_address | ( | switch_stun_packet_t * | packet, |
char * | ipstr, | ||
uint16_t | port, | ||
int | family | ||
) |
Definition at line 492 of file switch_stun.c.
References switch_stun_ip_t::address, switch_stun_ip_t::family, switch_stun_packet_t::first_attribute, switch_stun_packet_t::header, switch_stun_packet_header_t::id, ip, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, switch_stun_ip_t::port, STUN_MAGIC_COOKIE, SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, switch_stun_packet_attribute_t::type, v6_xor(), and switch_stun_packet_attribute_t::value.
Referenced by handle_ice().
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.
attribute | the attribute from which to extract |
ipstr | a buffer to write the string representation of the ip |
port | the port |
Definition at line 384 of file switch_stun.c.
References switch_stun_ip_t::address, ip, switch_stun_ip_t::port, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and switch_stun_lookup().
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.
attribute | the attribute from which to extract |
username | a buffer to write the string representation of the username |
len | the maximum size of the username buffer |
Definition at line 430 of file switch_stun.c.
References switch_stun_packet_attribute_t::length, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and switch_stun_lookup().
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 | ||
) |
Definition at line 401 of file switch_stun.c.
References switch_stun_ip_t::address, switch_stun_packet_header_t::cookie, switch_stun_ip_t::family, switch_stun_packet_header_t::id, if(), ip, switch_stun_ip_t::port, v6_xor(), and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and switch_stun_lookup().
switch_stun_packet_t* switch_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.
id | id to use (NULL for an auto generated id) |
type | the stun packet type |
buf | a pointer to data to use for the packet |
Definition at line 438 of file switch_stun.c.
References buf, switch_stun_packet_header_t::cookie, switch_stun_packet_header_t::id, switch_stun_packet_header_t::length, STUN_MAGIC_COOKIE, switch_stun_random_string(), and switch_stun_packet_header_t::type.
Referenced by handle_ice(), ice_out(), and switch_stun_lookup().
switch_stun_packet_t* switch_stun_packet_parse | ( | uint8_t * | buf, |
uint32_t | len | ||
) |
Prepare a raw packet for parsing.
buf | the raw data |
len | the length of the data |
Definition at line 144 of file switch_stun.c.
References switch_stun_ip_t::family, switch_stun_packet_t::header, if(), ip, switch_stun_packet_header_t::length, switch_stun_packet_attribute_t::length, switch_stun_ip_t::port, SWITCH_STUN_ALLOCATE_ERROR_RESPONSE, SWITCH_STUN_ALLOCATE_REQUEST, SWITCH_STUN_ALLOCATE_RESPONSE, SWITCH_STUN_ATTR_ALTERNATE_SERVER, SWITCH_STUN_ATTR_BANDWIDTH, SWITCH_STUN_ATTR_CHANGE_REQUEST, SWITCH_STUN_ATTR_CHANGED_ADDRESS, SWITCH_STUN_ATTR_DATA, SWITCH_STUN_ATTR_DESTINATION_ADDRESS, SWITCH_STUN_ATTR_ERROR_CODE, SWITCH_STUN_ATTR_LIFETIME, SWITCH_STUN_ATTR_MAGIC_COOKIE, SWITCH_STUN_ATTR_MAPPED_ADDRESS, SWITCH_STUN_ATTR_MESSAGE_INTEGRITY, SWITCH_STUN_ATTR_OPTIONS, SWITCH_STUN_ATTR_PASSWORD, SWITCH_STUN_ATTR_PRIORITY, SWITCH_STUN_ATTR_REFLECTED_FROM, SWITCH_STUN_ATTR_RESPONSE_ADDRESS, SWITCH_STUN_ATTR_SOFTWARE, SWITCH_STUN_ATTR_SOURCE_ADDRESS, SWITCH_STUN_ATTR_SOURCE_ADDRESS2, SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES, SWITCH_STUN_ATTR_UNKNOWN_ATTRIBUTES, SWITCH_STUN_ATTR_USERNAME, SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, SWITCH_STUN_ATTRIBUTE_MIN_LEN, switch_stun_attribute_padded_length, SWITCH_STUN_BINDING_ERROR_RESPONSE, SWITCH_STUN_BINDING_REQUEST, SWITCH_STUN_BINDING_RESPONSE, SWITCH_STUN_DATA_INDICATION, switch_stun_packet_first_attribute, SWITCH_STUN_PACKET_MIN_LEN, SWITCH_STUN_SEND_ERROR_RESPONSE, SWITCH_STUN_SEND_REQUEST, SWITCH_STUN_SEND_RESPONSE, SWITCH_STUN_SHARED_SECRET_ERROR_RESPONSE, SWITCH_STUN_SHARED_SECRET_REQUEST, SWITCH_STUN_SHARED_SECRET_RESPONSE, switch_stun_packet_header_t::type, switch_stun_packet_attribute_t::type, and switch_stun_packet_attribute_t::value.
Referenced by handle_ice(), and switch_stun_lookup().
void switch_stun_random_string | ( | char * | buf, |
uint16_t | len, | ||
char * | set | ||
) |
Writes random characters into a buffer.
buf | the buffer |
len | the length of the data |
set | the set of chars to use (NULL for auto) |
Definition at line 125 of file switch_stun.c.
Referenced by gen_ice(), generate_m(), random_string(), switch_core_media_gen_local_sdp(), switch_rtp_get_random(), switch_stun_lookup(), switch_stun_packet_attribute_add_controlled(), switch_stun_packet_attribute_add_controlling(), switch_stun_packet_attribute_add_password(), switch_stun_packet_attribute_add_software(), switch_stun_packet_attribute_add_username(), and switch_stun_packet_build_header().
const char* switch_stun_value_to_name | ( | int32_t | type, |
uint32_t | value | ||
) |
Obtain a printable string form of a given value.
type | the type of message |
value | the value to look up |
Definition at line 354 of file switch_stun.c.
References ATTR_TYPES, ERROR_TYPES, value_mapping::name, PACKET_TYPES, SWITCH_STUN_TYPE_ATTRIBUTE, SWITCH_STUN_TYPE_ERROR, SWITCH_STUN_TYPE_PACKET_TYPE, and value_mapping::value.
Referenced by handle_ice().