Search in sources :

Example 96 with Inet4Address

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);
        }
    }
}
Also used : Inet4Address(java.net.Inet4Address) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 97 with Inet4Address

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;
}
Also used : Inet4Address(java.net.Inet4Address) ArrayList(java.util.ArrayList) Service(javax.jmdns.impl.DNSRecord.Service) Pointer(javax.jmdns.impl.DNSRecord.Pointer) Text(javax.jmdns.impl.DNSRecord.Text)

Example 98 with Inet4Address

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();
    }
}
Also used : Inet4Address(java.net.Inet4Address) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket)

Example 99 with Inet4Address

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;
}
Also used : Inet4Address(java.net.Inet4Address) DNSRecord(net.sf.ivmaidns.dns.DNSRecord) ArrayList(java.util.ArrayList)

Example 100 with Inet4Address

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));
}
Also used : Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address)

Aggregations

Inet4Address (java.net.Inet4Address)184 InetAddress (java.net.InetAddress)85 Inet6Address (java.net.Inet6Address)45 NetworkInterface (java.net.NetworkInterface)39 UnknownHostException (java.net.UnknownHostException)28 LinkAddress (android.net.LinkAddress)24 SocketException (java.net.SocketException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)19 InterfaceAddress (java.net.InterfaceAddress)17 ByteBuffer (java.nio.ByteBuffer)17 RouteInfo (android.net.RouteInfo)12 LinkProperties (android.net.LinkProperties)7 InetSocketAddress (java.net.InetSocketAddress)6 Test (org.junit.Test)6 WifiDisplay (android.hardware.display.WifiDisplay)5 WifiDisplaySessionInfo (android.hardware.display.WifiDisplaySessionInfo)5 DhcpResults (android.net.DhcpResults)5 IpConfiguration (android.net.IpConfiguration)5 IpAssignment (android.net.IpConfiguration.IpAssignment)5