Source code: com/voytechs/jnetstream/primitive/address/MacAddress.java
1 /*
2 * File: MacAddress.java
3 * Auth: Mark Bednarczyk
4 * Date: 2001-08-05
5 * Id: $Id: MacAddress.java,v 1.1.1.1 2003/09/22 16:32:12 voytechs Exp $
6 ********************************************
7 Copyright (C) 2003 Mark Bednarczyk
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ********************************************
23 * $Log: MacAddress.java,v $
24 * Revision 1.1.1.1 2003/09/22 16:32:12 voytechs
25 * Initial import.
26 *
27 * Revision 1.1 2001/09/04 15:33:55 markbe
28 * Initial revision
29 *
30 */
31 package com.voytechs.jnetstream.primitive.address;
32
33 import java.util.*;
34 import java.net.*;
35 import java.io.Serializable;
36
37 /**
38 * A Class for storing MAC Addresses
39 */
40 public class MacAddress
41 extends Address {
42
43 /* Internal attributes */
44
45 /**
46 * Main constructor taking the array of bytes as the address.
47 * Automatically sets the separator token to ':'
48 *
49 * @param address array of bytes making up the address.
50 * @exception IllegalArgumentException if number of bytes is not 6.
51 */
52 public MacAddress(byte [] address) {
53 super(address);
54
55 if(address.length == 6) {
56 setSeparator(':');
57 setRadix(16);
58 }
59
60 else {
61 throw new IllegalArgumentException("MAC Address can only be 48 bits long");
62 }
63 }
64
65 /**
66 * Convert to dot notation string representation of the address. If hostname is
67 * known then hostname.domain is returned other wise the appropriate numerical
68 * representation of the numerical address is returned as a String.
69 *
70 * @return IP address in the dot notation.
71 */
72 public String toString() {
73 return(super.toString());
74 }
75
76 /**
77 * Test function for MacAddress
78 * @param args command line arguments
79 */
80 public static void main(String [] args) {
81
82 MacAddress ether = null;
83
84 ether = new MacAddress(new byte[] { (byte)192, (byte)100, 10, 10, 20, 20} );
85
86
87 System.out.println("Converted IP=" + ether );
88 }
89
90 } /* END OF: MacAddress */