This is a very simple example that shows how to make a simple D\+N\+S 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 D\+N\+S 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 {\ttfamily \+\_\+lookup\+\_\+done\+\_\+cb} passed as argument to ecore\+\_\+con\+\_\+lookup() just prints the resolved canonical name, I\+P, 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\+:


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o ecore\_con\_lookup\_example ecore\_con\_lookup\_example.c `pkg-config --libs --cflags ecore ecore-con`}

\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <Ecore\_Con.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_lookup\_done\_cb(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *canonname, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *ip, \textcolor{keyword}{struct} sockaddr *addr, \textcolor{keywordtype}{int} addrlen, \textcolor{keywordtype}{void} *data 
      EINA\_UNUSED)
\{
   printf(\textcolor{stringliteral}{"canonname = %s\(\backslash\)n"}, canonname);
   printf(\textcolor{stringliteral}{"ip = %s\(\backslash\)n"}, ip);
   printf(\textcolor{stringliteral}{"addr = %p\(\backslash\)n"}, addr);
   printf(\textcolor{stringliteral}{"addrlen = %d\(\backslash\)n"}, addrlen);
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *argv[])
\{
   \textcolor{keywordflow}{if} (argc < 2)
     \{
        printf(\textcolor{stringliteral}{"need one parameter: <address>\(\backslash\)n"});
        \textcolor{keywordflow}{return} -1;
     \}

   \hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}();
   \hyperlink{group__Ecore__Con__Events__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}();

   \textcolor{keywordflow}{if} (!ecore\_con\_lookup(argv[1], \_lookup\_done\_cb, NULL))
     \{
        printf(\textcolor{stringliteral}{"error when trying to start lookup for %s\(\backslash\)n"}, argv[1]);
        \textcolor{keywordflow}{goto} end;
     \}

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

end:
   \hyperlink{group__Ecore__Con__Events__Group_gaccfd8dd2a1187b71339b5cc39dc83938}{ecore\_con\_shutdown}();
   \hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}
 