Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1467141 - Improved Bogo shim IPv4 fallback, r=franziskus
Differential Revision: https://phabricator.services.mozilla.com/D1567

--HG--
extra : rebase_source : ad6510c85182eadd264254c6e56eb14f87e76ffd
extra : amend_source : c72cbecdd3fdaef0d3d4ccd22300023c4f61c741
  • Loading branch information
Jonas Allmann committed Jun 20, 2018
1 parent 9459444 commit 4c04217
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions gtests/nss_bogo_shim/nss_bogo_shim.cc
Expand Up @@ -88,18 +88,30 @@ class TestAgent {
}

bool ConnectTcp() {
// Try IPv6 first, then IPv4 in case of failure.
if (!OpenConnection("::1") && !OpenConnection("127.0.0.1")) {
return false;
}

ssl_fd_ = SSL_ImportFD(NULL, pr_fd_);
if (!ssl_fd_) {
return false;
}
pr_fd_ = nullptr;

return true;
}

bool OpenConnection(const char* ip) {
PRStatus prv;
PRNetAddr addr;

// Try IPv6 first.
prv = PR_StringToNetAddr("::1", &addr);
prv = PR_StringToNetAddr(ip, &addr);

if (prv != PR_SUCCESS) {
// If that fails, try IPv4.
prv = PR_StringToNetAddr("127.0.0.1", &addr);
if (prv != PR_SUCCESS) {
return false;
}
return false;
}

addr.inet.port = PR_htons(cfg_.get<int>("port"));

pr_fd_ = PR_OpenTCPSocket(addr.raw.family);
Expand All @@ -109,11 +121,6 @@ class TestAgent {
if (prv != PR_SUCCESS) {
return false;
}

ssl_fd_ = SSL_ImportFD(NULL, pr_fd_);
if (!ssl_fd_) return false;
pr_fd_ = nullptr;

return true;
}

Expand Down

0 comments on commit 4c04217

Please sign in to comment.