*/
switch (attr->type) {
case SWITCH_STUN_ATTR_MAPPED_ADDRESS: /* Address, we only care about this one, but parse the others too */
+ case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS:
case SWITCH_STUN_ATTR_RESPONSE_ADDRESS:
case SWITCH_STUN_ATTR_SOURCE_ADDRESS:
case SWITCH_STUN_ATTR_CHANGED_ADDRESS:
return 1;
}
+SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_xor_mapped_address(switch_stun_packet_attribute_t *attribute, uint32_t cookie, char *ipstr, uint16_t *port)
+{
+ switch_stun_ip_t *ip;
+ uint8_t x, *i;
+ char *p = ipstr;
+
+ ip = (switch_stun_ip_t *) attribute->value;
+ ip->address ^= cookie;
+
+ i = (uint8_t *) & ip->address;
+ *ipstr = 0;
+ for (x = 0; x < 4; x++) {
+ sprintf(p, "%u%s", i[x], x == 3 ? "" : ".");
+ p = ipstr + strlen(ipstr);
+ }
+
+ ip->port ^= ntohl(cookie) >> 16;
+ *port = ip->port;
+
+ return 1;
+}
+
SWITCH_DECLARE(char *) switch_stun_packet_attribute_get_username(switch_stun_packet_attribute_t *attribute, char *username, uint16_t len)
{
uint16_t cpylen;
switch_stun_packet_attribute_get_mapped_address(attr, rip, &rport);
}
break;
+ case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS:
+ if (attr->type) {
+ switch_stun_packet_attribute_get_xor_mapped_address(attr, packet->header.cookie, rip, &rport);
+ }
+ break;
case SWITCH_STUN_ATTR_USERNAME:
if (attr->type) {
switch_stun_packet_attribute_get_username(attr, username, 32);