use of java.net.Inet4Address in project Fling by entertailion.
the class FlingFrame method sendMediaUrl.
/**
* Send a uri to the ChromeCast device
*
* @param keycode
*/
protected void sendMediaUrl(String file) {
if (selectedDialServer == null) {
JOptionPane.showMessageDialog(this, resourceBundle.getString("device.select"));
return;
}
isTranscoding = false;
Log.d(LOG_TAG, "sendMediaUrl=" + file);
if (file != null) {
duration = 0;
boolean found = false;
String[] extensions = transcodingExtensionValues.split(",");
for (String extension : extensions) {
if (file.endsWith(extension.trim())) {
found = true;
break;
}
}
if (!found) {
try {
int pos = file.lastIndexOf('.');
String extension = "";
if (pos > -1) {
extension = file.substring(pos);
}
Inet4Address address = getNetworAddress();
if (address != null) {
final String url = "http://" + address.getHostAddress() + ":" + port + "/video" + extension;
if (!rampClient.isClosed()) {
rampClient.stop();
}
rampClient.launchApp(appId == null ? APP_ID : appId, selectedDialServer);
// wait for socket to be ready...
new Thread(new Runnable() {
public void run() {
while (!rampClient.isStarted() && !rampClient.isClosed()) {
try {
// make less than 3 second ping time
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
if (!rampClient.isClosed()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
rampClient.load(url);
}
}
}).start();
} else {
Log.d(LOG_TAG, "could not find a network interface");
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
vlcTranscode(file);
}
// TODO
if (!volume.getValueIsAdjusting()) {
int position = (int) volume.getValue();
// rampClient.volume(position / 100.0f);
}
}
}
use of java.net.Inet4Address in project JAirPort by froks.
the class ServiceInfoImpl method answers.
public Collection<DNSRecord> answers(boolean unique, int ttl, HostInfo localHost) {
List<DNSRecord> list = new ArrayList<DNSRecord>();
if (this.getSubtype().length() > 0) {
list.add(new Pointer(this.getTypeWithSubtype(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
}
list.add(new Text(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, textBytesToValidTextBytes(this.getTextBytes())));
list.add(new Pointer(this.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
list.add(new Service(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, _priority, _weight, _port, localHost.getName()));
// }
for (Inet4Address adr : this.getInet4Addresses()) {
list.add(new DNSRecord.IPv4Address(removeLastDot(this.getServer()), DNSRecordClass.CLASS_IN, false, ttl, adr));
}
list.add(new Pointer("_services._dns-sd._udp.local", DNSRecordClass.CLASS_IN, false, ttl, "_raop._tcp.local"));
return list;
}
use of java.net.Inet4Address in project fqrouter by fqrouter.
the class DnsUtils method resolveAOverUdp.
private static List<Inet4Address> resolveAOverUdp(InetSocketAddress dnsServer, byte[] query) throws Exception {
DatagramSocket datagramSocket = new DatagramSocket();
datagramSocket.setSoTimeout(1000);
try {
datagramSocket.connect(dnsServer.getAddress(), dnsServer.getPort());
datagramSocket.send(new DatagramPacket(query, query.length));
while (true) {
List<Inet4Address> ips = readIps(datagramSocket);
if (!isWrong(ips)) {
return ips;
}
}
} finally {
datagramSocket.close();
}
}
use of java.net.Inet4Address in project fqrouter by fqrouter.
the class DnsUtils method toIps.
private static List<Inet4Address> toIps(byte[] buffer) {
DNSRecord[] records = DNSConnection.decode(buffer);
List<Inet4Address> ips = new ArrayList<Inet4Address>();
for (DNSRecord record : records) {
if (DNSRecord.A == record.getRType()) {
if (record.getRData().length > 0) {
ips.add((Inet4Address) record.getRData()[0]);
}
}
}
return ips;
}
use of java.net.Inet4Address in project guava by google.
the class InetAddresses method getCoercedIPv4Address.
/**
* Coerces an IPv6 address into an IPv4 address.
*
* <p>HACK: As long as applications continue to use IPv4 addresses for indexing into tables,
* accounting, et cetera, it may be necessary to <b>coerce</b> IPv6 addresses into IPv4 addresses.
* This function does so by hashing the upper 64 bits into {@code 224.0.0.0/3} (64 bits into 29
* bits).
*
* <p>A "coerced" IPv4 address is equivalent to itself.
*
* <p>NOTE: This function is failsafe for security purposes: ALL IPv6 addresses (except localhost
* (::1)) are hashed to avoid the security risk associated with extracting an embedded IPv4
* address that might permit elevated privileges.
*
* @param ip {@link InetAddress} to "coerce"
* @return {@link Inet4Address} represented "coerced" address
* @since 7.0
*/
public static Inet4Address getCoercedIPv4Address(InetAddress ip) {
if (ip instanceof Inet4Address) {
return (Inet4Address) ip;
}
// Special cases:
byte[] bytes = ip.getAddress();
boolean leadingBytesOfZero = true;
for (int i = 0; i < 15; ++i) {
if (bytes[i] != 0) {
leadingBytesOfZero = false;
break;
}
}
if (leadingBytesOfZero && (bytes[15] == 1)) {
// ::1
return LOOPBACK4;
} else if (leadingBytesOfZero && (bytes[15] == 0)) {
// ::0
return ANY4;
}
Inet6Address ip6 = (Inet6Address) ip;
long addressAsLong = 0;
if (hasEmbeddedIPv4ClientAddress(ip6)) {
addressAsLong = getEmbeddedIPv4ClientAddress(ip6).hashCode();
} else {
// Just extract the high 64 bits (assuming the rest is user-modifiable).
addressAsLong = ByteBuffer.wrap(ip6.getAddress(), 0, 8).getLong();
}
// Many strategies for hashing are possible. This might suffice for now.
int coercedHash = Hashing.murmur3_32().hashLong(addressAsLong).asInt();
// Squash into 224/4 Multicast and 240/4 Reserved space (i.e. 224/3).
coercedHash |= 0xe0000000;
// illegal value is 255.255.255.255.
if (coercedHash == 0xffffffff) {
coercedHash = 0xfffffffe;
}
return getInet4Address(Ints.toByteArray(coercedHash));
}
Aggregations