Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I get the TCP/IP subnet mask?

Posted on 1997-06-23
16
Medium Priority
?
1,063 Views
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:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\xxxx\IPMask

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?

Thanks,

Jim Santmyer
0
Comment
Question by:santj
  • 7
  • 4
  • 4
  • +1
16 Comments
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398941
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
0
 

Author Comment

by:santj
ID: 1398942
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.  
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398943
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'.

0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
LVL 15

Expert Comment

by:NickRepin
ID: 1398944
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?
0
 

Author Comment

by:santj
ID: 1398945
I have posted the answer to the news groups:

microsoft.public.win32.programmer.networks,
comp.os.ms-windows.programmer.networks,
comp.os.mis-windows.programmer.misc
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398946
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.
0
 
LVL 3

Accepted Solution

by:
vinniew earned 400 total points
ID: 1398947
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.

0
 
LVL 1

Expert Comment

by:stas
ID: 1398948
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
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1398949
Ioctl calls point to vxd's.


0
 

Author Comment

by:santj
ID: 1398950
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.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398951
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  ;)
0
 

Author Comment

by:santj
ID: 1398952
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

           HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\xxxx\IPAddress

which is set to 0.0.0.0.  The IPMask is set to 0.0.0.0 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.
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1398953
socket()
bind()

*THAT* gets your IP.
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1398954
That uses the installed IP stack, too, BTW.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398955
Santj,

try this.

Run PPP connection.

Run ipconfig.exe.

It writes (for example):

Token Ring adapter tl3c3x91:

        IP Address. . . . . . . . . : 194.84.100.71
        Subnet Mask . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . : 194.84.100.101


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.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398956
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)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question