37 #ifndef FREESWITCH_STUN_PARSER_H
38 #define FREESWITCH_STUN_PARSER_H
41 #define SWITCH_STUN_DEFAULT_PORT 3478
42 #define SWITCH_STUN_PACKET_MIN_LEN 20
43 #define SWITCH_STUN_ATTRIBUTE_MIN_LEN 8
60 #define STUN_MAGIC_COOKIE 0x2112A442
134 uint8_t first_attribute[];
144 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
268 #define switch_stun_attribute_padded_length(attribute) (int16_t)((attribute->length & 0x3) ? 0x4 + (attribute->length & ~0x3) : attribute->length)
269 #define switch_stun_attribute_padded_length_hbo(attribute) (int16_t)((ntohs(attribute->length) & 0x3) ? 0x4 + (ntohs(attribute->length) & ~0x3) : ntohs(attribute->length))
277 #define switch_stun_packet_first_attribute(packet, attribute) attribute = (switch_stun_packet_attribute_t *)(&packet->first_attribute);
286 #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))
288 #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))
295 #define switch_stun_packet_length(packet) ntohs(packet->header.length) + (sizeof(switch_stun_packet_header_t))
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_priority(switch_stun_packet_t *packet, uint32_t priority)
uint8_t switch_stun_packet_attribute_add_fingerprint(switch_stun_packet_t *packet)
uint8_t switch_stun_packet_attribute_add_controlling(switch_stun_packet_t *packet)
#define SWITCH_END_EXTERN_C
uint32_t switch_crc32_8bytes(const void *data, size_t length)
switch_memory_pool_t * pool
char * switch_stun_host_lookup(const char *host, switch_memory_pool_t *pool)
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.
uint8_t switch_stun_packet_attribute_add_use_candidate(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.
switch_byte_t switch_byte_t * buf
void switch_stun_random_string(char *buf, uint16_t len, char *set)
Writes random characters into a buffer.
switch_stun_packet_header_t header
uint8_t switch_stun_packet_attribute_add_password(switch_stun_packet_t *packet, char *password, uint16_t ulen)
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.
switch_status_t
Common return values.
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)
switch_stun_packet_t * switch_stun_packet_parse(uint8_t *buf, uint32_t len)
Prepare a raw packet for parsing.
uint8_t switch_stun_packet_attribute_add_controlled(switch_stun_packet_t *packet)
struct apr_pool_t switch_memory_pool_t
uint8_t switch_stun_packet_attribute_add_xor_binded_address(switch_stun_packet_t *packet, char *ipstr, uint16_t port, int family)
const char * switch_stun_value_to_name(int32_t type, uint32_t value)
Obtain a printable string form of a given value.
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.
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.
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.
uint8_t switch_stun_packet_attribute_add_integrity(switch_stun_packet_t *packet, const char *pass)
#define SWITCH_BEGIN_EXTERN_C