[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to set subnet mask using Windows API function?

Posted on 2013-10-23
1
Medium Priority
?
835 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

650 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