Solved

How to set subnet mask using Windows API function?

Posted on 2013-10-23
1
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39594342
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

689 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