Solved

How to set subnet mask using Windows API function?

Posted on 2013-10-23
1
754 Views
Last Modified: 2013-10-29
I want to set subnet mask for Windows (.eg: 255.255.255.0). Which Windows API functions is suitable for this?

I try using CreateUnicastIpAddressEntry(&ipRow) with the parameter ipRow. OnLinkPrefixLength that content size of subnet to set (prefixlength get based on calling ConvertIpv4MaskToLength(&mask, maskLength)). However, there is two problems:
1.    the input parameter mask is kind of integer I don’t know how to set it from “255.255.255.0”.

2. I try setting mask with value 16777215 and ConvertIpv4MaskToLength(&mask, maskLength) return error “Access violation writing location 0x00000000” related memory area of parameter maskLength.

Regards.
0
Comment
Question by:FSOFT-SA
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
As for 1: To convert a string netmask or IP address to it's integer equivalent, use 'inet_addr()' (http://msdn.microsoft.com/en-us/library/windows/desktop/ms738563(v=vs.85).aspx), e.g.

ULONG ulMask = inet_addr("255.255.255.0");

Open in new window


As for 2: Can you post your code for that call?  This should be something like

UINT8 MaskLength;
ULONG ulMask = inet_addr("255.255.255.0");

ConvertIpv4MaskToLength(ulMask,&MaskLength); // use the address of an UINT8 here, not an PUINT8!

Open in new window


I assume the latter (using a pointer instead the address of a variable) was/is the issue here.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now