Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
c3094046
提交
c3094046
authored
6月 22, 2012
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update stun to more modern spec
上级
c28ced72
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
63 行增加
和
5 行删除
+63
-5
switch_stun.h
src/include/switch_stun.h
+8
-2
switch_stun.c
src/switch_stun.c
+55
-3
没有找到文件。
src/include/switch_stun.h
浏览文件 @
c3094046
...
@@ -57,6 +57,8 @@ SWITCH_BEGIN_EXTERN_C
...
@@ -57,6 +57,8 @@ SWITCH_BEGIN_EXTERN_C
SWITCH_STUN_DATA_INDICATION
=
0x0115
SWITCH_STUN_DATA_INDICATION
=
0x0115
}
switch_stun_message_t
;
}
switch_stun_message_t
;
#define STUN_MAGIC_COOKIE 0x2112A442
typedef
enum
{
typedef
enum
{
SWITCH_STUN_ATTR_MAPPED_ADDRESS
=
0x0001
,
/* Address */
SWITCH_STUN_ATTR_MAPPED_ADDRESS
=
0x0001
,
/* Address */
SWITCH_STUN_ATTR_RESPONSE_ADDRESS
=
0x0002
,
/* Address */
SWITCH_STUN_ATTR_RESPONSE_ADDRESS
=
0x0002
,
/* Address */
...
@@ -77,7 +79,8 @@ typedef enum {
...
@@ -77,7 +79,8 @@ typedef enum {
SWITCH_STUN_ATTR_DESTINATION_ADDRESS
=
0x0011
,
/* Address */
SWITCH_STUN_ATTR_DESTINATION_ADDRESS
=
0x0011
,
/* Address */
SWITCH_STUN_ATTR_SOURCE_ADDRESS2
=
0x0012
,
/* Address */
SWITCH_STUN_ATTR_SOURCE_ADDRESS2
=
0x0012
,
/* Address */
SWITCH_STUN_ATTR_DATA
=
0x0013
,
/* ByteString */
SWITCH_STUN_ATTR_DATA
=
0x0013
,
/* ByteString */
SWITCH_STUN_ATTR_OPTIONS
=
0x8001
/* UInt32 */
SWITCH_STUN_ATTR_OPTIONS
=
0x8001
,
/* UInt32 */
SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS
=
0x0020
,
/* Address */
}
switch_stun_attribute_t
;
}
switch_stun_attribute_t
;
typedef
enum
{
typedef
enum
{
...
@@ -101,7 +104,8 @@ typedef enum {
...
@@ -101,7 +104,8 @@ typedef enum {
typedef
struct
{
typedef
struct
{
uint16_t
type
;
uint16_t
type
;
uint16_t
length
;
uint16_t
length
;
char
id
[
16
];
uint32_t
cookie
;
char
id
[
12
];
}
switch_stun_packet_header_t
;
}
switch_stun_packet_header_t
;
typedef
struct
{
typedef
struct
{
...
@@ -185,6 +189,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_st
...
@@ -185,6 +189,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_st
\return true or false
\return true or false
*/
*/
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_username
(
switch_stun_packet_t
*
packet
,
char
*
username
,
uint16_t
ulen
);
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_username
(
switch_stun_packet_t
*
packet
,
char
*
username
,
uint16_t
ulen
);
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_password
(
switch_stun_packet_t
*
packet
,
char
*
password
,
uint16_t
ulen
);
/*!
/*!
...
@@ -195,6 +200,7 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_username(switch_stun_pa
...
@@ -195,6 +200,7 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_username(switch_stun_pa
\return true or false
\return true or false
*/
*/
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_binded_address
(
switch_stun_packet_t
*
packet
,
char
*
ipstr
,
uint16_t
port
);
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_binded_address
(
switch_stun_packet_t
*
packet
,
char
*
ipstr
,
uint16_t
port
);
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_xor_binded_address
(
switch_stun_packet_t
*
packet
,
char
*
ipstr
,
uint16_t
port
);
/*!
/*!
\brief Perform a stun lookup
\brief Perform a stun lookup
...
...
src/switch_stun.c
浏览文件 @
c3094046
...
@@ -186,7 +186,6 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
...
@@ -186,7 +186,6 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
* we don't want the upper layers to have to deal with attributes without a value
* we don't want the upper layers to have to deal with attributes without a value
* (or worse: invalid length)
* (or worse: invalid length)
*/
*/
return
NULL
;
}
}
/*
/*
...
@@ -367,11 +366,12 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_st
...
@@ -367,11 +366,12 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_st
header
=
(
switch_stun_packet_header_t
*
)
buf
;
header
=
(
switch_stun_packet_header_t
*
)
buf
;
header
->
type
=
htons
(
type
);
header
->
type
=
htons
(
type
);
header
->
length
=
0
;
header
->
length
=
0
;
header
->
cookie
=
htonl
(
STUN_MAGIC_COOKIE
);
if
(
id
)
{
if
(
id
)
{
memcpy
(
header
->
id
,
id
,
1
6
);
memcpy
(
header
->
id
,
id
,
1
2
);
}
else
{
}
else
{
switch_stun_random_string
(
header
->
id
,
1
6
,
NULL
);
switch_stun_random_string
(
header
->
id
,
1
2
,
NULL
);
}
}
return
(
switch_stun_packet_t
*
)
buf
;
return
(
switch_stun_packet_t
*
)
buf
;
...
@@ -402,6 +402,38 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_s
...
@@ -402,6 +402,38 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_s
}
}
}
}
packet
->
header
.
length
+=
htons
(
sizeof
(
switch_stun_packet_attribute_t
))
+
attribute
->
length
;
return
1
;
}
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_xor_binded_address
(
switch_stun_packet_t
*
packet
,
char
*
ipstr
,
uint16_t
port
)
{
switch_stun_packet_attribute_t
*
attribute
;
switch_stun_ip_t
*
ip
;
uint8_t
*
i
,
x
;
char
*
p
=
ipstr
;
attribute
=
(
switch_stun_packet_attribute_t
*
)
((
uint8_t
*
)
&
packet
->
first_attribute
+
ntohs
(
packet
->
header
.
length
));
attribute
->
type
=
htons
(
SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS
);
attribute
->
length
=
htons
(
8
);
ip
=
(
switch_stun_ip_t
*
)
attribute
->
value
;
ip
->
port
=
htons
(
port
^
(
STUN_MAGIC_COOKIE
>>
16
));
ip
->
family
=
1
;
i
=
(
uint8_t
*
)
&
ip
->
address
;
for
(
x
=
0
;
x
<
4
;
x
++
)
{
i
[
x
]
=
(
uint8_t
)
atoi
(
p
);
if
((
p
=
strchr
(
p
,
'.'
)))
{
p
++
;
}
else
{
break
;
}
}
ip
->
address
=
htonl
(
ntohl
(
ip
->
address
)
^
STUN_MAGIC_COOKIE
);
packet
->
header
.
length
+=
htons
(
sizeof
(
switch_stun_packet_attribute_t
))
+
attribute
->
length
;
packet
->
header
.
length
+=
htons
(
sizeof
(
switch_stun_packet_attribute_t
))
+
attribute
->
length
;
return
1
;
return
1
;
}
}
...
@@ -426,6 +458,26 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_username(switch_stun_pa
...
@@ -426,6 +458,26 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_username(switch_stun_pa
return
1
;
return
1
;
}
}
SWITCH_DECLARE
(
uint8_t
)
switch_stun_packet_attribute_add_password
(
switch_stun_packet_t
*
packet
,
char
*
password
,
uint16_t
ulen
)
{
switch_stun_packet_attribute_t
*
attribute
;
if
(
ulen
%
4
!=
0
)
{
return
0
;
}
attribute
=
(
switch_stun_packet_attribute_t
*
)
((
uint8_t
*
)
&
packet
->
first_attribute
+
ntohs
(
packet
->
header
.
length
));
attribute
->
type
=
htons
(
SWITCH_STUN_ATTR_PASSWORD
);
attribute
->
length
=
htons
(
ulen
);
if
(
password
)
{
memcpy
(
attribute
->
value
,
password
,
ulen
);
}
else
{
switch_stun_random_string
(
attribute
->
value
,
ulen
,
NULL
);
}
packet
->
header
.
length
+=
htons
(
sizeof
(
switch_stun_packet_attribute_t
))
+
attribute
->
length
;
return
1
;
}
SWITCH_DECLARE
(
char
*
)
switch_stun_host_lookup
(
const
char
*
host
,
switch_memory_pool_t
*
pool
)
SWITCH_DECLARE
(
char
*
)
switch_stun_host_lookup
(
const
char
*
host
,
switch_memory_pool_t
*
pool
)
{
{
switch_sockaddr_t
*
addr
=
NULL
;
switch_sockaddr_t
*
addr
=
NULL
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论