Build 1.0_r1(from source)

android.net
Class NetworkUtils

java.lang.Object
  extended by android.net.NetworkUtils

public class NetworkUtils
extends Object

Native methods for managing network interfaces.


Constructor Summary
NetworkUtils()
           
 
Method Summary
static int addHostRoute(String interfaceName, int hostaddr)
          Add a route to the specified host via the named interface.
static boolean configureInterface(String interfaceName, DhcpInfo ipInfo)
          When static IP configuration has been specified, configure the network interface according to the values supplied.
static int disableInterface(String interfaceName)
          Bring the named network interface down.
static int getDefaultRoute(String interfaceName)
          Return the gateway address for the default route for the named interface.
static String getDhcpError()
          Return the last DHCP-related error message that was recorded.
static int lookupHost(String hostname)
          Look up a host name and return the result as an int.
static int removeDefaultRoute(String interfaceName)
          Remove the default route for the named interface.
static int removeHostRoutes(String interfaceName)
          Remove host routes that uses the named interface.
static int resetConnections(String interfaceName)
          Reset any sockets that are connected via the named interface.
static boolean runDhcp(String interfaceName, DhcpInfo ipInfo)
          Start the DHCP client daemon, in order to have it request addresses for the named interface, and then configure the interface with those addresses.
static int setDefaultRoute(String interfaceName, int gwayAddr)
          Add a default route for the named interface.
static boolean stopDhcp(String interfaceName)
          Shut down the DHCP client daemon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkUtils

public NetworkUtils()
Method Detail

disableInterface

public static int disableInterface(String interfaceName)
Bring the named network interface down.


addHostRoute

public static int addHostRoute(String interfaceName,
                               int hostaddr)
Add a route to the specified host via the named interface.


setDefaultRoute

public static int setDefaultRoute(String interfaceName,
                                  int gwayAddr)
Add a default route for the named interface.


getDefaultRoute

public static int getDefaultRoute(String interfaceName)
Return the gateway address for the default route for the named interface.


removeHostRoutes

public static int removeHostRoutes(String interfaceName)
Remove host routes that uses the named interface.


removeDefaultRoute

public static int removeDefaultRoute(String interfaceName)
Remove the default route for the named interface.


resetConnections

public static int resetConnections(String interfaceName)
Reset any sockets that are connected via the named interface.


runDhcp

public static boolean runDhcp(String interfaceName,
                              DhcpInfo ipInfo)
Start the DHCP client daemon, in order to have it request addresses for the named interface, and then configure the interface with those addresses. This call blocks until it obtains a result (either success or failure) from the daemon.

Parameters:
interfaceName - the name of the interface to configure
ipInfo - if the request succeeds, this object is filled in with the IP address information.
Returns:
true for success, false for failure

stopDhcp

public static boolean stopDhcp(String interfaceName)
Shut down the DHCP client daemon.

Parameters:
interfaceName - the name of the interface for which the daemon should be stopped
Returns:
true for success, false for failure

getDhcpError

public static String getDhcpError()
Return the last DHCP-related error message that was recorded.

NOTE: This string is not localized, but currently it is only used in logging.

Returns:
the most recent error message, if any

configureInterface

public static boolean configureInterface(String interfaceName,
                                         DhcpInfo ipInfo)
When static IP configuration has been specified, configure the network interface according to the values supplied.

Parameters:
interfaceName - the name of the interface to configure
ipInfo - the IP address, default gateway, and DNS server addresses with which to configure the interface.
Returns:
true for success, false for failure

lookupHost

public static int lookupHost(String hostname)
Look up a host name and return the result as an int. Works if the argument is an IP address in dot notation. Obviously, this can only be used for IPv4 addresses.

Parameters:
hostname - the name of the host (or the IP address)
Returns:
the IP address as an int in network byte order

Build 1.0_r1(from source)

Please submit a feedback, bug or feature