RTM_IPV4_LEN_FROM_MASK macro (rtmv2.h)

The RTM_IPV4_LEN_FROM_MASK macro converts an IPv4 mask to a generic route length.

Syntax

void RTM_IPV4_LEN_FROM_MASK(
   Len,
   Mask
);

Parameters

Len

Receives the converted length

Mask

Specifies the mask to convert.

Return value

None

Remarks

For example, if a client supplies the Mask 255.255.255.255, the Len 24 is returned.

The macro is defined as follows:

#include <windows.h>

#define RTM_CHECK_NTH_BIT(Value, N, Len)                           \
        if ((Value) & (1 << (N)))                                  \
        {                                                          \
            (Len) += (N); (Value) <<= (N);                         \
        }

#define RTM_IPV4_LEN_FROM_MASK(Len, Mask)                   \
        {                                                   \
            ULONG _Temp_ = ntohl(Mask);                     \
            (Len) = 0;                                      \
            RTM_CHECK_NTH_BIT(_Temp_, 16, (Len));           \
            RTM_CHECK_NTH_BIT(_Temp_,  8, (Len));           \
            RTM_CHECK_NTH_BIT(_Temp_,  4, (Len));           \
            while (_Temp_)                                  \
            {                                               \
                (Len) +=  1; _Temp_ <<=  1;                 \
            }                                               \
        }                                                    \

Requirements

Requirement Value
Minimum supported client None supported
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header rtmv2.h

See also

RTM_IPV4_GET_ADDR_AND_LEN

RTM_IPV4_GET_ADDR_AND_MASK

RTM_IPV4_MAKE_NET_ADDRESS

RTM_IPV4_MASK_FROM_LEN

RTM_IPV4_SET_ADDR_AND_LEN

RTM_IPV4_SET_ADDR_AND_MASK

RTM_NET_ADDRESS