Calculates the network mask value from the address - Android Network

Android examples for Network:Network Operation

Description

Calculates the network mask value from the address

Demo Code


//package com.java2s;
import java.net.InetAddress;

public class Main {
    /**//  w w  w.  j  a va 2 s . co m
     * Calculates the network mask value from the address
     * 
     * @param address
     *            the network mask
     * @return
     */
    public static int networkMaskFromInetAddress(InetAddress address) {
        byte[] addrs = address.getAddress();
        int result = 0;
        int i = 24;
        for (byte value : addrs) {
            result += value << i;
            i -= 8;
        }
        return result;
    }
}

Related Tutorials