blob: 98bab44e19fb848a7d9615751d32bfbe9a2c4350 [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;
21
22/**
23 * A simple object for retrieving the results of a DHCP request.
24 */
25public class DhcpInfo implements Parcelable {
26 public int ipAddress;
27 public int gateway;
28 public int netmask;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029 public int dns1;
30 public int dns2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 public int serverAddress;
Robert Greenwalt4717c262012-10-31 14:32:53 -070032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 public int leaseDuration;
34
35 public DhcpInfo() {
36 super();
37 }
38
Irfan Sheriff31b62322010-08-30 12:26:00 -070039 /** copy constructor {@hide} */
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 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
66 private static void putAddress(StringBuffer buf, int addr) {
Robert Greenwalt70d2c4d2011-01-26 13:57:24 -080067 buf.append(NetworkUtils.intToInetAddress(addr).getHostAddress());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 }
69
70 /** Implement the Parcelable interface {@hide} */
71 public int describeContents() {
72 return 0;
73 }
74
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);
80 dest.writeInt(dns1);
81 dest.writeInt(dns2);
82 dest.writeInt(serverAddress);
83 dest.writeInt(leaseDuration);
84 }
85
86 /** Implement the Parcelable interface {@hide} */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070087 public static final @android.annotation.NonNull Creator<DhcpInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 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}