use of java.net.Inet4Address in project guava by google.
the class InetAddressesTest method testForUriStringIPv4.
public void testForUriStringIPv4() {
Inet4Address expected = (Inet4Address) InetAddresses.forString("192.168.1.1");
assertEquals(expected, InetAddresses.forUriString("192.168.1.1"));
}
use of java.net.Inet4Address in project guava by google.
the class InetAddressesTest method testForUriStringIPv4Mapped.
public void testForUriStringIPv4Mapped() {
Inet4Address expected = (Inet4Address) InetAddresses.forString("192.0.2.1");
assertEquals(expected, InetAddresses.forUriString("[::ffff:192.0.2.1]"));
}
use of java.net.Inet4Address in project guava by hceylan.
the class InetAddresses method getTeredoInfo.
/**
* Returns the Teredo information embedded in a Teredo address.
*
* @param ip {@link Inet6Address} to be examined for embedded Teredo
* information
* @return extracted {@code TeredoInfo}
* @throws IllegalArgumentException if the argument is not a valid
* IPv6 Teredo address
*/
public static TeredoInfo getTeredoInfo(Inet6Address ip) {
Preconditions.checkArgument(isTeredoAddress(ip), "Address '%s' is not a Teredo address.", toAddrString(ip));
byte[] bytes = ip.getAddress();
Inet4Address server = getInet4Address(copyOfRange(bytes, 4, 8));
int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;
// Teredo obfuscates the mapped client port, per section 4 of the RFC.
int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;
byte[] clientBytes = copyOfRange(bytes, 12, 16);
for (int i = 0; i < clientBytes.length; i++) {
// Teredo obfuscates the mapped client IP, per section 4 of the RFC.
clientBytes[i] = (byte) ~clientBytes[i];
}
Inet4Address client = getInet4Address(clientBytes);
return new TeredoInfo(server, client, port, flags);
}
use of java.net.Inet4Address in project guava by hceylan.
the class InetAddressesTest method testForUriStringIPv4.
public void testForUriStringIPv4() {
Inet4Address expected = (Inet4Address) InetAddresses.forString("192.168.1.1");
assertEquals(expected, InetAddresses.forUriString("192.168.1.1"));
}
use of java.net.Inet4Address in project XobotOS by xamarin.
the class DataCallState method setLinkProperties.
public SetupResult setLinkProperties(LinkProperties linkProperties, boolean okToUseSystemPropertyDns) {
SetupResult result;
// a failure we'll clear again at the bottom of this code.
if (linkProperties == null)
linkProperties = new LinkProperties();
else
linkProperties.clear();
if (status == FailCause.NONE.getErrorCode()) {
String propertyPrefix = "net." + ifname + ".";
try {
// set interface name
linkProperties.setInterfaceName(ifname);
// set link addresses
if (addresses != null && addresses.length > 0) {
for (String addr : addresses) {
LinkAddress la;
int addrPrefixLen;
String[] ap = addr.split("/");
if (ap.length == 2) {
addr = ap[0];
addrPrefixLen = Integer.parseInt(ap[1]);
} else {
addrPrefixLen = 0;
}
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric ip addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
if (addrPrefixLen == 0) {
// Assume point to point
addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128;
}
if (DBG)
Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen);
la = new LinkAddress(ia, addrPrefixLen);
linkProperties.addLinkAddress(la);
}
}
} else {
throw new UnknownHostException("no address for ifname=" + ifname);
}
// set dns servers
if (dnses != null && dnses.length > 0) {
for (String addr : dnses) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric dns addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addDns(ia);
}
}
} else if (okToUseSystemPropertyDns) {
String[] dnsServers = new String[2];
dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
for (String dnsAddr : dnsServers) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(dnsAddr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addDns(ia);
}
}
} else {
throw new UnknownHostException("Empty dns response and no system default dns");
}
// set gateways
if ((gateways == null) || (gateways.length == 0)) {
String sysGateways = SystemProperties.get(propertyPrefix + "gw");
if (sysGateways != null) {
gateways = sysGateways.split(" ");
} else {
gateways = new String[0];
}
}
for (String addr : gateways) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric gateway addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addRoute(new RouteInfo(ia));
}
}
result = SetupResult.SUCCESS;
} catch (UnknownHostException e) {
Log.d(LOG_TAG, "setLinkProperties: UnknownHostException " + e);
e.printStackTrace();
result = SetupResult.ERR_UnacceptableParameter;
}
} else {
if (version < 4) {
result = SetupResult.ERR_GetLastErrorFromRil;
} else {
result = SetupResult.ERR_RilError;
}
}
// An error occurred so clear properties
if (result != SetupResult.SUCCESS) {
if (DBG) {
Log.d(LOG_TAG, "setLinkProperties: error clearing LinkProperties " + "status=" + status + " result=" + result);
}
linkProperties.clear();
}
return result;
}
Aggregations