imported from svn
[metux-java.git] / ip / IPAddr.java
blobf724786ae82b66aebe8d3379d403a725deb86cbc
2 package org.de.metux.ip;
4 public class IPAddr
6 public byte addr[];
7 public byte mask;
8 public boolean is_class;
10 public IPAddr()
12 addr[0] = 0;
13 addr[1] = 0;
14 addr[2] = 0;
15 addr[3] = 0;
16 is_class = 0;
17 mask = 0;
20 public toString()
22 String str = String(addr[0])+"."+
23 String(addr[1])+"."+
24 String(addr[2])+"."+
25 String(addr[3]);
27 if (is_class)
28 str += "/"+String(mask);
30 return str;
33 public boolean parseAddress
35 StringTokenizer tok = new StringTokenizer(str,".");
36 if (tok.countTokens()!=4)
37 throw new RuntimeException("parse error 1");
39 addr[0] = new Integer(tok.nextToken()).byteValue();
40 addr[1] = new Integer(tok.nextToken()).byteValue();
41 addr[2] = new Integer(tok.nextToken()).byteValue();
42 addr[3] = new Integer(tok.nextToken()).byteValue();
44 return true;
47 public boolean parseAddress
49 StringTokenizer tok = new StringTokenizer(str,".");
50 if (tok.countTokens()!=4)
51 throw new RuntimeException("parse error 1");
53 addr[0] = new Integer(tok.nextToken()).byteValue();
54 addr[1] = new Integer(tok.nextToken()).byteValue();
55 addr[2] = new Integer(tok.nextToken()).byteValue();
57 StringTokenzier tok2 = new StringTokenizer(tok.nextToken(),"/");
58 if (tok2.countTokens()!=2)
59 throw new RuntimeException("parse error 2");
61 addr[3] = new Integer(tok.nextToken()).byteValue();
62 mask = new Integer(tok.nextToken()).byteValue();
64 return true;
68 //public class StrSplit
69 //{
70 // /* a little workaround against missing regex in current libgcj */
71 // public static String[] split(String str)
72 // {
73 // StringTokenizer tok = new StringTokenizer(str);
74 // String[] list = new String[tok.countTokens()];
76 // for (int x=0; tok.hasMoreTokens(); x++)
77 // list[x] = tok.nextToken();
79 // return list;
80 // }
82 // public static String[] split(String str, String delimiter)
83 // {
84 // }
85 //}