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 17 package android.net; 18 19 import android.os.Parcelable; 20 import android.os.Parcel; 21 22 /** 23 * A simple object for retrieving the results of a DHCP request. 24 */ 25 public class DhcpInfo implements Parcelable { 26 public int ipAddress; 27 public int gateway; 28 public int netmask; 29 30 public int dns1; 31 public int dns2; 32 33 public int serverAddress; 34 public int leaseDuration; 35 DhcpInfo()36 public DhcpInfo() { 37 super(); 38 } 39 toString()40 public String toString() { 41 StringBuffer str = new StringBuffer(); 42 43 str.append("ipaddr "); putAddress(str, ipAddress); 44 str.append(" gateway "); putAddress(str, gateway); 45 str.append(" netmask "); putAddress(str, netmask); 46 str.append(" dns1 "); putAddress(str, dns1); 47 str.append(" dns2 "); putAddress(str, dns2); 48 str.append(" DHCP server "); putAddress(str, serverAddress); 49 str.append(" lease ").append(leaseDuration).append(" seconds"); 50 51 return str.toString(); 52 } 53 putAddress(StringBuffer buf, int addr)54 private static void putAddress(StringBuffer buf, int addr) { 55 buf.append(addr & 0xff).append('.'). 56 append((addr >>>= 8) & 0xff).append('.'). 57 append((addr >>>= 8) & 0xff).append('.'). 58 append((addr >>>= 8) & 0xff); 59 } 60 61 /** Implement the Parcelable interface {@hide} */ describeContents()62 public int describeContents() { 63 return 0; 64 } 65 66 /** Implement the Parcelable interface {@hide} */ writeToParcel(Parcel dest, int flags)67 public void writeToParcel(Parcel dest, int flags) { 68 dest.writeInt(ipAddress); 69 dest.writeInt(gateway); 70 dest.writeInt(netmask); 71 dest.writeInt(dns1); 72 dest.writeInt(dns2); 73 dest.writeInt(serverAddress); 74 dest.writeInt(leaseDuration); 75 } 76 77 /** Implement the Parcelable interface {@hide} */ 78 public static final Creator<DhcpInfo> CREATOR = 79 new Creator<DhcpInfo>() { 80 public DhcpInfo createFromParcel(Parcel in) { 81 DhcpInfo info = new DhcpInfo(); 82 info.ipAddress = in.readInt(); 83 info.gateway = in.readInt(); 84 info.netmask = in.readInt(); 85 info.dns1 = in.readInt(); 86 info.dns2 = in.readInt(); 87 info.serverAddress = in.readInt(); 88 info.leaseDuration = in.readInt(); 89 return info; 90 } 91 92 public DhcpInfo[] newArray(int size) { 93 return new DhcpInfo[size]; 94 } 95 }; 96 } 97