Solved

How to set subnet mask using Windows API function?

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 121
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 138
Raspberry Pi 3 to send text message 9 114
macro vba to pivot table 1 19
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…
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…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 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