Commit dd672a60 authored by Dafydd Harries's avatar Dafydd Harries

add support for packing STUN usernames

darcs-hash:20070130112905-c9803-66d17400e841246fa09c95f0f211a50ea7ad2fa9.gz
parent 9e5d7436
......@@ -137,6 +137,22 @@ stun_attribute_pack (StunAttribute *attr, gchar **packed)
return 12;
}
case STUN_ATTRIBUTE_USERNAME:
{
if (packed != NULL)
{
StunAttribute *ret = g_malloc0 (sizeof (StunAttribute));
ret->type = htons (attr->type);
ret->length = htons (attr->length);
memcpy (ret->username, attr->username, attr->length);
*packed = (gchar *) ret;
}
return ceil4 (4 + attr->length);
}
default:
return 0;
}
......
......@@ -3,8 +3,8 @@
#include "stun.h"
int
main (void)
void
test_pack_mapped_address (void)
{
StunAttribute *attr = stun_attribute_mapped_address_new (0x02030405, 2345);
gchar *packed;
......@@ -24,6 +24,36 @@ main (void)
length));
g_free (packed);
stun_attribute_free (attr);
}
void
test_pack_username (void)
{
StunAttribute *attr;
gchar *packed;
guint length;
attr = stun_attribute_username_new ("abcdefghi");
length = stun_attribute_pack (attr, &packed);
// 4 bytes header + 9 bytes padded to 32 bits = 16
g_assert (16 == length);
// type
g_assert (0 == memcmp (packed + 0, "\x00\x06", 2));
// length
g_assert (0 == memcmp (packed + 2, "\x00\x09", 2));
// value
g_assert (0 == memcmp (packed + 4, "abcdefghi\0\0\0", length - 4));
g_free (packed);
stun_attribute_free (attr);
}
int
main (void)
{
test_pack_mapped_address ();
test_pack_username ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment