Click here to Skip to main content
15,887,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i done that program to get a only one subnet mask address from system and display..

i refer from the msdn website. my coding is:


C++
#include <stdafx.h>
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, &quot;Iphlpapi.lib&quot;)
int main(void)
{
    ULONG            cbBuf    = 0;
    PIP_ADAPTER_INFO pAdapter = NULL;
    PIP_ADAPTER_INFO pMemory  = NULL;
    DWORD            dwResult = 0;
    PIP_ADAPTER_INFO pMemory1 = NULL;
    dwResult = GetAdaptersInfo(NULL, &amp;cbBuf);
    pMemory = pAdapter = (PIP_ADAPTER_INFO) malloc(cbBuf);
    dwResult = GetAdaptersInfo(pAdapter, &amp;cbBuf);
    while (pAdapter)
    {
        printf("Name: %s\nDescription: %s\nGateway: %s\nSubnet Mask: %s\n",
               pAdapter-&gt;AdapterName,
               pAdapter-&gt;Description,
               pAdapter-&gt;GatewayList.IpAddress.String,
               pAdapter-&gt;IpAddressList.IpMask.String);
        pAdapter = pAdapter-&gt;Next;
    }
    free(pMemory);
    getchar();
    return 0;
}



like that i created.

i run sucessfully..

but my system i create 4 ip address and equivalent subnet mask address also...

i don't know how to retrieve all subnet mask address form the system using c.


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 8-Jul-11 3:54am
v2
Comments
@BangIndia 8-Jul-11 10:08am    
use the adapter function
harish85 8-Jul-11 21:19pm    
This should return all your Ethernet Cards details(Includes subnet mask), What are you expecting to see?

1 solution

PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter=NULL;
printf("Hello World!\n");
DWORD dwRetVal=0;
ULONG ulOutBufLen=sizeof(PIP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof (IP_ADAPTER_INFO));
if(GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)==ERROR_BUFFER_OVERFLOW)
{
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);

}
dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
pAdapter = pAdapterInfo;
while (pAdapter)
{
temp=new node();
temp->gate=pAdapter->GatewayList.IpAddress.String;
temp->ip=pAdapter->IpAddressList.IpAddress.String;
temp->mac=pAdapter->IpAddressList.IpMask.String;
temp->next=main1;
main1=temp;
IP_ADDR_STRING *p;
p=(pAdapter->IpAddressList.Next);
while(p)
{
temp=main1;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp=new node();
temp->ip=p->IpAddress.String;
temp->mac=p->IpMask.String;
temp->next=main1;
main1=temp;
p=p->Next;
}

pAdapter=pAdapter->Next;
}
this will provide all ip and subnet mask address you can use it..

100% its working..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900