Skip to content

Commit

Permalink
nix: Fix haveInternet to check for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ramboman committed Feb 23, 2024
1 parent 6a5210f commit d3bff69
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <netdb.h>
#include <netinet/in.h>
#include <regex>
#include <cstdlib>

#include <nlohmann/json.hpp>

Expand All @@ -32,6 +33,24 @@ void chrootHelper(int argc, char * * argv);

namespace nix {

static bool haveProxyEnvironmentVariables()
{
static const char * const proxyVariables[] = {
"http_proxy",
"https_proxy",
"ftp_proxy",
"HTTP_PROXY",
"HTTPS_PROXY",
"FTP_PROXY"
};
for (auto & proxyVariable: proxyVariables) {
if (std::getenv(proxyVariable)) {
return true;
}
}
return false;
}

/* Check if we have a non-loopback/link-local network interface. */
static bool haveInternet()
{
Expand All @@ -55,6 +74,8 @@ static bool haveInternet()
}
}

if (haveProxyEnvironmentVariables()) return true;

return false;
}

Expand Down

0 comments on commit d3bff69

Please sign in to comment.