Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
7a0e9c3f
R
rt-thread
项目概览
BaiXuePrincess
/
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看板
提交
7a0e9c3f
编写于
6月 14, 2014
作者:
wuyangyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format code Astyle.
上级
9ab59cf1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
218 addition
and
218 deletion
+218
-218
components/net/lwip-1.3.2/apps/ping.c
components/net/lwip-1.3.2/apps/ping.c
+109
-109
components/net/lwip/apps/ping.c
components/net/lwip/apps/ping.c
+109
-109
未找到文件。
components/net/lwip-1.3.2/apps/ping.c
浏览文件 @
7a0e9c3f
...
...
@@ -39,140 +39,140 @@
static
u16_t
ping_seq_num
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
};
/** Prepare a echo ICMP request */
static
void
ping_prepare_echo
(
struct
icmp_echo_hdr
*
iecho
,
u16_t
len
)
{
size_t
i
;
size_t
data_len
=
len
-
sizeof
(
struct
icmp_echo_hdr
);
ICMPH_TYPE_SET
(
iecho
,
ICMP_ECHO
);
ICMPH_CODE_SET
(
iecho
,
0
);
iecho
->
chksum
=
0
;
iecho
->
id
=
PING_ID
;
iecho
->
seqno
=
htons
(
++
ping_seq_num
);
/* fill the additional data buffer with some data */
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
((
char
*
)
iecho
)[
sizeof
(
struct
icmp_echo_hdr
)
+
i
]
=
(
char
)
i
;
}
iecho
->
chksum
=
inet_chksum
(
iecho
,
len
);
size_t
i
;
size_t
data_len
=
len
-
sizeof
(
struct
icmp_echo_hdr
);
ICMPH_TYPE_SET
(
iecho
,
ICMP_ECHO
);
ICMPH_CODE_SET
(
iecho
,
0
);
iecho
->
chksum
=
0
;
iecho
->
id
=
PING_ID
;
iecho
->
seqno
=
htons
(
++
ping_seq_num
);
/* fill the additional data buffer with some data */
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
((
char
*
)
iecho
)[
sizeof
(
struct
icmp_echo_hdr
)
+
i
]
=
(
char
)
i
;
}
iecho
->
chksum
=
inet_chksum
(
iecho
,
len
);
}
/* Ping using the socket ip */
static
err_t
ping_send
(
int
s
,
struct
ip_addr
*
addr
,
int
size
)
{
int
err
;
struct
icmp_echo_hdr
*
iecho
;
struct
sockaddr_in
to
;
size_t
ping_size
=
sizeof
(
struct
icmp_echo_hdr
)
+
size
;
LWIP_ASSERT
(
"ping_size is too big"
,
ping_size
<=
0xffff
);
int
err
;
struct
icmp_echo_hdr
*
iecho
;
struct
sockaddr_in
to
;
size_t
ping_size
=
sizeof
(
struct
icmp_echo_hdr
)
+
size
;
LWIP_ASSERT
(
"ping_size is too big"
,
ping_size
<=
0xffff
);
iecho
=
rt_malloc
(
ping_size
);
if
(
iecho
==
RT_NULL
)
{
return
ERR_MEM
;
}
iecho
=
rt_malloc
(
ping_size
);
if
(
iecho
==
RT_NULL
)
{
return
ERR_MEM
;
}
ping_prepare_echo
(
iecho
,
(
u16_t
)
ping_size
);
ping_prepare_echo
(
iecho
,
(
u16_t
)
ping_size
);
to
.
sin_len
=
sizeof
(
to
);
to
.
sin_family
=
AF_INET
;
to
.
sin_addr
.
s_addr
=
addr
->
addr
;
to
.
sin_len
=
sizeof
(
to
);
to
.
sin_family
=
AF_INET
;
to
.
sin_addr
.
s_addr
=
addr
->
addr
;
err
=
lwip_sendto
(
s
,
iecho
,
ping_size
,
0
,
(
struct
sockaddr
*
)
&
to
,
sizeof
(
to
));
rt_free
(
iecho
);
err
=
lwip_sendto
(
s
,
iecho
,
ping_size
,
0
,
(
struct
sockaddr
*
)
&
to
,
sizeof
(
to
));
rt_free
(
iecho
);
return
(
err
?
ERR_OK
:
ERR_VAL
);
return
(
err
?
ERR_OK
:
ERR_VAL
);
}
static
void
ping_recv
(
int
s
)
{
char
buf
[
64
];
int
fromlen
,
len
;
struct
sockaddr_in
from
;
struct
ip_hdr
*
iphdr
;
struct
icmp_echo_hdr
*
iecho
;
struct
_ip_addr
*
addr
;
while
((
len
=
lwip_recvfrom
(
s
,
buf
,
sizeof
(
buf
),
0
,
(
struct
sockaddr
*
)
&
from
,
(
socklen_t
*
)
&
fromlen
))
>
0
)
{
if
(
len
>=
(
sizeof
(
struct
ip_hdr
)
+
sizeof
(
struct
icmp_echo_hdr
)))
{
addr
=
(
struct
_ip_addr
*
)
&
(
from
.
sin_addr
);
rt_kprintf
(
"ping: recv %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
iphdr
=
(
struct
ip_hdr
*
)
buf
;
iecho
=
(
struct
icmp_echo_hdr
*
)(
buf
+
(
IPH_HL
(
iphdr
)
*
4
));
if
((
iecho
->
id
==
PING_ID
)
&&
(
iecho
->
seqno
==
htons
(
ping_seq_num
)))
{
return
;
}
else
{
rt_kprintf
(
"ping: drop
\n
"
);
}
}
}
if
(
len
<=
0
)
{
rt_kprintf
(
"ping: timeout
\n
"
);
}
char
buf
[
64
];
int
fromlen
,
len
;
struct
sockaddr_in
from
;
struct
ip_hdr
*
iphdr
;
struct
icmp_echo_hdr
*
iecho
;
struct
_ip_addr
*
addr
;
while
((
len
=
lwip_recvfrom
(
s
,
buf
,
sizeof
(
buf
),
0
,
(
struct
sockaddr
*
)
&
from
,
(
socklen_t
*
)
&
fromlen
))
>
0
)
{
if
(
len
>=
(
sizeof
(
struct
ip_hdr
)
+
sizeof
(
struct
icmp_echo_hdr
)))
{
addr
=
(
struct
_ip_addr
*
)
&
(
from
.
sin_addr
);
rt_kprintf
(
"ping: recv %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
iphdr
=
(
struct
ip_hdr
*
)
buf
;
iecho
=
(
struct
icmp_echo_hdr
*
)(
buf
+
(
IPH_HL
(
iphdr
)
*
4
));
if
((
iecho
->
id
==
PING_ID
)
&&
(
iecho
->
seqno
==
htons
(
ping_seq_num
)))
{
return
;
}
else
{
rt_kprintf
(
"ping: drop
\n
"
);
}
}
}
if
(
len
<=
0
)
{
rt_kprintf
(
"ping: timeout
\n
"
);
}
}
rt_err_t
ping
(
char
*
target
,
rt_uint32_t
time
,
rt_size_t
size
)
{
int
s
;
int
timeout
=
PING_RCV_TIMEO
;
struct
ip_addr
ping_target
;
rt_uint32_t
send_time
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
}
*
addr
;
int
s
;
int
timeout
=
PING_RCV_TIMEO
;
struct
ip_addr
ping_target
;
rt_uint32_t
send_time
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
}
*
addr
;
send_time
=
0
;
if
(
size
==
0
)
size
=
PING_DATA_SIZE
;
if
(
inet_aton
(
target
,
(
struct
in_addr
*
)
&
ping_target
)
==
0
)
return
-
RT_ERROR
;
addr
=
(
struct
_ip_addr
*
)
&
ping_target
;
if
((
s
=
lwip_socket
(
AF_INET
,
SOCK_RAW
,
IP_PROTO_ICMP
))
<
0
)
{
rt_kprintf
(
"create socket failled
\n
"
);
return
-
RT_ERROR
;
}
lwip_setsockopt
(
s
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
while
(
1
)
{
if
(
ping_send
(
s
,
&
ping_target
,
size
)
==
ERR_OK
)
{
rt_kprintf
(
"ping: send %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
ping_recv
(
s
);
}
else
{
rt_kprintf
(
"ping: send %d.%d.%d.%d - error
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
}
send_time
++
;
if
(
send_time
>=
time
)
break
;
/* send ping times reached, stop */
rt_thread_delay
(
PING_DELAY
);
/* take a delay */
}
lwip_close
(
s
);
return
RT_EOK
;
if
(
size
==
0
)
size
=
PING_DATA_SIZE
;
if
(
inet_aton
(
target
,
(
struct
in_addr
*
)
&
ping_target
)
==
0
)
return
-
RT_ERROR
;
addr
=
(
struct
_ip_addr
*
)
&
ping_target
;
if
((
s
=
lwip_socket
(
AF_INET
,
SOCK_RAW
,
IP_PROTO_ICMP
))
<
0
)
{
rt_kprintf
(
"create socket failled
\n
"
);
return
-
RT_ERROR
;
}
lwip_setsockopt
(
s
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
while
(
1
)
{
if
(
ping_send
(
s
,
&
ping_target
,
size
)
==
ERR_OK
)
{
rt_kprintf
(
"ping: send %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
ping_recv
(
s
);
}
else
{
rt_kprintf
(
"ping: send %d.%d.%d.%d - error
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
}
send_time
++
;
if
(
send_time
>=
time
)
break
;
/* send ping times reached, stop */
rt_thread_delay
(
PING_DELAY
);
/* take a delay */
}
lwip_close
(
s
);
return
RT_EOK
;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
...
...
components/net/lwip/apps/ping.c
浏览文件 @
7a0e9c3f
...
...
@@ -39,140 +39,140 @@
static
u16_t
ping_seq_num
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
};
/** Prepare a echo ICMP request */
static
void
ping_prepare_echo
(
struct
icmp_echo_hdr
*
iecho
,
u16_t
len
)
{
size_t
i
;
size_t
data_len
=
len
-
sizeof
(
struct
icmp_echo_hdr
);
ICMPH_TYPE_SET
(
iecho
,
ICMP_ECHO
);
ICMPH_CODE_SET
(
iecho
,
0
);
iecho
->
chksum
=
0
;
iecho
->
id
=
PING_ID
;
iecho
->
seqno
=
htons
(
++
ping_seq_num
);
/* fill the additional data buffer with some data */
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
((
char
*
)
iecho
)[
sizeof
(
struct
icmp_echo_hdr
)
+
i
]
=
(
char
)
i
;
}
iecho
->
chksum
=
inet_chksum
(
iecho
,
len
);
size_t
i
;
size_t
data_len
=
len
-
sizeof
(
struct
icmp_echo_hdr
);
ICMPH_TYPE_SET
(
iecho
,
ICMP_ECHO
);
ICMPH_CODE_SET
(
iecho
,
0
);
iecho
->
chksum
=
0
;
iecho
->
id
=
PING_ID
;
iecho
->
seqno
=
htons
(
++
ping_seq_num
);
/* fill the additional data buffer with some data */
for
(
i
=
0
;
i
<
data_len
;
i
++
)
{
((
char
*
)
iecho
)[
sizeof
(
struct
icmp_echo_hdr
)
+
i
]
=
(
char
)
i
;
}
iecho
->
chksum
=
inet_chksum
(
iecho
,
len
);
}
/* Ping using the socket ip */
static
err_t
ping_send
(
int
s
,
struct
ip_addr
*
addr
,
int
size
)
{
int
err
;
struct
icmp_echo_hdr
*
iecho
;
struct
sockaddr_in
to
;
size_t
ping_size
=
sizeof
(
struct
icmp_echo_hdr
)
+
size
;
LWIP_ASSERT
(
"ping_size is too big"
,
ping_size
<=
0xffff
);
int
err
;
struct
icmp_echo_hdr
*
iecho
;
struct
sockaddr_in
to
;
size_t
ping_size
=
sizeof
(
struct
icmp_echo_hdr
)
+
size
;
LWIP_ASSERT
(
"ping_size is too big"
,
ping_size
<=
0xffff
);
iecho
=
rt_malloc
(
ping_size
);
if
(
iecho
==
RT_NULL
)
{
return
ERR_MEM
;
}
iecho
=
rt_malloc
(
ping_size
);
if
(
iecho
==
RT_NULL
)
{
return
ERR_MEM
;
}
ping_prepare_echo
(
iecho
,
(
u16_t
)
ping_size
);
ping_prepare_echo
(
iecho
,
(
u16_t
)
ping_size
);
to
.
sin_len
=
sizeof
(
to
);
to
.
sin_family
=
AF_INET
;
to
.
sin_addr
.
s_addr
=
addr
->
addr
;
to
.
sin_len
=
sizeof
(
to
);
to
.
sin_family
=
AF_INET
;
to
.
sin_addr
.
s_addr
=
addr
->
addr
;
err
=
lwip_sendto
(
s
,
iecho
,
ping_size
,
0
,
(
struct
sockaddr
*
)
&
to
,
sizeof
(
to
));
rt_free
(
iecho
);
err
=
lwip_sendto
(
s
,
iecho
,
ping_size
,
0
,
(
struct
sockaddr
*
)
&
to
,
sizeof
(
to
));
rt_free
(
iecho
);
return
(
err
?
ERR_OK
:
ERR_VAL
);
return
(
err
?
ERR_OK
:
ERR_VAL
);
}
static
void
ping_recv
(
int
s
)
{
char
buf
[
64
];
int
fromlen
,
len
;
struct
sockaddr_in
from
;
struct
ip_hdr
*
iphdr
;
struct
icmp_echo_hdr
*
iecho
;
struct
_ip_addr
*
addr
;
while
((
len
=
lwip_recvfrom
(
s
,
buf
,
sizeof
(
buf
),
0
,
(
struct
sockaddr
*
)
&
from
,
(
socklen_t
*
)
&
fromlen
))
>
0
)
{
if
(
len
>=
(
sizeof
(
struct
ip_hdr
)
+
sizeof
(
struct
icmp_echo_hdr
)))
{
addr
=
(
struct
_ip_addr
*
)
&
(
from
.
sin_addr
);
rt_kprintf
(
"ping: recv %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
iphdr
=
(
struct
ip_hdr
*
)
buf
;
iecho
=
(
struct
icmp_echo_hdr
*
)(
buf
+
(
IPH_HL
(
iphdr
)
*
4
));
if
((
iecho
->
id
==
PING_ID
)
&&
(
iecho
->
seqno
==
htons
(
ping_seq_num
)))
{
return
;
}
else
{
rt_kprintf
(
"ping: drop
\n
"
);
}
}
}
if
(
len
<=
0
)
{
rt_kprintf
(
"ping: timeout
\n
"
);
}
char
buf
[
64
];
int
fromlen
,
len
;
struct
sockaddr_in
from
;
struct
ip_hdr
*
iphdr
;
struct
icmp_echo_hdr
*
iecho
;
struct
_ip_addr
*
addr
;
while
((
len
=
lwip_recvfrom
(
s
,
buf
,
sizeof
(
buf
),
0
,
(
struct
sockaddr
*
)
&
from
,
(
socklen_t
*
)
&
fromlen
))
>
0
)
{
if
(
len
>=
(
sizeof
(
struct
ip_hdr
)
+
sizeof
(
struct
icmp_echo_hdr
)))
{
addr
=
(
struct
_ip_addr
*
)
&
(
from
.
sin_addr
);
rt_kprintf
(
"ping: recv %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
iphdr
=
(
struct
ip_hdr
*
)
buf
;
iecho
=
(
struct
icmp_echo_hdr
*
)(
buf
+
(
IPH_HL
(
iphdr
)
*
4
));
if
((
iecho
->
id
==
PING_ID
)
&&
(
iecho
->
seqno
==
htons
(
ping_seq_num
)))
{
return
;
}
else
{
rt_kprintf
(
"ping: drop
\n
"
);
}
}
}
if
(
len
<=
0
)
{
rt_kprintf
(
"ping: timeout
\n
"
);
}
}
rt_err_t
ping
(
char
*
target
,
rt_uint32_t
time
,
rt_size_t
size
)
{
int
s
;
int
timeout
=
PING_RCV_TIMEO
;
struct
ip_addr
ping_target
;
rt_uint32_t
send_time
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
}
*
addr
;
int
s
;
int
timeout
=
PING_RCV_TIMEO
;
struct
ip_addr
ping_target
;
rt_uint32_t
send_time
;
struct
_ip_addr
{
rt_uint8_t
addr0
,
addr1
,
addr2
,
addr3
;
}
*
addr
;
send_time
=
0
;
if
(
size
==
0
)
size
=
PING_DATA_SIZE
;
if
(
inet_aton
(
target
,
(
struct
in_addr
*
)
&
ping_target
)
==
0
)
return
-
RT_ERROR
;
addr
=
(
struct
_ip_addr
*
)
&
ping_target
;
if
((
s
=
lwip_socket
(
AF_INET
,
SOCK_RAW
,
IP_PROTO_ICMP
))
<
0
)
{
rt_kprintf
(
"create socket failled
\n
"
);
return
-
RT_ERROR
;
}
lwip_setsockopt
(
s
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
while
(
1
)
{
if
(
ping_send
(
s
,
&
ping_target
,
size
)
==
ERR_OK
)
{
rt_kprintf
(
"ping: send %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
ping_recv
(
s
);
}
else
{
rt_kprintf
(
"ping: send %d.%d.%d.%d - error
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
}
send_time
++
;
if
(
send_time
>=
time
)
break
;
/* send ping times reached, stop */
rt_thread_delay
(
PING_DELAY
);
/* take a delay */
}
lwip_close
(
s
);
return
RT_EOK
;
if
(
size
==
0
)
size
=
PING_DATA_SIZE
;
if
(
inet_aton
(
target
,
(
struct
in_addr
*
)
&
ping_target
)
==
0
)
return
-
RT_ERROR
;
addr
=
(
struct
_ip_addr
*
)
&
ping_target
;
if
((
s
=
lwip_socket
(
AF_INET
,
SOCK_RAW
,
IP_PROTO_ICMP
))
<
0
)
{
rt_kprintf
(
"create socket failled
\n
"
);
return
-
RT_ERROR
;
}
lwip_setsockopt
(
s
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
while
(
1
)
{
if
(
ping_send
(
s
,
&
ping_target
,
size
)
==
ERR_OK
)
{
rt_kprintf
(
"ping: send %d.%d.%d.%d
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
ping_recv
(
s
);
}
else
{
rt_kprintf
(
"ping: send %d.%d.%d.%d - error
\n
"
,
addr
->
addr0
,
addr
->
addr1
,
addr
->
addr2
,
addr
->
addr3
);
}
send_time
++
;
if
(
send_time
>=
time
)
break
;
/* send ping times reached, stop */
rt_thread_delay
(
PING_DELAY
);
/* take a delay */
}
lwip_close
(
s
);
return
RT_EOK
;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录