The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Robert Greenwalt | 70d2c4d | 2011-01-26 13:57:24 -0800 | [diff] [blame] | 21 | import java.net.InetAddress; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * A simple object for retrieving the results of a DHCP request. |
| 25 | */ |
| 26 | public class DhcpInfo implements Parcelable { |
| 27 | public int ipAddress; |
| 28 | public int gateway; |
| 29 | public int netmask; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | public int dns1; |
| 31 | public int dns2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | public int serverAddress; |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | public int leaseDuration; |
| 35 | |
| 36 | public DhcpInfo() { |
| 37 | super(); |
| 38 | } |
| 39 | |
Irfan Sheriff | 31b6232 | 2010-08-30 12:26:00 -0700 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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) { |
Robert Greenwalt | 70d2c4d | 2011-01-26 13:57:24 -0800 | [diff] [blame] | 68 | buf.append(NetworkUtils.intToInetAddress(addr).getHostAddress()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | } |