summaryrefslogtreecommitdiff
path: root/pjlib-util/src
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2010-07-06 08:11:04 +0000
committerNanang Izzuddin <nanang@teluu.com>2010-07-06 08:11:04 +0000
commite96bece6bdc9ccdff04632d7e15f3eb5c6d7d8e2 (patch)
treef5b7e918a082c8e0626f059dae2b1718b36d7b48 /pjlib-util/src
parent328097bf3f6ac7538e8573ee2770d55c67924a79 (diff)
Fix #1078: added XOR_MAPPED_ADDRESS parsing capability to the resolver.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3235 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src')
-rw-r--r--pjlib-util/src/pjlib-util/stun_simple.c8
-rw-r--r--pjlib-util/src/pjlib-util/stun_simple_client.c13
2 files changed, 17 insertions, 4 deletions
diff --git a/pjlib-util/src/pjlib-util/stun_simple.c b/pjlib-util/src/pjlib-util/stun_simple.c
index 7b7aa772..9bc6b457 100644
--- a/pjlib-util/src/pjlib-util/stun_simple.c
+++ b/pjlib-util/src/pjlib-util/stun_simple.c
@@ -86,6 +86,7 @@ PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len,
while (msg_len > 0) {
pjstun_attr_hdr **attr = &msg->attr[msg->attr_count];
pj_uint32_t len;
+ pj_uint16_t attr_type;
*attr = (pjstun_attr_hdr*)p_attr;
len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pjstun_attr_hdr);
@@ -97,10 +98,13 @@ PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len,
return PJLIB_UTIL_ESTUNINATTRLEN;
}
- if (pj_ntohs((*attr)->type) > PJSTUN_ATTR_REFLECTED_FORM) {
+ attr_type = pj_ntohs((*attr)->type);
+ if (attr_type > PJSTUN_ATTR_REFLECTED_FROM &&
+ attr_type != PJSTUN_ATTR_XOR_MAPPED_ADDR)
+ {
PJ_LOG(5,(THIS_FILE, "Warning: unknown attr type %x in attr %d. "
"Attribute was ignored.",
- pj_ntohs((*attr)->type), msg->attr_count));
+ attr_type, msg->attr_count));
}
msg_len = (pj_uint16_t)(msg_len - len);
diff --git a/pjlib-util/src/pjlib-util/stun_simple_client.c b/pjlib-util/src/pjlib-util/stun_simple_client.c
index cd21f7f0..fa4fb966 100644
--- a/pjlib-util/src/pjlib-util/stun_simple_client.c
+++ b/pjlib-util/src/pjlib-util/stun_simple_client.c
@@ -29,6 +29,7 @@
enum { MAX_REQUEST = 4 };
static int stun_timer[] = {1000, 1000, 1000, 1000 };
+#define STUN_MAGIC 0x2112A442
#define THIS_FILE "stun_client.c"
#define LOG_ADDR(addr) pj_inet_ntoa(addr.sin_addr), pj_ntohs(addr.sin_port)
@@ -223,12 +224,20 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr( pj_pool_factory *pf,
attr = (pjstun_mapped_addr_attr*)
pjstun_msg_find_attr(&msg, PJSTUN_ATTR_MAPPED_ADDR);
if (!attr) {
- status = PJLIB_UTIL_ESTUNNOMAP;
- continue;
+ attr = (pjstun_mapped_addr_attr*)
+ pjstun_msg_find_attr(&msg, PJSTUN_ATTR_XOR_MAPPED_ADDR);
+ if (!attr || attr->family != 1) {
+ status = PJLIB_UTIL_ESTUNNOMAP;
+ continue;
+ }
}
rec[sock_idx].srv[srv_idx].mapped_addr = attr->addr;
rec[sock_idx].srv[srv_idx].mapped_port = attr->port;
+ if (pj_ntohs(attr->hdr.type) == PJSTUN_ATTR_XOR_MAPPED_ADDR) {
+ rec[sock_idx].srv[srv_idx].mapped_addr ^= pj_htonl(STUN_MAGIC);
+ rec[sock_idx].srv[srv_idx].mapped_port ^= pj_htons(STUN_MAGIC >> 16);
+ }
}
}