Skip to content

Commit

Permalink
[main]
Browse files Browse the repository at this point in the history
* checkInternetAccess change return codes to:

host success = 0
DNS error = 1
other error = 2
no link = 3
no active adapter = 4

(cherry picked from commit a7a548b)
  • Loading branch information
jbleyel committed Jun 18, 2023
1 parent f787ba1 commit 2052c06
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions main/enigma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ int checkLinkStatus()
if (interface.empty())
{
eDebug("[Enigma] checkLinkStatus: No valid active network adapter.");
return 0;
return 4;
}

int sock;
Expand All @@ -563,7 +563,7 @@ int checkLinkStatus()
if (sock < 0)
{
eDebug("[Enigma] checkLinkStatus: Failed to create socket.");
return 0;
return 3;
}
// Set the interface name
strncpy(ifr.ifr_name, interface.c_str(), IFNAMSIZ);
Expand All @@ -572,9 +572,9 @@ int checkLinkStatus()
{
eDebug("[Enigma] checkLinkStatus: Failed to get interface flags.");
close(sock);
return 0;
return 3;
}
int ret = (ifr.ifr_flags & IFF_RUNNING) ? 1 : 0;
int ret = (ifr.ifr_flags & IFF_RUNNING) ? 0 : 3;
close(sock);
return ret;
}
Expand All @@ -593,15 +593,15 @@ int checkInternetAccess(const char *host, int timeout = 3)
{

int link = checkLinkStatus();
if (link == 0)
if (link != 0)
{
eDebug("[Enigma] checkInternetAccess: No Active link.");
return 0;
return link;
}

CURL *curl;
CURLcode res;
int ret = 2;
int ret = 0; // SUCCESS
curl = curl_easy_init();
if (curl)
{
Expand All @@ -615,28 +615,31 @@ int checkInternetAccess(const char *host, int timeout = 3)
{
switch (res)
{
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_HOST:
eDebug("[Enigma] checkInternetAccess: Failed to resolve host.");
ret = 1;
break;
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_PROXY:
eDebug("[Enigma] checkInternetAccess: Failed.");
ret = 1;
ret = 2;
break;
default:
eDebug("[Enigma] checkInternetAccess: Failed with error (%s).", curl_easy_strerror(res));
ret = 1;
ret = 2;
break;
}
if (ret == 1)
if (ret > 0)
break;
}
curl_easy_cleanup(curl);
}
else
{
eDebug("[Enigma] checkInternetAccess: Failed to init curl.");
return 1;
return 2;
}
if (ret == 2)
if (ret == 0)
eDebug("[Enigma] checkInternetAccess: Success.");
return ret;
}

0 comments on commit 2052c06

Please sign in to comment.