diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 15:27:50 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 15:27:50 +0000 |
commit | 0d1f4c47457e4f38ff79433783d79795eb5aad59 (patch) | |
tree | 11ee74402900880cf69d79441caaaa629ad5ce1f /net/base/net_util.cc | |
parent | ca1abf67762946dca6b8988a16d027b650c9042e (diff) | |
download | chromium_src-0d1f4c47457e4f38ff79433783d79795eb5aad59.zip chromium_src-0d1f4c47457e4f38ff79433783d79795eb5aad59.tar.gz chromium_src-0d1f4c47457e4f38ff79433783d79795eb5aad59.tar.bz2 |
Prefer IPv4 in the ConnectBackupJob to work around broken IPv6 networks
where connects take a long time to fail.
R=eroman@chromium.org,mbelshe@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6905080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84251 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r-- | net/base/net_util.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 5c7aab4..e97cb7f 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -911,6 +911,14 @@ void AppendFormattedComponent(const std::string& spec, } } +char* do_strdup(const char* src) { +#if defined(OS_WIN) + return _strdup(src); +#else + return strdup(src); +#endif +} + } // namespace const FormatUrlType kFormatUrlOmitNothing = 0; @@ -2075,6 +2083,51 @@ bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, return true; } +struct addrinfo* CreateCopyOfAddrinfo(const struct addrinfo* info, + bool recursive) { + DCHECK(info); + struct addrinfo* copy = new addrinfo; + + // Copy all the fields (some of these are pointers, we will fix that next). + memcpy(copy, info, sizeof(addrinfo)); + + // ai_canonname is a NULL-terminated string. + if (info->ai_canonname) { + copy->ai_canonname = do_strdup(info->ai_canonname); + } + + // ai_addr is a buffer of length ai_addrlen. + if (info->ai_addr) { + copy->ai_addr = reinterpret_cast<sockaddr *>(new char[info->ai_addrlen]); + memcpy(copy->ai_addr, info->ai_addr, info->ai_addrlen); + } + + // Recursive copy. + if (recursive && info->ai_next) + copy->ai_next = CreateCopyOfAddrinfo(info->ai_next, recursive); + else + copy->ai_next = NULL; + + return copy; +} + +void FreeCopyOfAddrinfo(struct addrinfo* info) { + DCHECK(info); + if (info->ai_canonname) + free(info->ai_canonname); // Allocated by strdup. + + if (info->ai_addr) + delete [] reinterpret_cast<char*>(info->ai_addr); + + struct addrinfo* next = info->ai_next; + + delete info; + + // Recursive free. + if (next) + FreeCopyOfAddrinfo(next); +} + // Returns the port field of the sockaddr in |info|. uint16* GetPortFieldFromAddrinfo(struct addrinfo* info) { const struct addrinfo* const_info = info; |