Skip to content

Commit

Permalink
error debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
https433 committed Mar 24, 2024
1 parent 1f2d323 commit 9c3e941
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions ipcv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ void print_pretty_json(const std::string& json) {
}

int main(int argc, char* argv[]) {
const char* ipurl = "https://if-config.io";
const char* ip_api_url = "http://ip-api.com/json/";
const char* url = "https://if-config.co";
const char* ip_api_url = "http://ip-api.com/json";
std::string response;
long http_code = 0;

bool pretty_flag = false, json_flag = false;
for (int i = 1; i < argc; ++i) {
Expand All @@ -37,7 +38,11 @@ int main(int argc, char* argv[]) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_perform(curl);
print_pretty_json(response);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200)
print_pretty_json(response);
else
std::cerr << "HTTP Error: " << http_code << std::endl;
curl_easy_cleanup(curl);
}
else if (json_flag) {
Expand All @@ -46,16 +51,24 @@ int main(int argc, char* argv[]) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_perform(curl);
std::cout << response << std::endl;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200)
std::cout << response << std::endl;
else
std::cerr << "HTTP Error: " << http_code << std::endl;
curl_easy_cleanup(curl);
}
else {
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, ipurl);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_perform(curl);
std::cout << "IP: " << response << std::endl;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200)
std::cout << "IP: " << response << std::endl;
else
std::cerr << "HTTP Error: " << http_code << std::endl;
curl_easy_cleanup(curl);
}

Expand Down

0 comments on commit 9c3e941

Please sign in to comment.