blob: 3bede5da50902b0edef247058f76f4c158b57641 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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;
Robert Greenwalt70d2c4d2011-01-26 13:57:24 -080021import java.net.InetAddress;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 public int dns1;
31 public int dns2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 public int serverAddress;
Robert Greenwalt4717c262012-10-31 14:32:53 -070033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 public int leaseDuration;
35
36 public DhcpInfo() {
37 super();
38 }
39
Irfan Sheriff31b62322010-08-30 12:26:00 -070040 /** 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 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) {
Robert Greenwalt70d2c4d2011-01-26 13:57:24 -080068 buf.append(NetworkUtils.intToInetAddress(addr).getHostAddress());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 }
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}