We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


How do I get the TCP/IP subnet mask?

santj asked
Medium Priority
Last Modified: 2013-12-03
I am writing a Winsocks program in "C" using the MS Visual C++ compiler and I need to get the subnet mask of the network that the program is executed on.

This program is to be run on many different Win95/WINNT systems. Each system's networking may be configured differently (i.e. some may be using Microsoft's tcp/ip stack, others may use a third party tcp/ip stack, or
some systems may be configured for DHCP).

I am aware that Microsoft's stack stores the subnet mask under:


I assume third party tcp/ip stack vendors may store the subnet mask else where.  Another assumption is, systems configured for DHCP do not store the subnet mask in the registry.  Are these assumptions correct?

There must be an API call to get this information (I find it hard to believe that developers at MicroSoft write registry searches when they need this information).  Does anyone know of an API call to get the subnet mask?


Jim Santmyer
Watch Question

You can obtain ip address and subnet mask from registry only.
For more information, see the MS knowledge base article  Q120642.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<Adapter Name>\Parameters\Tcpip\SubnetMask

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<Adapter Name>\Parameters\Tcpip\DhcpSubnetMask


Wrong answer :). I have since found an API call that will provide me the subnet mask on Win95 and WinNT platforms.  

I expected a better answer then RTFM from an "expert".  I also expected a correct answer.  Since you like to read the manual I will give you a hint were to find the correct answer, start with  ioctl calls.  
Well, I am interesting in your answer. Some time ago I've used the registry to obtain IP address to solve some problems. Unfortunately, I have no time to look for API call you mentioned.
I have only 125 'points' to ask the question. And if you will be so kind to answer to MY question about subnet mask, I'll give you them all with grade 'A'.

Also, please tell me why my answer is wrong. Am I wrong with API call, or I am wrong at all?
Also, does your API call cares about multihomed systems with multiply IP addresses?


I have posted the answer to the news groups:

I've reviewed the discussion in microsoft...networks newsgroup right now. And I see now that you was unjust with me.
My anwer was right and still right.
Other methods to obtain the subnet mask are non-portable (now at least).

As to ipconfig, this program obtains the subnet mask from registry only, not from any API call.
Nick was right.  Even if you look at the Vxd level, MS drivers even use the registry to get the mask.  It's a configuration setting, not part of the SNMP protocol.  Check the RFC if you don't believe me.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Hi , Santj!

As part of this descussion you are point to news groups. I am lost this information. Could you resend me it (stas@vdo.net).

Thank you

Ioctl calls point to vxd's.


How do you get the IP address and/or subnetmask on a system that is configured for PPP and dynamic address assignment?  Or a system configured to use DHCP to get it's address and subnet mask?  In either of these cases I do not think this information is in the registy.
Although you DON'T like to read the manual  :),
you may find this information in knowledge base article mentioned in my rejected answer.
Registry entries are dynamically updating by system while PPP link is established/dropped. It's true for DHCP also.

'I expected a better answer then RTFM from an "expert" '.
Well, only an expert can grade the another expert's answer  ;)


Wrong again :-). As I write this comment I am using a dial-up PPP connection with the IP address dynamiclly assigned.  A search of the registry does not find my IP address.  The only IP addresses in the registry are the default gateway, the name server and an entry in


which is set to  The IPMask is set to also, yet when I run winipcfg, it shows my ip address and subnet mask.

I do not claim to be an expert, but I do verify my answers to be correct before responding :).  

Thinking about your lastest answer, I wonder how the registry is updated dynamiclly with the IP address, if it is not currently know by the system.  It must be stored some place else, possibly in the IP stack?  In which case there must be a way to get the IP address without using the registy.


*THAT* gets your IP.

That uses the installed IP stack, too, BTW.

try this.

Run PPP connection.

Run ipconfig.exe.

It writes (for example):

Token Ring adapter tl3c3x91:

        IP Address. . . . . . . . . :
        Subnet Mask . . . . . . . . :
        Default Gateway . . . . . . :

Now look for this key in registry and see your dynamically assigned ip address and mask!

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<Adapter Name>\Parameters\Tcpip\

(<Adapter name> is 'tl3c3x91'in my case)

When PPP connection is dropped, all values are 0.

I've checked my previous answer before I submitted it.
P.S. It's possible to have got an adapter and PPP connection at the same time. In this case there will be a two adapters in your PC - one is real and second is virtual. And you should check two registry keys in this case (refer to ipconfig.exe)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.