Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
3f64a8a6
Commit
3f64a8a6
authored
Jan 10, 2007
by
Dafydd Harries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reindent stun.c for consistency
darcs-hash:20070110164644-c9803-71026228f7b135922e39f9d6a7b2d75f77125e0f.gz
parent
90abca99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
71 deletions
+81
-71
stun/stun.c
stun/stun.c
+81
-71
No files found.
stun/stun.c
View file @
3f64a8a6
...
...
@@ -43,16 +43,17 @@ stun_attribute_unpack (guint length, const gchar *s)
g_assert
(
length
);
attr
=
stun_attribute_new
(
ntohs
(
*
(
guint16
*
)
s
));
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
attr
->
address
.
af
=
(
guint8
)
s
[
5
];
g_assert
(
attr
->
address
.
af
==
1
);
attr
->
address
.
port
=
ntohs
(
*
(
guint16
*
)(
s
+
6
));
attr
->
address
.
ip
=
ntohl
(
*
(
guint32
*
)(
s
+
8
));
break
;
default:
break
;
}
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
attr
->
address
.
af
=
(
guint8
)
s
[
5
];
g_assert
(
attr
->
address
.
af
==
1
);
attr
->
address
.
port
=
ntohs
(
*
(
guint16
*
)(
s
+
6
));
attr
->
address
.
ip
=
ntohl
(
*
(
guint32
*
)(
s
+
8
));
break
;
default:
break
;
}
return
attr
;
}
...
...
@@ -60,39 +61,41 @@ stun_attribute_unpack (guint length, const gchar *s)
guint
stun_attribute_pack
(
StunAttribute
*
attr
,
gchar
**
packed
)
{
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
{
StunAttribute
*
ret
=
g_malloc0
(
sizeof
(
StunAttribute
));
ret
->
type
=
htons
(
attr
->
type
);
ret
->
length
=
htons
(
8
);
ret
->
address
.
af
=
attr
->
address
.
af
;
ret
->
address
.
port
=
htons
(
attr
->
address
.
port
);
ret
->
address
.
ip
=
htonl
(
attr
->
address
.
ip
);
*
packed
=
(
gchar
*
)
ret
;
return
12
;
}
default:
return
0
;
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
{
StunAttribute
*
ret
=
g_malloc0
(
sizeof
(
StunAttribute
));
ret
->
type
=
htons
(
attr
->
type
);
ret
->
length
=
htons
(
8
);
ret
->
address
.
af
=
attr
->
address
.
af
;
ret
->
address
.
port
=
htons
(
attr
->
address
.
port
);
ret
->
address
.
ip
=
htonl
(
attr
->
address
.
ip
);
*
packed
=
(
gchar
*
)
ret
;
return
12
;
}
default:
return
0
;
}
}
gchar
*
stun_attribute_dump
(
StunAttribute
*
attr
)
{
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
return
g_strdup_printf
(
"MAPPED-ADDRESS %d.%d.%d.%d:%d"
,
(
attr
->
address
.
ip
&
0xff000000
)
>>
24
,
(
attr
->
address
.
ip
&
0x00ff0000
)
>>
16
,
(
attr
->
address
.
ip
&
0x0000ff00
)
>>
8
,
(
attr
->
address
.
ip
&
0x000000ff
)
>>
0
,
attr
->
address
.
port
);
default:
return
g_strdup_printf
(
"UNKNOWN (%d)"
,
attr
->
type
);
}
switch
(
attr
->
type
)
{
case
STUN_ATTRIBUTE_MAPPED_ADDRESS
:
return
g_strdup_printf
(
"MAPPED-ADDRESS %d.%d.%d.%d:%d"
,
(
attr
->
address
.
ip
&
0xff000000
)
>>
24
,
(
attr
->
address
.
ip
&
0x00ff0000
)
>>
16
,
(
attr
->
address
.
ip
&
0x0000ff00
)
>>
8
,
(
attr
->
address
.
ip
&
0x000000ff
)
>>
0
,
attr
->
address
.
port
);
default:
return
g_strdup_printf
(
"UNKNOWN (%d)"
,
attr
->
type
);
}
}
void
...
...
@@ -121,12 +124,13 @@ stun_message_free (StunMessage *msg)
{
StunAttribute
**
attr
;
if
(
msg
->
attributes
)
{
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
stun_attribute_free
(
*
attr
);
if
(
msg
->
attributes
)
{
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
stun_attribute_free
(
*
attr
);
g_free
(
msg
->
attributes
);
}
g_free
(
msg
->
attributes
);
}
g_slice_free
(
StunMessage
,
msg
);
}
...
...
@@ -152,10 +156,11 @@ stun_message_unpack (guint length, gchar *s)
/* count the number of attributes */
for
(
offset
=
20
;
offset
<
length
;
offset
+=
attr_length
+
4
)
{
attr_length
=
ntohs
(
*
(
guint16
*
)(
s
+
offset
+
2
));
n_attributes
++
;
}
for
(
offset
=
20
;
offset
<
length
;
offset
+=
attr_length
+
4
)
{
attr_length
=
ntohs
(
*
(
guint16
*
)(
s
+
offset
+
2
));
n_attributes
++
;
}
/* allocate memory for the attribute list and terminate it */
...
...
@@ -164,10 +169,12 @@ stun_message_unpack (guint length, gchar *s)
/* unpack attributes */
for
(
i
=
0
,
offset
=
20
;
i
<
n_attributes
;
i
++
,
offset
+=
attr_length
+
4
)
{
attr_length
=
ntohs
(
*
(
guint16
*
)(
s
+
offset
+
2
));
attr
=
msg
->
attributes
[
i
]
=
stun_attribute_unpack
(
attr_length
,
s
+
offset
);
}
for
(
i
=
0
,
offset
=
20
;
i
<
n_attributes
;
i
++
,
offset
+=
attr_length
+
4
)
{
attr_length
=
ntohs
(
*
(
guint16
*
)(
s
+
offset
+
2
));
attr
=
msg
->
attributes
[
i
]
=
stun_attribute_unpack
(
attr_length
,
s
+
offset
);
}
return
msg
;
}
...
...
@@ -180,12 +187,13 @@ stun_message_pack (StunMessage *msg, gchar **packed)
guint16
packed_length
;
guint
length
=
0
;
if
(
msg
->
attributes
)
{
StunAttribute
**
attr
;
if
(
msg
->
attributes
)
{
StunAttribute
**
attr
;
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
length
+=
4
+
(
*
attr
)
->
length
;
}
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
length
+=
4
+
(
*
attr
)
->
length
;
}
packed_type
=
htons
(
msg
->
type
);
packed_length
=
htons
(
length
);
...
...
@@ -197,16 +205,18 @@ stun_message_pack (StunMessage *msg, gchar **packed)
((
gchar
*
)
&
packed_length
)[
1
]);
g_string_append_len
(
tmp
,
msg
->
transaction_id
,
16
);
if
(
msg
->
attributes
)
{
StunAttribute
**
attr
;
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
{
gchar
*
attr_packed
;
guint
attr_length
=
stun_attribute_pack
(
*
attr
,
&
attr_packed
);
g_string_append_len
(
tmp
,
attr_packed
,
attr_length
);
g_free
(
attr_packed
);
if
(
msg
->
attributes
)
{
StunAttribute
**
attr
;
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
{
gchar
*
attr_packed
;
guint
attr_length
=
stun_attribute_pack
(
*
attr
,
&
attr_packed
);
g_string_append_len
(
tmp
,
attr_packed
,
attr_length
);
g_free
(
attr_packed
);
}
}
}
*
packed
=
g_string_free
(
tmp
,
FALSE
);
return
length
+
20
;
...
...
@@ -238,13 +248,13 @@ stun_message_dump (StunMessage *msg)
*
(
guint32
*
)(
msg
->
transaction_id
+
8
),
*
(
guint32
*
)(
msg
->
transaction_id
+
12
));
if
(
msg
->
attributes
)
{
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
{
gchar
*
dump
=
stun_attribute_dump
(
*
attr
);
g_string_append_printf
(
tmp
,
"
\n
%s"
,
dump
);
g_free
(
dump
);
}
}
if
(
msg
->
attributes
)
for
(
attr
=
msg
->
attributes
;
*
attr
;
attr
++
)
{
gchar
*
dump
=
stun_attribute_dump
(
*
attr
);
g_string_append_printf
(
tmp
,
"
\n
%s"
,
dump
);
g_free
(
dump
);
}
return
g_string_free
(
tmp
,
FALSE
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment