name server config

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/15/08, Klaus Darilion <klaus.mailinglists at pernau.at> wrote:
>
>
> I think there is no easier way. I've checked ares resolver (part of
> resiprocate) and they are doing it the same way:
>   - GetNetworkParams on Windows
>   - parsing /etc/resolv.conf on Unix
>
> Ares further suports MacOS.
>
> IMO it would be real cool if pjlib supports getting nameserver config too.


Thanks for the info and the vote. I've added
http://trac.pjsip.org/repos/ticket/450 for this, hopefully it can be done
soon.

PS: I have attached how I have done it in Windows.


Ugh, it has QString! ;-)

cheers,
 -benny


regards
> klaus
>
>
>
>         pjsua_config cfg;
>         pjsua_config_default(&cfg);
>
> #ifdef WIN32
>         /* searching for nameserver on WIN32
>          * code partly from resiprocate/ares/ares_init.c,
>          * http://msdn2.microsoft.com/en-us/library/aa366068.aspx and
>          * by Klaus Darilion (c) ipcom.at  */
>
>         /*
>      * Way of getting nameservers that should work on all Windows from 98
> on.
>      */
>         FIXED_INFO *     FixedInfo;
>         ULONG            ulOutBufLen;
>         DWORD            dwRetVal;
>         IP_ADDR_STRING * pIPAddr;
>         HANDLE           hLib;
>         int failed=0;
>         typedef DWORD (*GNP) (FIXED_INFO*, DWORD*);
>         GNP gnp;
>
>         while(1) {
>                 hLib = LoadLibrary(TEXT("iphlpapi.dll"));
>                 if (!hLib) {
>                         failed++;
>                         break;
>                 }
>                 //appLog("DLL loaded ...");
>
>                 gnp = (GNP) GetProcAddress((HINSTANCE__*) hLib,
> "GetNetworkParams");
>
>                 if (!gnp) {
>                         FreeLibrary((HINSTANCE__*) hLib);
>                         failed++;
>                         break;
>                 }
>                 //appLog("GetNetworkParams found ...");
>                 FixedInfo = (FIXED_INFO *) GlobalAlloc(GPTR,
> sizeof(FIXED_INFO));
>                 ulOutBufLen = sizeof(FIXED_INFO);
>
>                 if (ERROR_BUFFER_OVERFLOW == gnp(FixedInfo, &ulOutBufLen)
> ) {
>                         GlobalFree(FixedInfo);
>                         FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR,
> ulOutBufLen);
>                 }
>
>                 if ( dwRetVal = gnp( FixedInfo, &ulOutBufLen ) ) {
>                         GlobalFree( FixedInfo );
>                         FreeLibrary((HINSTANCE__*) hLib);
>                         failed++;
>                         break;
>                 }
>                 //appLog("GetNetworkParams done ...");
>                 pIPAddr = &FixedInfo->DnsServerList;
>                 while ( pIPAddr && strlen(pIPAddr->IpAddress.String) > 0)
>                 {
>                         char *dns;
>                         appLog("found name server: " + QString(pIPAddr->
> IpAddress.String));
>                         dns = strdup(pIPAddr->IpAddress.String);
>                         cfg.nameserver[cfg.nameserver_count] =
> pj_str(dns);
>                         pIPAddr = pIPAddr ->Next;
>                         cfg.nameserver_count++;
>                         if (cfg.nameserver_count == 4) {
>                                 break;  /* pjsua allows configuration of 4
> name servers */
>                         }
>                 }
>                 GlobalFree( FixedInfo );
>                 FreeLibrary((HINSTANCE__*) hLib);
>                 break;
>         }
> #endif //WIN32
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20080116/5b3dfed5/attachment-0001.html 


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux