From a55a9b39155856224bc8e81e9abaff1d8235834c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Feb 2013 07:35:18 -0600 Subject: [PATCH] FS-5081 --resolve cool, thanks --- src/switch_stun.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/switch_stun.c b/src/switch_stun.c index 616cf27a37..8e44b249db 100644 --- a/src/switch_stun.c +++ b/src/switch_stun.c @@ -193,6 +193,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui */ 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: @@ -350,6 +351,28 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_s 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; @@ -605,6 +628,11 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, 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);