资源简介
android4.4 DhcpInfoInternal.java
代码片段和文件信息
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License Version 2.0 (the “License“);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing software
* distributed under the License is distributed on an “AS IS“ BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import android.text.TextUtils;
import android.util.Log;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* A simple object for retrieving the results of a DHCP request.
* Replaces (internally) the IPv4-only DhcpInfo class.
* @hide
*/
public class DhcpInfoInternal {
private final static String TAG = “DhcpInfoInternal“;
public String ipAddress;
public int prefixLength;
public String dns1;
public String dns2;
public String serverAddress;
public int leaseDuration;
/**
* Vendor specific information (from RFC 2132).
*/
public String vendorInfo;
private Collection mRoutes;
public DhcpInfoInternal() {
mRoutes = new ArrayList();
}
public void addRoute(RouteInfo routeInfo) {
mRoutes.add(routeInfo);
}
public Collection getRoutes() {
return Collections.unmodifiableCollection(mRoutes);
}
private int convertToInt(String addr) {
if (addr != null) {
try {
InetAddress inetAddress = NetworkUtils.numericToInetAddress(addr);
if (inetAddress instanceof Inet4Address) {
return NetworkUtils.inetAddressToInt((Inet4Address)inetAddress);
}
} catch (IllegalArgumentException e) {}
}
return 0;
}
public DhcpInfo makeDhcpInfo() {
DhcpInfo info = new DhcpInfo();
info.ipAddress = convertToInt(ipAddress);
for (RouteInfo route : mRoutes) {
if (route.isDefaultRoute()) {
info.gateway = convertToInt(route.getGateway().getHostAddress());
break;
}
}
try {
InetAddress inetAddress = NetworkUtils.numericToInetAddress(ipAddress);
info.netmask = NetworkUtils.prefixLeng
- 上一篇:Java从入门到精通光盘资料
- 下一篇:用TXT做数据库的简单ATM取款机系统
评论
共有 条评论