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     public int dns1;
30     public int dns2;
31     public int serverAddress;
32 
33     public int leaseDuration;
34 
DhcpInfo()35     public DhcpInfo() {
36         super();
37     }
38 
39     /** copy constructor {@hide} */
DhcpInfo(DhcpInfo source)40     public DhcpInfo(DhcpInfo source) {
41         if (source != null) {
42             ipAddress = source.ipAddress;
43             gateway = source.gateway;
44             netmask = source.netmask;
45             dns1 = source.dns1;
46             dns2 = source.dns2;
47             serverAddress = source.serverAddress;
48             leaseDuration = source.leaseDuration;
49         }
50     }
51 
toString()52     public String toString() {
53         StringBuffer str = new StringBuffer();
54 
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");
62 
63         return str.toString();
64     }
65 
putAddress(StringBuffer buf, int addr)66     private static void putAddress(StringBuffer buf, int addr) {
67         buf.append(NetworkUtils.intToInetAddress(addr).getHostAddress());
68     }
69 
70     /** Implement the Parcelable interface {@hide} */
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     /** Implement the Parcelable interface {@hide} */
writeToParcel(Parcel dest, int flags)76     public void writeToParcel(Parcel dest, int flags) {
77         dest.writeInt(ipAddress);
78         dest.writeInt(gateway);
79         dest.writeInt(netmask);
80         dest.writeInt(dns1);
81         dest.writeInt(dns2);
82         dest.writeInt(serverAddress);
83         dest.writeInt(leaseDuration);
84     }
85 
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();
98                 return info;
99             }
100 
101             public DhcpInfo[] newArray(int size) {
102                 return new DhcpInfo[size];
103             }
104         };
105 }
106