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