Ecore_Con - DNS lookup

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

Ecore_Con - DNS lookup

This is a very simple example that shows how to make a simple DNS lookup using ecore_con_lookup().

It's possible to see in the beginning of the main function that we are using the arguments passed via command line. This is the address that we are going to make the DNS lookup on.

The next step is to initialize the libraries, and just call ecore_con_lookup(). This function will get the string that contains the address to be resolved as first parameter, then a callback that will be called when the resolve stage is done, and finally a data pointer that will be passed to the callback.

This function is asynchronous, and the callback will be called only on success. If there was an error during the resolve stage, there's no way to know about that. It's only possible to know about errors when setting up the lookup, by looking at the return code of the ecore_con_lookup() function.

The callback `_lookup_done_cb` passed as argument to ecore_con_lookup() just prints the resolved canonical name, IP, address of the sockaddr structure, and the length of the socket address (in bytes).

Finally, we start the main loop, and after that we finalize the libraries and exit.

This is the code for this simple example:

//Compile with:
// gcc -o ecore_con_lookup_example ecore_con_lookup_example.c `pkg-config --libs --cflags ecore ecore-con`
#include <stdio.h>
#include <Ecore.h>
#include <Ecore_Con.h>
static void
_lookup_done_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen EINA_UNUSED, void *data EINA_UNUSED)
{
printf("canonname = %s\n", canonname);
printf("ip = %s\n", ip);
printf("addr = %p\n", addr);
ecore_main_loop_quit();
}
int
main(int argc, const char *argv[])
{
if (argc < 2)
{
printf("need one parameter: <address>\n");
return -1;
}
ecore_con_init();
if (!ecore_con_lookup(argv[1], _lookup_done_cb, NULL))
{
printf("error when trying to start lookup for %s\n", argv[1]);
goto end;
}
ecore_main_loop_begin();
end:
ecore_con_shutdown();
return 0;
}
ecore_con_shutdown
ECORE_CON_API int ecore_con_shutdown(void)
Shuts down the Ecore_Con library.
Definition: ecore_con.c:133
ecore_con_lookup
ECORE_CON_API Eina_Bool ecore_con_lookup(const char *name, Ecore_Con_Dns_Cb done_cb, const void *data)
Do an asynchronous DNS lookup.
Definition: ecore_con_legacy.c:2678
ecore_con_init
ECORE_CON_API int ecore_con_init(void)
Initializes the Ecore_Con library.
Definition: ecore_con.c:68
ecore_main_loop_quit
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1321
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339