提交 3ac69fe1 编写于 作者: Peacoor Zomboss's avatar Peacoor Zomboss

Bug fix for IP address enum

这个bug不会造成错误,但是会一定程度影响性能,尽管微乎其微。
上级 2fcf59c2
......@@ -12,23 +12,25 @@ Hook *sendto_hook;
SockQueue sockqueue;
// 枚举当前所有可用网卡的IPv4地址
const std::vector<in_addr> &enum_addr()
static const std::vector<in_addr> &enum_addr()
{
static std::vector<in_addr> list;
hostent *phost = gethostbyname(""); // 获取本机网卡
if (phost) {
if (phost->h_length == list.size()) // 数量相同直接返回
return list;
char **ppc = phost->h_addr_list; // 获取地址列表
if (ppc) {
list.clear();
// 遍历列表添加到容器
while (*ppc) {
in_addr addr;
memcpy(&addr, *ppc, sizeof(in_addr));
list.push_back(addr);
ppc++;
}
int addr_num = 0;
while (*ppc)
addr_num++, ppc++; // 获取地址个数
if (addr_num == list.size()) // 数量相同直接返回
return list;
ppc = phost->h_addr_list;
list.clear();
// 遍历列表添加到容器
while (*ppc) {
in_addr addr;
memcpy(&addr, *ppc, sizeof(in_addr));
list.push_back(addr);
ppc++;
}
}
return list;
......
......@@ -22,18 +22,20 @@ static const std::vector<in_addr> &enum_addr()
static std::vector<in_addr> list;
hostent *phost = gethostbyname(""); // 获取本机网卡
if (phost) {
if (phost->h_length == list.size()) // 数量相同直接返回
return list;
char **ppc = phost->h_addr_list; // 获取地址列表
if (ppc) {
list.clear();
// 遍历列表添加到容器
while (*ppc) {
in_addr addr;
memcpy(&addr, *ppc, sizeof(in_addr));
list.push_back(addr);
ppc++;
}
int addr_num = 0;
while (*ppc)
addr_num++, ppc++; // 获取地址个数
if (addr_num == list.size()) // 数量相同直接返回
return list;
ppc = phost->h_addr_list;
list.clear();
// 遍历列表添加到容器
while (*ppc) {
in_addr addr;
memcpy(&addr, *ppc, sizeof(in_addr));
list.push_back(addr);
ppc++;
}
}
return list;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册