InterfaceConfiguration.java revision 04808c294027f8bc318643a94c85a999257d7f52
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.net; 18 19import android.os.Parcelable; 20import android.os.Parcel; 21 22import java.net.InetAddress; 23import java.net.UnknownHostException; 24 25/** 26 * A simple object for retrieving / setting an interfaces configuration 27 * @hide 28 */ 29public class InterfaceConfiguration implements Parcelable { 30 public String hwAddr; 31 public InetAddress addr; 32 public InetAddress mask; 33 public String interfaceFlags; 34 35 public InterfaceConfiguration() { 36 super(); 37 } 38 39 public String toString() { 40 StringBuffer str = new StringBuffer(); 41 42 str.append("ipddress "); str.append(addr.toString()); 43 str.append(" netmask "); str.append(mask.toString()); 44 str.append(" flags ").append(interfaceFlags); 45 str.append(" hwaddr ").append(hwAddr); 46 47 return str.toString(); 48 } 49 50 /** Implement the Parcelable interface {@hide} */ 51 public int describeContents() { 52 return 0; 53 } 54 55 /** Implement the Parcelable interface {@hide} */ 56 public void writeToParcel(Parcel dest, int flags) { 57 dest.writeString(hwAddr); 58 if (addr != null) { 59 dest.writeByte((byte)1); 60 dest.writeByteArray(addr.getAddress()); 61 } else { 62 dest.writeByte((byte)0); 63 } 64 if (mask != null) { 65 dest.writeByte((byte)1); 66 dest.writeByteArray(mask.getAddress()); 67 } else { 68 dest.writeByte((byte)0); 69 } 70 dest.writeString(interfaceFlags); 71 } 72 73 /** Implement the Parcelable interface {@hide} */ 74 public static final Creator<InterfaceConfiguration> CREATOR = 75 new Creator<InterfaceConfiguration>() { 76 public InterfaceConfiguration createFromParcel(Parcel in) { 77 InterfaceConfiguration info = new InterfaceConfiguration(); 78 info.hwAddr = in.readString(); 79 if (in.readByte() == 1) { 80 try { 81 info.addr = InetAddress.getByAddress(in.createByteArray()); 82 } catch (UnknownHostException e) {} 83 } 84 if (in.readByte() == 1) { 85 try { 86 info.mask = InetAddress.getByAddress(in.createByteArray()); 87 } catch (UnknownHostException e) {} 88 } 89 info.interfaceFlags = in.readString(); 90 return info; 91 } 92 93 public InterfaceConfiguration[] newArray(int size) { 94 return new InterfaceConfiguration[size]; 95 } 96 }; 97} 98