<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; DNS</title>
	<atom:link href="http://www.ucosoft.com/tag/dns/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Mon, 19 Jul 2010 04:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to get the local DNS server record</title>
		<link>http://www.ucosoft.com/how-to-get-the-local-dns-server-record.html</link>
		<comments>http://www.ucosoft.com/how-to-get-the-local-dns-server-record.html#comments</comments>
		<pubDate>Wed, 03 Jan 2007 07:48:42 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/62.html</guid>
		<description><![CDATA[If you don&#8217;t have Iphlpapi.lib installed, you can retrieve the local DNS server in the following way. The main step is load &#8220;Iphlpapi.dll&#8221; with ::LoadLibary method and call ::GetProcAddress to get the &#8220;GetNetworkParams&#8221;. Here is the full source: #include &#8220;stdafx.h&#8221; #include #include #define MAX_HOSTNAME_LEN 128 #define MAX_DOMAIN_NAME_LEN 128 #define MAX_SCOPE_ID_LEN 256 typedef struct _IP_ADDR_STRING {]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t have Iphlpapi.lib installed, you can retrieve the local DNS server in the following way.</p>
<p>The main step is load &#8220;Iphlpapi.dll&#8221; with <b>::LoadLibary</b> method and call <b>::GetProcAddress</b> to get the &#8220;GetNetworkParams&#8221;.</p>
<p>Here is the full source:</P><br />
<span id="more-62"></span><br />
<coolcode lang="cpp" linenum="no" download="GetDns.cpp"><br />
#include &#8220;stdafx.h&#8221;<br />
#include <stdio.h><br />
#include <windows.h></p>
<p>#define MAX_HOSTNAME_LEN     128<br />
#define MAX_DOMAIN_NAME_LEN  128<br />
#define MAX_SCOPE_ID_LEN     256</p>
<p>typedef struct _IP_ADDR_STRING {<br />
        struct _IP_ADDR_STRING* Next;<br />
        BYTE IpAddress[16];<br />
        BYTE IpMask[16];<br />
        DWORD Context;<br />
}IP_ADDR_STRING, *PIP_ADDR_STRING;</p>
<p>typedef struct {<br />
        char HostName [MAX_HOSTNAME_LEN + 4] ;<br />
        char DomainName [MAX_DOMAIN_NAME_LEN + 4] ;<br />
        PIP_ADDR_STRING CurrentDnsServer ;<br />
        IP_ADDR_STRING DnsServerList ;<br />
        UINT NodeType ;<br />
        char ScopeId [MAX_SCOPE_ID_LEN + 4] ;<br />
        UINT EnableRouting ;<br />
        UINT EnableProxy ;<br />
        UINT EnableDns ;<br />
} FIXED_INFO, *PFIXED_INFO ;</p>
<p>typedef  DWORD  (__stdcall *pGetNetworkParams)(PFIXED_INFO,PULONG);</p>
<p>int main()<br />
{<br />
        FIXED_INFO     *  FixedInfo;<br />
        ULONG             ulOutBufLen;<br />
        HINSTANCE         hIphlpapiDll;<br />
        pGetNetworkParams  p;</p>
<p>        __try<br />
        {<br />
                hIphlpapiDll=::LoadLibrary(&#8220;Iphlpapi.dll&#8221;);<br />
                p=(pGetNetworkParams)::GetProcAddress(hIphlpapiDll,<br />
&#8220;GetNetworkParams&#8221;);</p>
<p>        FixedInfo = (FIXED_INFO *) GlobalAlloc( GPTR, sizeof( FIXED_INFO ) );<br />
        ulOutBufLen = sizeof( FIXED_INFO );</p>
<p>                if( ERROR_BUFFER_OVERFLOW ==(*p)( FixedInfo, &#038;ulOutBufLen ) )<br />
                {<br />
                GlobalFree( FixedInfo );<br />
                FixedInfo = (FIXED_INFO *)GlobalAlloc( GPTR, ulOutBufLen );<br />
                }</p>
<p>                (*p)( FixedInfo, &#038;ulOutBufLen );</p>
<p>                printf( &#8220;Host Name: %s\n&#8221;, FixedInfo->HostName );<br />
                printf( &#8220;DNS Servers: %s\n&#8221;,FixedInfo->DnsServerList.IpAddress )<br />
;</p>
<p>        }<br />
        __except( EXCEPTION_EXECUTE_HANDLER){}<br />
        ::FreeLibrary(hIphlpapiDll);<br />
    ::GlobalFree( FixedInfo );<br />
    return 1;<br />
}<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</a>, <a href="http://www.ucosoft.com/tag/dns" title="DNS" rel="tag">DNS</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/write-and-read-binary-data-in-variant.html" title="Write and read binary data in VARIANT (November 22, 2006)">Write and read binary data in VARIANT</a> (0)</li>
	<li><a href="http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html" title="Set the head backgroud color of CPropertyPage (October 18, 2007)">Set the head backgroud color of CPropertyPage</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html" title="How to translate among CString,string and char array (June 22, 2007)">How to translate among CString,string and char array</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html" title="How to subclass CTreeCtrl in CTreeView? (October 25, 2007)">How to subclass CTreeCtrl in CTreeView?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html" title="How to sort items of CListCtrl or CListView? (October 22, 2007)">How to sort items of CListCtrl or CListView?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html" title="How to launch an Application with Admin privileges in VISTA (March 8, 2007)">How to launch an Application with Admin privileges in VISTA</a> (0)</li>
	<li><a href="http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html" title="How to get ClistCtrl item text of another process (September 24, 2008)">How to get ClistCtrl item text of another process</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html" title="How to Draw Bitmap from a bmp File? (January 4, 2007)">How to Draw Bitmap from a bmp File?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-check-whether-the-window-is-in-minimise-or-maximise-mode.html" title="How to check whether the window is in minimise or Maximise mode (March 21, 2007)">How to check whether the window is in minimise or Maximise mode</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-get-the-local-dns-server-record.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
