Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

public class Main {
    /**
     * 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;
    }
}