Validate a Domain Name in C/C++

Running a business means that you are always a target for potential security threats; these can be made via phishing attempts, viruses, spyware, and a whole army of other risks. In this brief article, we will discuss how you can use an API in C/C++ to validate a domain name and protect your organization and client base from these risks. The process is achieved by contacting DNS services to perform a live validation, which will ensure that the response is consistently current and accurate. By performing this action, you can instantly find out if the input domain name is correct.

To start things off, we will need to install libcurl into the project:


Next, we can call the validation function with the following code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "\"<string>\"";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);

Done! Your result will indicate the validity of the domain name in question.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store