Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SummerGao.
rt-thread
提交
2d48769a
R
rt-thread
项目概览
SummerGao.
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2d48769a
编写于
5月 28, 2019
作者:
B
Bernard Xiong
提交者:
GitHub
5月 28, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2729 from Lawlieta/develop_sal
[net][sal] Improve the sal_bind() function
上级
e228d976
4608e116
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
31 deletion
+29
-31
components/net/sal_socket/src/sal_socket.c
components/net/sal_socket/src/sal_socket.c
+29
-31
未找到文件。
components/net/sal_socket/src/sal_socket.c
浏览文件 @
2d48769a
...
...
@@ -561,8 +561,7 @@ int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
{
struct
sal_socket
*
sock
;
struct
sal_proto_family
*
pf
;
struct
netdev
*
new_netdev
;
ip_addr_t
local_addr
;
ip_addr_t
input_ipaddr
;
RT_ASSERT
(
name
);
...
...
@@ -570,44 +569,43 @@ int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
SAL_SOCKET_OBJ_GET
(
sock
,
socket
);
/* bind network interface by ip address */
sal_sockaddr_to_ipaddr
(
name
,
&
local_
addr
);
sal_sockaddr_to_ipaddr
(
name
,
&
input_ip
addr
);
/* check input ipaddr is default netdev ipaddr */
if
(
local_addr
.
addr
=
=
INADDR_ANY
)
if
(
input_ipaddr
.
addr
!
=
INADDR_ANY
)
{
SAL_NETDEV_SOCKETOPS_VALID
(
sock
->
netdev
,
pf
,
bind
);
return
pf
->
skt_ops
->
bind
((
int
)
sock
->
user_data
,
name
,
namelen
);
}
new_netdev
=
netdev_get_by_ipaddr
(
&
local_addr
);
if
(
new_netdev
==
RT_NULL
)
{
LOG_E
(
"Not find network interface device ipaddr(%s)."
,
inet_ntoa
(
local_addr
));
return
-
1
;
}
struct
sal_proto_family
*
input_pf
=
RT_NULL
,
*
local_pf
=
RT_NULL
;
struct
netdev
*
new_netdev
=
RT_NULL
;
/* change network interface device parameter in sal socket object */
if
(
sock
->
netdev
!=
new_netdev
)
{
struct
sal_proto_family
*
old_pf
,
*
new_pf
;
int
new_socket
=
0
;
new_netdev
=
netdev_get_by_ipaddr
(
&
input_ipaddr
);
if
(
new_netdev
==
RT_NULL
)
{
return
-
1
;
}
/*
close old netdev socket
*/
SAL_NETDEV_SOCKETOPS_VALID
(
sock
->
netdev
,
old_pf
,
closesocket
);
old_pf
->
skt_ops
->
closesocket
(
socket
);
/*
get input and local ip address proto_family
*/
SAL_NETDEV_SOCKETOPS_VALID
(
sock
->
netdev
,
local_pf
,
bind
);
SAL_NETDEV_SOCKETOPS_VALID
(
new_netdev
,
input_pf
,
bind
);
/* open new netdev socket */
SAL_NETDEV_SOCKETOPS_VALID
(
new_netdev
,
new_pf
,
socket
);
new_socket
=
new_pf
->
skt_ops
->
socket
(
sock
->
domain
,
sock
->
type
,
sock
->
protocol
);
if
(
new_socket
<
0
)
/* check the network interface protocol family type */
if
(
input_pf
->
family
!=
local_pf
->
family
)
{
return
-
1
;
int
new_socket
=
-
1
;
/* protocol family is different, close old socket and create new socket by input ip address */
local_pf
->
skt_ops
->
closesocket
(
socket
);
new_socket
=
input_pf
->
skt_ops
->
socket
(
input_pf
->
family
,
sock
->
type
,
sock
->
protocol
);
if
(
new_socket
<
0
)
{
return
-
1
;
}
sock
->
netdev
=
new_netdev
;
sock
->
user_data
=
(
void
*
)
new_socket
;
}
sock
->
netdev
=
new_netdev
;
sock
->
user_data
=
(
void
*
)
new_socket
;
}
/* check
the network interface socket opreation
*/
/* check
and get protocol families by the network interface device
*/
SAL_NETDEV_SOCKETOPS_VALID
(
sock
->
netdev
,
pf
,
bind
);
return
pf
->
skt_ops
->
bind
((
int
)
sock
->
user_data
,
name
,
namelen
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录