2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import android.os.Parcelable;
20 import android.os.Parcel;
23 * A simple object for retrieving the results of a DHCP request.
25 public class DhcpInfo implements Parcelable {
31 public int serverAddress;
33 public int leaseDuration;
39 /** copy constructor {@hide} */
40 public DhcpInfo(DhcpInfo source) {
42 ipAddress = source.ipAddress;
43 gateway = source.gateway;
44 netmask = source.netmask;
47 serverAddress = source.serverAddress;
48 leaseDuration = source.leaseDuration;
52 public String toString() {
53 StringBuffer str = new StringBuffer();
55 str.append("ipaddr "); putAddress(str, ipAddress);
56 str.append(" gateway "); putAddress(str, gateway);
57 str.append(" netmask "); putAddress(str, netmask);
58 str.append(" dns1 "); putAddress(str, dns1);
59 str.append(" dns2 "); putAddress(str, dns2);
60 str.append(" DHCP server "); putAddress(str, serverAddress);
61 str.append(" lease ").append(leaseDuration).append(" seconds");
63 return str.toString();
66 private static void putAddress(StringBuffer buf, int addr) {
67 buf.append(NetworkUtils.intToInetAddress(addr).getHostAddress());
70 /** Implement the Parcelable interface {@hide} */
71 public int describeContents() {
75 /** Implement the Parcelable interface {@hide} */
76 public void writeToParcel(Parcel dest, int flags) {
77 dest.writeInt(ipAddress);
78 dest.writeInt(gateway);
79 dest.writeInt(netmask);
82 dest.writeInt(serverAddress);
83 dest.writeInt(leaseDuration);
86 /** Implement the Parcelable interface {@hide} */
87 public static final Creator<DhcpInfo> CREATOR =
88 new Creator<DhcpInfo>() {
89 public DhcpInfo createFromParcel(Parcel in) {
90 DhcpInfo info = new DhcpInfo();
91 info.ipAddress = in.readInt();
92 info.gateway = in.readInt();
93 info.netmask = in.readInt();
94 info.dns1 = in.readInt();
95 info.dns2 = in.readInt();
96 info.serverAddress = in.readInt();
97 info.leaseDuration = in.readInt();
101 public DhcpInfo[] newArray(int size) {
102 return new DhcpInfo[size];