InterfaceConfiguration.java revision 353ced79b49269151b056c4b06dc632801b59497
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
17package android.net;
18
19import android.os.Parcelable;
20import android.os.Parcel;
21
22/**
23 * A simple object for retrieving / setting an interfaces configuration
24 * @hide
25 */
26public class InterfaceConfiguration implements Parcelable {
27    public String hwAddr;
28    public int ipAddr;
29    public int netmask;
30    public String interfaceFlags;
31
32    public InterfaceConfiguration() {
33        super();
34    }
35
36    public String toString() {
37        StringBuffer str = new StringBuffer();
38
39        str.append("ipddress "); putAddress(str, ipAddr);
40        str.append(" netmask "); putAddress(str, netmask);
41        str.append(" flags ").append(interfaceFlags);
42        str.append(" hwaddr ").append(hwAddr);
43
44        return str.toString();
45    }
46
47    private static void putAddress(StringBuffer buf, int addr) {
48        buf.append(addr  & 0xff).append('.').
49            append((addr >>>= 8) & 0xff).append('.').
50            append((addr >>>= 8) & 0xff).append('.').
51            append((addr >>>= 8) & 0xff);
52    }
53
54    /** Implement the Parcelable interface {@hide} */
55    public int describeContents() {
56        return 0;
57    }
58
59    /** Implement the Parcelable interface {@hide} */
60    public void writeToParcel(Parcel dest, int flags) {
61        dest.writeString(hwAddr);
62        dest.writeInt(ipAddr);
63        dest.writeInt(netmask);
64        dest.writeString(interfaceFlags);
65    }
66
67    /** Implement the Parcelable interface {@hide} */
68    public static final Creator<InterfaceConfiguration> CREATOR =
69        new Creator<InterfaceConfiguration>() {
70            public InterfaceConfiguration createFromParcel(Parcel in) {
71                InterfaceConfiguration info = new InterfaceConfiguration();
72                info.hwAddr = in.readString();
73                info.ipAddr = in.readInt();
74                info.netmask = in.readInt();
75                info.interfaceFlags = in.readString();
76                return info;
77            }
78
79            public InterfaceConfiguration[] newArray(int size) {
80                return new InterfaceConfiguration[size];
81            }
82        };
83}
84