You need to install libcurl in order to compile the program.
Also the example below is written in C++11, so you will need to install g++-4.7, which supports C++11.
The source code above is a wrapping class for libcurl easy-functions. You can find document from here. There are three functions from libcurl:
- curl_easy_init() : will create an handle for CURL,
- curl_easy_setopt() : will allow us to set options such as user id and URL and
- curl_easy_perform() : will allow us to execute whatever options you set.
There are several options with curl_easy_setopt() and that was little tricky part:
- CURLOPT_URL : is for setting the URL,
- CURLOPT_USERPWD : is for setting user ID and Password,
- CURLOPT_WRITEFUNCTION : is to set a function pointer that will be called when HTML data is retrieved.
- CURLOPT_WRITEDATA : is to set a data point which will be used by a function set with CURLOPT_WRITEFUNCTION.
The source code also reveals my C++ programming style little bit.
- I like to have private member variable and methods to have "_" at the end of the name.
- I almost always hold member pointer with shared_ptr or unique_ptr; when I return the pointer to users, I return the raw-pointer not the share_ptr or unique_ptr so that the ownership remains.
- I use a lot of exceptions because it makes source code simpler.
The source code is an example of how to use the wrapping class. You will need to modify Configuration::PW or ID. You may need to modify the search patter depending on what your Router send you.
I am using -std=c++11, which is supported only by 4.7 at the moment of writing this post.
*Note: don't be confused with gcc-4.7, which is C compiler not C++ compiler.
The Makefile uses pre-compiled-header, which improves a lot of compile time; the compiled file from the pre-compile-header is 14MB, which is very large.
You will get the executable, public_ip.