8000 fix bug when IPv6 nameserver in resolv.conf by Barenboim · Pull Request #520 · sogou/workflow · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix bug when IPv6 nameserver in resolv.conf #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/WFDnsClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int WFDnsClient::init(const std::string& url, const std::string& search_list,
id = 0;
hosts = StringUtil::split_filter_empty(url, ',');

for(size_t i = 0; i < hosts.size(); i++)
for (size_t i = 0; i < hosts.size(); i++)
{
host = hosts[i];
if (strncasecmp(host.c_str(), "dns://", 6) != 0 &&
Expand Down
19 changes: 15 additions & 4 deletions src/manager/WFGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <string>
#include <unordered_map>
#include <atomic>
Expand Down Expand Up @@ -560,7 +561,8 @@ class __NameServiceManager
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#define HOSTS_LINEBUF_INIT_SIZE 128

static void __split_merge_str(const char *p, std::string& result)
static void __split_merge_str(const char *p, bool is_nameserver,
std::string& result)
{
const char *start;

Expand All @@ -581,7 +583,16 @@ static void __split_merge_str(const char *p, std::string& result)

if (!result.empty())
result.push_back(',');
result.append(start, p);

std::string str(start, p);
if (is_nameserver)
{
struct in6_addr buf;
if (inet_pton(AF_INET6, str.c_str(), &buf) > 0)
str = "[" + str + "]";
}

result.append(str);
}
}

Expand Down Expand Up @@ -643,9 +654,9 @@ static int __parse_resolv_conf(const char *path,
{
const char *p = (const char *)line;
if (strncmp(p, "nameserver", 10) == 0)
__split_merge_str(p + 10, url);
__split_merge_str(p + 10, true, url);
else if (strncmp(p, "search", 6) == 0)
__split_merge_str(p + 6, search_list);
__split_merge_str(p + 6, false, search_list);
else if (strncmp(p, "options", 7) == 0)
__set_options(p + 7, ndots, attempts, rotate);
}
Expand Down
0