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