Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_63117999
taskbus
提交
311faa37
taskbus
项目概览
m0_63117999
/
taskbus
与 Fork 源项目一致
Fork自
colorEagleStdio / taskbus
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
taskbus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
311faa37
编写于
12月 24, 2022
作者:
丁劲犇
😸
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
减少PCAP设备枚举时的文字长度,同时在出错后可继续工作。
上级
702804c0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
167 addition
and
134 deletion
+167
-134
modules/sinks/sink_pcap/pcapio.cpp
modules/sinks/sink_pcap/pcapio.cpp
+50
-34
modules/sources/source_pcap/pcapio.cpp
modules/sources/source_pcap/pcapio.cpp
+117
-100
未找到文件。
modules/sinks/sink_pcap/pcapio.cpp
浏览文件 @
311faa37
...
...
@@ -28,18 +28,24 @@ namespace PCAPIO{
{
std
::
string
res
;
char
buf
[
1024
];
int
left_start
=
0
,
right_end
=
sizeof
(
sockaddr
::
sa_data
)
-
1
;
while
(
left_start
+
3
<
right_end
&&
v
[
left_start
]
==
0
)
++
left_start
;
while
(
left_start
+
3
<
right_end
&&
v
[
right_end
]
==
0
)
--
right_end
;
res
+=
"HEX("
;
for
(
unsigned
char
i
=
0
;
i
<
sizeof
(
sockaddr
::
sa_data
)
;
++
i
)
for
(
unsigned
char
i
=
left_start
;
i
<=
right_end
;
++
i
)
{
if
(
i
)
res
+=
":"
;
if
(
i
-
left_start
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%02X"
,
(
unsigned
int
)
v
[
i
]);
res
+=
buf
;
}
res
+=
")"
;
res
+=
"DEC("
;
for
(
unsigned
char
i
=
0
;
i
<
sizeof
(
sockaddr
::
sa_data
)
;
++
i
)
for
(
unsigned
char
i
=
left_start
;
i
<=
right_end
;
++
i
)
{
if
(
i
)
res
+=
":"
;
if
(
i
-
left_start
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%u"
,
(
unsigned
int
)
v
[
i
]
);
res
+=
buf
;
}
...
...
@@ -106,7 +112,10 @@ void pcap_sink::run()
{
if
(
m_bStop
)
return
;
bool
bQuit
=
false
;
using
namespace
TASKBUS
;
while
(
false
==
m_bStop
)
{
pcap_t
*
handle
=
NULL
;
char
errbuf
[
PCAP_ERRBUF_SIZE
];
handle
=
pcap_open_live
(
m_device
.
c_str
(),
65535
,
1
,
10
,
errbuf
);
...
...
@@ -116,7 +125,6 @@ void pcap_sink::run()
emit
sig_message
(
err
);
return
;
}
bool
bQuit
=
false
;
m_tx
=
0
;
while
(
false
==
m_bStop
)
{
...
...
@@ -142,12 +150,20 @@ void pcap_sink::run()
}
else
if
(
header
.
subject_id
==
m_nSubject
)
{
pcap_sendpacket
(
handle
,
packagedta
.
data
(),
packagedta
.
size
());
if
(
PCAP_ERROR
==
pcap_sendpacket
(
handle
,
packagedta
.
data
(),
packagedta
.
size
()))
{
fprintf
(
stderr
,
pcap_geterr
(
handle
));
fprintf
(
stderr
,
"
\n
"
);
fflush
(
stderr
);
break
;
}
++
m_tx
;
}
}
}
pcap_close
(
handle
);
}
emit
sig_message
(
"Stopped"
);
if
(
bQuit
)
emit
quit_app
();
...
...
modules/sources/source_pcap/pcapio.cpp
浏览文件 @
311faa37
...
...
@@ -4,10 +4,10 @@
#include "tb_interface.h"
namespace
PCAPIO
{
std
::
string
ifaddresses
(
pcap_if_t
*
d
);
std
::
string
ifaddresses
(
pcap_if_t
*
d
);
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
)
{
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
)
{
std
::
string
res
;
pcap_if_t
*
alldevs
;
char
errbuf
[
PCAP_ERRBUF_SIZE
];
...
...
@@ -23,33 +23,39 @@ namespace PCAPIO{
pcap_freealldevs
(
alldevs
);
return
res
;
}
std
::
string
address_print
(
unsigned
char
*
v
)
{
}
std
::
string
address_print
(
unsigned
char
*
v
)
{
std
::
string
res
;
char
buf
[
1024
];
int
left_start
=
0
,
right_end
=
sizeof
(
sockaddr
::
sa_data
)
-
1
;
while
(
left_start
+
3
<
right_end
&&
v
[
left_start
]
==
0
)
++
left_start
;
while
(
left_start
+
3
<
right_end
&&
v
[
right_end
]
==
0
)
--
right_end
;
res
+=
"HEX("
;
for
(
unsigned
char
i
=
0
;
i
<
sizeof
(
sockaddr
::
sa_data
)
;
++
i
)
for
(
unsigned
char
i
=
left_start
;
i
<=
right_end
;
++
i
)
{
if
(
i
)
res
+=
":"
;
if
(
i
-
left_start
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%02X"
,
(
unsigned
int
)
v
[
i
]);
res
+=
buf
;
}
res
+=
")"
;
res
+=
"DEC("
;
for
(
unsigned
char
i
=
0
;
i
<
sizeof
(
sockaddr
::
sa_data
)
;
++
i
)
for
(
unsigned
char
i
=
left_start
;
i
<=
right_end
;
++
i
)
{
if
(
i
)
res
+=
":"
;
if
(
i
-
left_start
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%u"
,
(
unsigned
int
)
v
[
i
]
);
res
+=
buf
;
}
res
+=
")"
;
return
res
;
}
/* Print all the available information on the given interface */
std
::
string
ifaddresses
(
pcap_if_t
*
d
)
{
}
/* Print all the available information on the given interface */
std
::
string
ifaddresses
(
pcap_if_t
*
d
)
{
char
buf
[
1024
];
pcap_addr_t
*
a
;
std
::
string
res
;
...
...
@@ -76,7 +82,7 @@ namespace PCAPIO{
}
}
return
res
;
}
}
}
pcap_source
::
pcap_source
(
QObject
*
parent
)
...
...
@@ -106,6 +112,8 @@ void pcap_source::run()
{
if
(
m_bStop
)
return
;
while
(
!
m_bStop
)
{
pcap_t
*
handle
=
NULL
;
char
errbuf
[
PCAP_ERRBUF_SIZE
];
handle
=
pcap_open_live
(
m_device
.
c_str
(),
65535
,
1
,
10
,
errbuf
);
...
...
@@ -148,7 +156,16 @@ void pcap_source::run()
TASKBUS
::
push_subject
(
m_nSubject
,
m_nInstance
,
header
.
len
,(
unsigned
char
*
)
packet
);
}
else
{
fprintf
(
stderr
,
pcap_geterr
(
handle
));
fprintf
(
stderr
,
"
\n
"
);
fflush
(
stderr
);
break
;
}
}
pcap_close
(
handle
);
}
emit
sig_message
(
"Cap Stopped"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录