This is a very simple example that shows how to make a simple DNS lookup using \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga25b58526055fd5bfa3166e6fe182b0fb}{ecore\+\_\+con\+\_\+lookup()}}.

It\textquotesingle{}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 \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga25b58526055fd5bfa3166e6fe182b0fb}{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\textquotesingle{}s no way to know about that. It\textquotesingle{}s only possible to know about errors when setting up the lookup, by looking at the return code of the \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga25b58526055fd5bfa3166e6fe182b0fb}{ecore\+\_\+con\+\_\+lookup()}} function.

The callback {\ttfamily \+\_\+lookup\+\_\+done\+\_\+cb} passed as argument to \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga25b58526055fd5bfa3166e6fe182b0fb}{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\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/o\ ecore\_con\_lookup\_example\ ecore\_con\_lookup\_example.c\ `pkg-\/config\ -\/-\/libs\ -\/-\/cflags\ ecore\ ecore-\/con`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore\_Con.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_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\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}canonname\ =\ \%s\(\backslash\)n"{}},\ canonname);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}ip\ =\ \%s\(\backslash\)n"{}},\ ip);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}addr\ =\ \%p\(\backslash\)n"{}},\ addr);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (argc\ <\ 2)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}need\ one\ parameter:\ <address>\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga8a20f47372627a03e86a8705a6f8a82d}{ecore\_con\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga25b58526055fd5bfa3166e6fe182b0fb}{ecore\_con\_lookup}}(argv[1],\ \_lookup\_done\_cb,\ NULL))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}error\ when\ trying\ to\ start\ lookup\ for\ \%s\(\backslash\)n"{}},\ argv[1]);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ end;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{end:}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga0e5e01c67f7135e16db0e8f17d087d99}{ecore\_con\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 