Before using the Ecore_Con library, it needs to be initialized.
#include <Ecore_Con.h> // Init ecore_con library. int ret = ecore_con_init(); // ret is the number of times the library has been initialized // without shutdown.
We can do a simple DNS lookup using the following function:
EAPI Eina_Bool ecore_con_lookup(const char * name, Ecore_Con_Dns_Cb done_cb, const void * data )
in which:
name
: the IP address or the server name to translate;done_cb
: a callback to notify when the request is done;data
: the data to be passed to the callback.
The done_cb
function prototype is :
void done_cb(const char * canonname, const char * ip, struct sockaddr * addr, int addrlen, void * data )
where:
canonname
: the canonical name associated with the address;ip
: the resolved IP address;addr
: a pointer to the socket address;addrlen
: the length of the socket address, in bytes;data
: the data passed to the callback.
As an example, we want to know the canonical name of the 140.211.167.135 IP
address. Let’s first declare the done_cb
callback that will be called when
the DNS lookup will finish.
static void done_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen, void *data) { printf("140.211.167.135 name is %s\n", canonname); }
Then we can call the ecore_con_lookup()
function to do the query.
// Call ecore_con_lookup. ret = ecore_con_lookup("140.211.167.135", done_cb, NULL); // If ret is EINA_FALSE the request failed to set up.
When the request succeeds it shall call the done_cb()
callback that will
printthe name associated with the IP address we gave.
When the library is not be used anymore, it has to be shut down.
// Shutdown the library. ret = ecore_con_shutdown();