mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
switched stun packet byte layout to network-byte-order.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@333 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
215e3386f2
commit
54063ab434
@ -321,7 +321,7 @@ bool UdpSorter::response(void *stun_pkt, int size, struct sockaddr_in &addr)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((uint16_t *) stun_pkt)[0] != 0x0101)
|
||||
if (htons(((uint16_t *) stun_pkt)[0]) != 0x0101)
|
||||
{
|
||||
/* not a response */
|
||||
return false;
|
||||
@ -354,13 +354,13 @@ bool UdpSorter::generate_stun_pkt(void *stun_pkt, int *len)
|
||||
}
|
||||
|
||||
/* just the header */
|
||||
((uint16_t *) stun_pkt)[0] = 0x0001;
|
||||
((uint16_t *) stun_pkt)[1] = 20; /* only header */
|
||||
((uint16_t *) stun_pkt)[0] = (uint16_t) htons(0x0001);
|
||||
((uint16_t *) stun_pkt)[1] = (uint16_t) htons(20); /* only header */
|
||||
/* transaction id - should be random */
|
||||
((uint32_t *) stun_pkt)[1] = 0x0020;
|
||||
((uint32_t *) stun_pkt)[2] = 0x0121;
|
||||
((uint32_t *) stun_pkt)[3] = 0x0111;
|
||||
((uint32_t *) stun_pkt)[4] = 0x1010;
|
||||
((uint32_t *) stun_pkt)[1] = (uint32_t) htonl(0x0020);
|
||||
((uint32_t *) stun_pkt)[2] = (uint32_t) htonl(0x0121);
|
||||
((uint32_t *) stun_pkt)[3] = (uint32_t) htonl(0x0111);
|
||||
((uint32_t *) stun_pkt)[4] = (uint32_t) htonl(0x1010);
|
||||
*len = 20;
|
||||
return true;
|
||||
}
|
||||
@ -370,21 +370,23 @@ void *UdpSorter::generate_stun_reply(struct sockaddr_in *stun_addr, int *len)
|
||||
{
|
||||
/* just the header */
|
||||
void *stun_pkt = malloc(28);
|
||||
((uint16_t *) stun_pkt)[0] = 0x0101;
|
||||
((uint16_t *) stun_pkt)[1] = 28; /* only header + 8 byte addr */
|
||||
((uint16_t *) stun_pkt)[0] = (uint16_t) htons(0x0101);
|
||||
((uint16_t *) stun_pkt)[1] = (uint16_t) htons(28); /* only header + 8 byte addr */
|
||||
/* transaction id - should be random */
|
||||
((uint32_t *) stun_pkt)[1] = 0x0020;
|
||||
((uint32_t *) stun_pkt)[2] = 0x0121;
|
||||
((uint32_t *) stun_pkt)[3] = 0x0111;
|
||||
((uint32_t *) stun_pkt)[4] = 0x1010;
|
||||
((uint32_t *) stun_pkt)[1] = (uint32_t) htonl(0x0f20);
|
||||
((uint32_t *) stun_pkt)[2] = (uint32_t) htonl(0x0f21);
|
||||
((uint32_t *) stun_pkt)[3] = (uint32_t) htonl(0x0f11);
|
||||
((uint32_t *) stun_pkt)[4] = (uint32_t) htonl(0x1010);
|
||||
/* now add address
|
||||
* 0 1 2 3
|
||||
* <INET> <port>
|
||||
* <inet address>
|
||||
*/
|
||||
|
||||
((uint32_t *) stun_pkt)[6] = stun_addr->sin_addr.s_addr;
|
||||
/* THESE SHOULD BE NET ORDER ALREADY */
|
||||
((uint16_t *) stun_pkt)[10] = AF_INET;
|
||||
((uint16_t *) stun_pkt)[11] = stun_addr->sin_port;
|
||||
((uint32_t *) stun_pkt)[6] = stun_addr->sin_addr.s_addr;
|
||||
|
||||
*len = 28;
|
||||
return stun_pkt;
|
||||
@ -407,7 +409,7 @@ bool UdpSorter::isStunPacket(void *data, int size)
|
||||
}
|
||||
|
||||
/* match size field */
|
||||
uint16_t pktsize = ((uint16_t *) data)[1];
|
||||
uint16_t pktsize = ntohs(((uint16_t *) data)[1]);
|
||||
if (size != pktsize)
|
||||
{
|
||||
#ifdef DEBUG_UDP_SORTER
|
||||
@ -417,7 +419,7 @@ bool UdpSorter::isStunPacket(void *data, int size)
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((size == 20) && (0x0001 == ((uint16_t *) data)[0]))
|
||||
if ((size == 20) && (0x0001 == ntohs(((uint16_t *) data)[0])))
|
||||
{
|
||||
#ifdef DEBUG_UDP_SORTER
|
||||
std::cerr << "UdpSorter::isStunPacket() (size=20 & data[0]=0x0001) -> true";
|
||||
@ -427,7 +429,7 @@ bool UdpSorter::isStunPacket(void *data, int size)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((size == 28) && (0x0101 == ((uint16_t *) data)[0]))
|
||||
if ((size == 28) && (0x0101 == ntohs(((uint16_t *) data)[0])))
|
||||
{
|
||||
#ifdef DEBUG_UDP_SORTER
|
||||
std::cerr << "UdpSorter::isStunPacket() (size=28 & data[0]=0x0101) -> true";
|
||||
|
Loading…
Reference in New Issue
Block a user