You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/11/13 17:11:58 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/net InetAddressUtil.java

andreas     2003/11/13 08:11:58

  Modified:    src/java/org/apache/lenya/net InetAddressUtil.java
  Log:
  refactoring access control package structure
  
  Revision  Changes    Path
  1.8       +33 -1     cocoon-lenya/src/java/org/apache/lenya/net/InetAddressUtil.java
  
  Index: InetAddressUtil.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/net/InetAddressUtil.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InetAddressUtil.java	28 Oct 2003 11:14:56 -0000	1.7
  +++ InetAddressUtil.java	13 Nov 2003 16:11:58 -0000	1.8
  @@ -55,6 +55,7 @@
   package org.apache.lenya.net;
   
   import java.net.InetAddress;
  +import java.net.UnknownHostException;
   
   import org.apache.log4j.Category;
   
  @@ -65,7 +66,14 @@
    * @version $Id$
    */
   public class InetAddressUtil {
  +    
       private static final Category log = Category.getInstance(InetAddressUtil.class);
  +
  +    /**
  +     * Ctor.
  +     */    
  +    private InetAddressUtil() {
  +    }
   	
       /**
        * Checks if a subnet contains a specific IP address.
  @@ -168,4 +176,28 @@
           log.error(".checkNetmask(): Illegal Netmask: " + netmask);
           return -1;
       }
  +
  +    /**
  +     * Converts a string to an IP addres.
  +     * @param string The IP address, represented by a string.
  +     * @return An InetAddress object.
  +     * @throws AccessControlException when something went wrong.
  +     */
  +    public static InetAddress getAddress(String string) throws UnknownHostException {
  +        String[] strings = string.split("\\.");
  +
  +        InetAddress address;
  +        byte[] numbers = new byte[strings.length];
  +        for (int i = 0; i < strings.length; i++) {
  +            int number = Integer.parseInt(strings[i]);
  +            if (number > 127) {
  +                number = number - 256;
  +            }
  +            numbers[i] = (byte) number;
  +        }
  +
  +        address = InetAddress.getByAddress(numbers);
  +        return address;
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org