-
-
Save tarickb/efdb09f42460cf53e1c6f7b8538d8af6 to your computer and use it in GitHub Desktop.
sasl-xoauth2: force ipv4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/config.cc b/src/config.cc | |
index 6bd780c..1f4d3bf 100644 | |
--- a/src/config.cc | |
+++ b/src/config.cc | |
@@ -148,6 +148,9 @@ int Config::Init(const Json::Value &root) { | |
&log_full_trace_on_failure_); | |
if (err != SASL_OK) return err; | |
+ err = Fetch(root, "force_ipv4", true, &force_ipv4_); | |
+ if (err != SASL_OK) return err; | |
+ | |
return 0; | |
} catch (const std::exception &e) { | |
diff --git a/src/config.h b/src/config.h | |
index 2268b6b..9e8c2f2 100644 | |
--- a/src/config.h | |
+++ b/src/config.h | |
@@ -33,6 +33,7 @@ class Config { | |
std::string client_secret() const { return client_secret_; } | |
bool log_to_syslog_on_failure() const { return log_to_syslog_on_failure_; } | |
bool log_full_trace_on_failure() const { return log_full_trace_on_failure_; } | |
+ bool force_ipv4() const { return force_ipv4_; } | |
private: | |
Config() = default; | |
@@ -43,6 +44,7 @@ class Config { | |
std::string client_secret_; | |
bool log_to_syslog_on_failure_ = true; | |
bool log_full_trace_on_failure_ = false; | |
+ bool force_ipv4_ = false; | |
}; | |
} // namespace sasl_xoauth2 | |
diff --git a/src/http.cc b/src/http.cc | |
index 25bc36f..6bbbed0 100644 | |
--- a/src/http.cc | |
+++ b/src/http.cc | |
@@ -20,6 +20,8 @@ | |
#include <vector> | |
+#include "config.h" | |
+ | |
namespace sasl_xoauth2 { | |
namespace { | |
@@ -113,6 +115,11 @@ int HttpPost(const std::string &url, const std::string &data, | |
// Errors. | |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, transport_error); | |
+ // IPv4/IPv6 | |
+ if (Config::Get()->force_ipv4()) { | |
+ curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); | |
+ } | |
+ | |
// Network. | |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment