Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colorEagleStdio
qtcpp_demo
提交
dcb12710
qtcpp_demo
项目概览
colorEagleStdio
/
qtcpp_demo
通知
465
Star
24
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
qtcpp_demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dcb12710
编写于
8月 12, 2022
作者:
D
dev@dev.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Format Change for PCAP enum
上级
7a278f81
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
84 deletion
+70
-84
pcapio/pcapio.cpp
pcapio/pcapio.cpp
+69
-83
pcapio/pcapio.h
pcapio/pcapio.h
+1
-1
未找到文件。
pcapio/pcapio.cpp
浏览文件 @
dcb12710
...
...
@@ -2,105 +2,91 @@
#include <pcap.h>
#include <string.h>
namespace
PCAPIO
{
std
::
string
ifaddresses
(
pcap_if_t
*
d
);
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
)
{
std
::
string
res
;
pcap_if_t
*
alldevs
;
char
errbuf
[
PCAP_ERRBUF_SIZE
];
if
(
pcap_findalldevs
(
&
alldevs
,
errbuf
)
==
-
1
){
res
=
errbuf
;
return
res
;
}
for
(
auto
d
=
alldevs
;
d
!=
NULL
;
d
=
d
->
next
){
std
::
string
d_name
=
d
->
name
;
std
::
string
d_des
=
ifaddresses
(
d
);
devmap
[
d_name
]
=
d_des
;
}
std
::
string
ifaddresses
(
pcap_if_t
*
d
);
pcap_freealldevs
(
alldevs
);
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
)
{
std
::
string
res
;
pcap_if_t
*
alldevs
;
char
errbuf
[
PCAP_ERRBUF_SIZE
];
if
(
pcap_findalldevs
(
&
alldevs
,
errbuf
)
==
-
1
){
res
=
errbuf
;
return
res
;
}
std
::
string
address_print
(
unsigned
char
*
v
)
for
(
auto
d
=
alldevs
;
d
!=
NULL
;
d
=
d
->
next
){
std
::
string
d_name
=
d
->
name
;
std
::
string
d_des
=
ifaddresses
(
d
);
devmap
[
d_name
]
=
d_des
;
}
pcap_freealldevs
(
alldevs
);
return
res
;
}
std
::
string
address_print
(
unsigned
char
*
v
)
{
std
::
string
res
;
char
buf
[
1024
];
res
+=
"HEX("
;
for
(
unsigned
char
i
=
0
;
i
<
sizeof
(
sockaddr
::
sa_data
);
++
i
)
{
std
::
string
res
;
char
buf
[
1024
];
int
lbegin
=
0
,
rbegin
=
13
;
while
(
!
v
[
lbegin
]
)
{
++
lbegin
;
if
(
lbegin
>=
rbegin
)
break
;
}
while
(
!
v
[
rbegin
]
)
if
(
i
)
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
)
{
if
(
i
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%03u"
,
(
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
)
{
char
buf
[
1024
];
pcap_addr_t
*
a
;
std
::
string
res
=
"NAME="
;
res
+=
d
->
name
;
res
+=
"
\n
"
;
if
(
d
->
description
)
{
res
+=
"Description="
;
res
+=
d
->
description
;
res
+=
"
\n
"
;
}
for
(
a
=
d
->
addresses
;
a
;
a
=
a
->
next
)
{
snprintf
(
buf
,
1024
,
" AF_0x%02X:"
,(
unsigned
int
)
a
->
addr
->
sa_family
);
res
+=
buf
;
if
(
a
->
addr
)
{
--
rbegin
;
if
(
lbegin
>=
rbegin
)
break
;
snprintf
(
buf
,
1024
,
"
\n
Addr:%s "
,
address_print
((
unsigned
char
*
)
a
->
addr
->
sa_data
).
c_str
());
res
+=
buf
;
}
res
+=
"HEX("
;
for
(
int
i
=
lbegin
;
i
<=
rbegin
;
++
i
)
if
(
a
->
netmask
)
{
if
(
i
>
lbegin
)
res
+=
":"
;
snprintf
(
buf
,
1024
,
"%02X"
,
(
unsigned
int
)
v
[
i
]);
snprintf
(
buf
,
1024
,
"
\n
Mask:%s "
,
address_print
((
unsigned
char
*
)
a
->
netmask
->
sa_data
).
c_str
());
res
+=
buf
;
}
res
+=
")"
;
res
+=
"DEC("
;
for
(
int
i
=
lbegin
;
i
<=
rbegin
;
++
i
)
if
(
a
->
broadaddr
)
{
if
(
i
>
lbegin
)
res
+=
"."
;
snprintf
(
buf
,
1024
,
"%u"
,
(
unsigned
int
)
v
[
i
]
);
snprintf
(
buf
,
1024
,
"
\n
Cast:%s "
,
address_print
((
unsigned
char
*
)
a
->
broadaddr
->
sa_data
).
c_str
());
res
+=
buf
;
}
res
+=
")"
;
return
res
;
}
/* 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
=
"NAME="
;
res
+=
d
->
name
;
res
+=
"
\n
"
;
if
(
d
->
description
)
if
(
a
->
dstaddr
)
{
res
+=
"Description="
;
res
+=
d
->
description
;
res
+=
"
\n
"
;
}
for
(
a
=
d
->
addresses
;
a
;
a
=
a
->
next
)
{
snprintf
(
buf
,
1024
,
" AF_0x%02X:"
,(
unsigned
int
)
a
->
addr
->
sa_family
);
snprintf
(
buf
,
1024
,
"
\n
Dest:%s "
,
address_print
((
unsigned
char
*
)
a
->
dstaddr
->
sa_data
).
c_str
());
res
+=
buf
;
if
(
a
->
addr
)
{
snprintf
(
buf
,
1024
,
"
\n
Addr:%s "
,
address_print
((
unsigned
char
*
)
a
->
addr
->
sa_data
).
c_str
());
res
+=
buf
;
}
if
(
a
->
netmask
)
{
snprintf
(
buf
,
1024
,
"
\n
Mask:%s "
,
address_print
((
unsigned
char
*
)
a
->
addr
->
sa_data
).
c_str
());
res
+=
buf
;
}
if
(
a
->
broadaddr
)
{
snprintf
(
buf
,
1024
,
"
\n
Cast:%s "
,
address_print
((
unsigned
char
*
)
a
->
addr
->
sa_data
).
c_str
());
res
+=
buf
;
}
if
(
a
->
dstaddr
)
{
snprintf
(
buf
,
1024
,
"
\n
Dest:%s "
,
address_print
((
unsigned
char
*
)
a
->
addr
->
sa_data
).
c_str
());
res
+=
buf
;
}
res
+=
"
\n
"
;
}
re
turn
res
;
re
s
+=
"
\n
"
;
}
return
res
;
}
}
pcapio/pcapio.h
浏览文件 @
dcb12710
...
...
@@ -5,7 +5,7 @@
namespace
PCAPIO
{
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
);
std
::
string
pcapio_interfaces
(
std
::
map
<
std
::
string
,
std
::
string
>
&
devmap
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录