Solved

How to set subnet mask using Windows API function?

Posted on 2013-10-23
1
784 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
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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 245
Computer slow / BSOD 10 64
How to convert Structure to vector of byte and vice versa 5 24
windows 10 pro lost profile. 10 43
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

856 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