October 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

IP Helper API: Retrieving Basic Information

  • September 10, 2004
  • By Alex Gusev
  • Send Email »
  • More Articles »

This article starts a set of postings discussing different aspects of mobile networking insides. This is a pretty wide area, so one article is too small to cover it all. Thus, we will divide this topic into several logical pieces and overview them one by one. A recent article told about starting part of IP Helper API : general network configuration information, adapters, and interfaces.

General Info is really simple stuff

As I said above, we will start with obtaining info about the general network configuration. IP Helper API has one function for this purpose: GetNetworkParams. This function returns general information that is not specific to a particular network adapter or interface such as DNS, proxy, DHCP parameters, and so forth. This data is the same for all available network adapters or interfaces. The function signature is listed below:

DWORD GetNetworkParams(PFIXED_INFO pFixedInfo,PULONG pOutBufLen);

The function takes the pointer to the FIXED_INFO struct and fills it in. pOutBufLen tells the size of the supplying buffer. If no errors occured, GetNetworkParams returns NO_ERROR and corresponding data in pFixedInfo. Otherwise, you will get ERROR_BUFFER_OVERFLOW and actually the required size into pOutBufLen parameter if the initial buffer is insufficient to hold all data. That is a common behavior of most IP Helper API (and Windows' ones in general) functions. FIXED_INFO struct is presented below:

typedef struct {
char HostName [MAX_HOSTNAME_LEN + 4];
char DomainName [MAX_DOMAIN_NAME_LEN + 4];
PIP_ADDR_STRING CurrentDnsServer;
IP_ADDR_STRING DnsServerList;
UINT NodeType;
char ScopeId [MAX_SCOPE_ID_LEN + 4];
UINT EnableRouting;
UINT EnableProxy;
UINT EnableDns;
} FIXED_INFO, *PFIXED_INFO;

All its fields are self-documented and intuitive enough, so we will just cover them briefly here, mainly for reference purposes:

Field Description
HostName Name of your PDA, which you may change on the Settings\System\About\DeviceID page
DomainName This field will be empty in many cases because mobile devices usually do not belong to any domain
CurrentDnsServer Not used under Windows CE
DnsServerList Linked list of IP_ADDR_STRING structures holding info about defined DSN servers
NodeType Specifies whether the local computer a uses dynamic host configuration protocol (DHCP) Usually has a HYBRID_NODETYPE value
ScopeId Specifies the DHCP scope name
EnableRouting Specifies whether routing is enabled on the local computer. Usually equals 0 on Windows CE
EnableProxy Specifies whether the local computer is acting as an ARP proxy. Usually equals 0 on Windows CE
EnableDns Specifies whether DNS is enabled on the local computer

To complete this topic, let's consider a simple code sample that retrieves info from the system:

void CNWParamsDlg::OnButtonQuery()
{
   FIXED_INFO FixedInfo;
   ULONG OutBufLen = sizeof(FixedInfo);
   DWORD dwRet = GetNetworkParams(&FixedInfo, &OutBufLen);
   if ( dwRet == NO_ERROR )
   {
      TRACE(L"OK\n");
      ShowDSN(&FixedInfo);
   }
   else if ( dwRet == ERROR_BUFFER_OVERFLOW )
   {
      TRACE(L"Error: size = %lu\n",OutBufLen);
      BYTE *pBuffer = new BYTE[OutBufLen];
      PFIXED_INFO pInfo = (PFIXED_INFO)pBuffer;
      dwRet = GetNetworkParams(pInfo, &OutBufLen);
      if ( dwRet == NO_ERROR )
      {
         TRACE(L"OK\n");
         ShowDSN(pInfo);
      }
      delete [] pBuffer;
   }
}

void CNWParamsDlg::ShowDSN(PFIXED_INFO pInfo)
{
   m_ListBox.ResetContent();
   m_ListBox.AddString(CString(pInfo->
                       DnsServerList.IpAddress.String));
   IP_ADDR_STRING * pIPAddr = pInfo->DnsServerList.Next;
   while ( pIPAddr )
   {
      m_ListBox.AddString(CString(pIPAddr->IpAddress.String));
      pIPAddr = pIPAddr->Next;
   }
   ((CStatic*)GetDlgItem(IDC_STATIC_INFO))->SetWindowText(L"DNS:");
}




Page 1 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel