use of java.net.Inet4Address in project platform_frameworks_base by android.
the class DhcpPacket method toDhcpResults.
/**
* Construct a DhcpResults object from a DHCP reply packet.
*/
public DhcpResults toDhcpResults() {
Inet4Address ipAddress = mYourIp;
if (ipAddress.equals(Inet4Address.ANY)) {
ipAddress = mClientIp;
if (ipAddress.equals(Inet4Address.ANY)) {
return null;
}
}
int prefixLength;
if (mSubnetMask != null) {
try {
prefixLength = NetworkUtils.netmaskToPrefixLength(mSubnetMask);
} catch (IllegalArgumentException e) {
// Non-contiguous netmask.
return null;
}
} else {
prefixLength = NetworkUtils.getImplicitNetmask(ipAddress);
}
DhcpResults results = new DhcpResults();
try {
results.ipAddress = new LinkAddress(ipAddress, prefixLength);
} catch (IllegalArgumentException e) {
return null;
}
if (mGateways.size() > 0) {
results.gateway = mGateways.get(0);
}
results.dnsServers.addAll(mDnsServers);
results.domains = mDomainName;
results.serverAddress = mServerIdentifier;
results.vendorInfo = mVendorInfo;
results.leaseDuration = (mLeaseTime != null) ? mLeaseTime : INFINITE_LEASE;
results.mtu = (mMtu != null && MIN_MTU <= mMtu && mMtu <= MAX_MTU) ? mMtu : 0;
return results;
}
use of java.net.Inet4Address in project platform_frameworks_base by android.
the class DhcpOfferPacket method toString.
public String toString() {
String s = super.toString();
String dnsServers = ", DNS servers: ";
if (mDnsServers != null) {
for (Inet4Address dnsServer : mDnsServers) {
dnsServers += dnsServer + " ";
}
}
return s + " OFFER, ip " + mYourIp + ", mask " + mSubnetMask + dnsServers + ", gateways " + mGateways + " lease time " + mLeaseTime + ", domain " + mDomainName;
}
use of java.net.Inet4Address in project platform_frameworks_base by android.
the class DhcpPacket method addTlv.
/**
* Adds an optional parameter containing a list of IP addresses.
*/
protected static void addTlv(ByteBuffer buf, byte type, List<Inet4Address> addrs) {
if (addrs == null || addrs.size() == 0)
return;
int optionLen = 4 * addrs.size();
if (optionLen > MAX_OPTION_LEN) {
throw new IllegalArgumentException("DHCP option too long: " + optionLen + " vs. " + MAX_OPTION_LEN);
}
buf.put(type);
buf.put((byte) (optionLen));
for (Inet4Address addr : addrs) {
buf.put(addr.getAddress());
}
}
use of java.net.Inet4Address in project platform_frameworks_base by android.
the class CommonTimeUtils method transactSetSockaddr.
public int transactSetSockaddr(int method_code, InetSocketAddress addr) {
android.os.Parcel data = android.os.Parcel.obtain();
android.os.Parcel reply = android.os.Parcel.obtain();
int ret_val = ERROR;
try {
data.writeInterfaceToken(mInterfaceDesc);
if (null == addr) {
data.writeInt(0);
} else {
data.writeInt(1);
final InetAddress a = addr.getAddress();
final byte[] b = a.getAddress();
final int p = addr.getPort();
if (a instanceof Inet4Address) {
int v4addr = (((int) b[0] & 0xFF) << 24) | (((int) b[1] & 0xFF) << 16) | (((int) b[2] & 0xFF) << 8) | ((int) b[3] & 0xFF);
data.writeInt(AF_INET);
data.writeInt(v4addr);
data.writeInt(p);
} else if (a instanceof Inet6Address) {
int i;
Inet6Address v6 = (Inet6Address) a;
data.writeInt(AF_INET6);
for (i = 0; i < 4; ++i) {
int aword = (((int) b[(i * 4) + 0] & 0xFF) << 24) | (((int) b[(i * 4) + 1] & 0xFF) << 16) | (((int) b[(i * 4) + 2] & 0xFF) << 8) | ((int) b[(i * 4) + 3] & 0xFF);
data.writeInt(aword);
}
data.writeInt(p);
// flow info
data.writeInt(0);
data.writeInt(v6.getScopeId());
} else {
return ERROR_BAD_VALUE;
}
}
mRemote.transact(method_code, data, reply, 0);
ret_val = reply.readInt();
} catch (RemoteException e) {
ret_val = ERROR_DEAD_OBJECT;
} finally {
reply.recycle();
data.recycle();
}
return ret_val;
}
use of java.net.Inet4Address in project hazelcast by hazelcast.
the class AddressHelper method getPossibleSocketAddresses.
public static Collection<InetSocketAddress> getPossibleSocketAddresses(int port, String scopedAddress, int portTryCount) {
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(scopedAddress);
} catch (UnknownHostException ignored) {
Logger.getLogger(AddressHelper.class).finest("Address not available", ignored);
}
int possiblePort = port;
if (possiblePort == -1) {
possiblePort = INITIAL_FIRST_PORT;
}
final Collection<InetSocketAddress> socketAddresses = new LinkedList<InetSocketAddress>();
if (inetAddress == null) {
for (int i = 0; i < portTryCount; i++) {
socketAddresses.add(new InetSocketAddress(scopedAddress, possiblePort + i));
}
} else if (inetAddress instanceof Inet4Address) {
for (int i = 0; i < portTryCount; i++) {
socketAddresses.add(new InetSocketAddress(inetAddress, possiblePort + i));
}
} else if (inetAddress instanceof Inet6Address) {
final Collection<Inet6Address> addresses = getPossibleInetAddressesFor((Inet6Address) inetAddress);
for (Inet6Address inet6Address : addresses) {
for (int i = 0; i < portTryCount; i++) {
socketAddresses.add(new InetSocketAddress(inet6Address, possiblePort + i));
}
}
}
return socketAddresses;
}
Aggregations