Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C code to find subnet mask

Status
Not open for further replies.

groove69

Programmer
May 25, 2004
9
0
0
US
Is there a way within Microsoft C++ to get the subnet mask of your local workstation??
 
groove69,

You can use WSAIoctl() with the SIO_GET_INTERFACE_LIST command. It's not documented in the command list in the documentation, but it works. There is example code you can get from Microsoft here:


The only problam I had using it was that I passed in the address of an INTERFACE_INFO structure. It failed with WSAEFAULT, which the code it returns when the data structure you give it isn't large enough. The argument needed to be the address of an array of INTERFACE_INFO structures that was big enough to hold all of the interfaces present. Even if there is only one interface on your system, it will enumerate the loopback address also. The example code clarified it.

- Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top