Package org.jnode.driver.net

Examples of org.jnode.driver.net.NetDeviceAPI


        String devId = (args.length > 0) ? args[0] : "eth0";

        try {
            final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
            final Device dev = dm.getDevice(devId);
            final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);
            final EthernetAddress mac = (EthernetAddress) api.getAddress();

            SocketBuffer skbuf = new SocketBuffer();
            skbuf.insert(28);
            skbuf.set16(0, 0x0001); // Hardware type
            skbuf.set16(2, 0x0800); // Protocol type
View Full Code Here


     * @param device
     */
    private void request(ProtocolAddress address, ProtocolAddress myAddress, Device device)
        throws NetworkException {
        // Not found in the cache, make a request
        final NetDeviceAPI api = getAPI(device);
        final HardwareAddress srcHwAddr = api.getAddress();
        final HardwareAddress trgHwAddr = srcHwAddr.getDefaultBroadcastAddress();
        final ARPOperation op = ARPOperation.ARP_REQUEST;
        final int hwtype = srcHwAddr.getType();
        final int ptype = address.getType();

        final ARPHeader hdr =
            new ARPHeader(srcHwAddr, myAddress, trgHwAddr, address, op, hwtype, ptype, EthernetConstants.ETH_ALEN,
                IPv4_PROTOCOL_SIZE);
        final SocketBuffer skbuf = new SocketBuffer();
        skbuf.setProtocolID(EthernetConstants.ETH_P_ARP);
        hdr.prefixTo(skbuf);

        api.transmit(skbuf, trgHwAddr);
    }
View Full Code Here

    /**
     * @throws NetworkException
     * @see org.jnode.net.ipv4.config.impl.NetDeviceConfig#apply(Device)
     */
    public void doApply(Device device) throws NetworkException {
        final NetDeviceAPI api;
        try {
            api = device.getAPI(NetDeviceAPI.class);
        } catch (ApiNotFoundException ex) {
            throw new NetworkException("Device is not a network device", ex);
        }

        if (netmask == null) {
            netmask = address.getDefaultSubnetmask();
        }
        IPv4ProtocolAddressInfo addrInfo =
                (IPv4ProtocolAddressInfo) api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
        if (addrInfo == null) {
            addrInfo = new IPv4ProtocolAddressInfo(address, netmask);
            api.setProtocolAddressInfo(EthernetConstants.ETH_P_IP, addrInfo);
        } else {
            addrInfo.add(address, netmask);
            addrInfo.setDefaultAddress(address, netmask);
        }
    }
View Full Code Here

     * @param address
     * @param netmask
     */
    public static void setDefault(Device device, IPv4Address address, IPv4Address netmask)
        throws NetworkException {
        final NetDeviceAPI api;
        try {
            api = device.getAPI(NetDeviceAPI.class);
        } catch (ApiNotFoundException ex) {
            throw new NetworkException("Device is not a network device", ex);
        }

        if (netmask == null) {
            netmask = address.getDefaultSubnetmask();
        }
        IPv4ProtocolAddressInfo addrInfo =
                (IPv4ProtocolAddressInfo) api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
        if (addrInfo == null) {
            addrInfo = new IPv4ProtocolAddressInfo(address, netmask);
            api.setProtocolAddressInfo(EthernetConstants.ETH_P_IP, addrInfo);
        } else {
            addrInfo.add(address, netmask);
            addrInfo.setDefaultAddress(address, netmask);
        }
    }
View Full Code Here

     */
    public static IPv4Address getLocalAddress() throws UnknownHostException {
        final Collection<Device> devices = DeviceUtils.getDevicesByAPI(NetDeviceAPI.class);
        for (Device dev : devices) {
            try {
                final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);
                final IPv4ProtocolAddressInfo addrInfo =
                        (IPv4ProtocolAddressInfo) api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
                if (addrInfo != null) {
                    final IPv4Address addr = (IPv4Address) addrInfo.getDefaultAddress();
                    if (addr != null) {
                        return addr;
                    }
View Full Code Here

        }
        stat.opackets.inc();

        // The device we will use to transmit the packet
        final Device dev;
        final NetDeviceAPI api;
        // The hardware address we will be sending to
        final HardwareAddress hwDstAddr;

        // Has the destination device been given?
        if (skbuf.getDevice() == null) {
            // The device has not been send, figure out the route ourselves.

            // First lets try to find a route
            final IPv4Route route;
            route = findRoute(hdr, skbuf);
            route.incUseCount();

            // Get the device
            dev = route.getDevice();
            api = route.getDeviceAPI();

            // Get my source address if not already set
            if (hdr.getSource() == null) {
                hdr.setSource(getSourceAddress(route, hdr, skbuf));
            }

            // Get the hardware address for this device
            hwDstAddr = findDstHWAddress(route, hdr, skbuf);
        } else {
            // The device has been given, use it
            dev = skbuf.getDevice();
            try {
                api = dev.getAPI(NetDeviceAPI.class);
            } catch (ApiNotFoundException ex) {
                throw new NetworkException("Device is not a network device", ex);
            }
            // The source address must have been set, check it
            if (hdr.getSource() == null) {
                throw new NetworkException("The source address must have been set");
            }
            // Find the HW destination address
            hwDstAddr = findDstHWAddress(hdr.getDestination(), dev, hdr, skbuf);
        }

        // Set the datalength (if not set)
        if (hdr.getDataLength() == 0) {
            hdr.setDataLength(skbuf.getSize());
        }

        // Set the identification number, if not set before
        if (hdr.getIdentification() == 0) {
            hdr.setIdentification(getNextID());
        }

        // Should we fragment?
        final int mtu = api.getMTU();

        if (hdr.getTotalLength() <= mtu) {
            // We can send the complete packet
            hdr.setMoreFragments(false);
            hdr.setFragmentOffset(0);
View Full Code Here

     */
    private static Device findDevice(DeviceManager dm, IPv4Address target, IPv4Address mask)
        throws NetworkException {
        for (Device dev : dm.getDevicesByAPI(NetDeviceAPI.class)) {
            try {
                final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);
                final IPv4ProtocolAddressInfo addrInfo;
                addrInfo = (IPv4ProtocolAddressInfo) api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
                if (addrInfo != null) {
                    final IPv4Address devAddr = (IPv4Address) addrInfo.getDefaultAddress();
                    if (devAddr.matches(target, mask)) {
                        return dev;
                    }
View Full Code Here

        // the IP address 127.0.0.1 is bound to the loopback network interface.  And if there isn't, JNode's
        // network layer is left in a state that will require a reboot to unjam it (AFAIK). 
        //
        // So, check that loopback is correctly bound ...
        Device loopback = (InitialNaming.lookup(DeviceManager.NAME)).getDevice("loopback");
        NetDeviceAPI api = loopback.getAPI(NetDeviceAPI.class);
        ProtocolAddressInfo info = api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
        if (info == null || !info.contains(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}))) {
            PrintWriter err = getError().getPrintWriter();
            err.format(err_loopback);
            exit(1);
        }
View Full Code Here

        PrintWriter out = getOutput().getPrintWriter();
        if (!argDevice.isSet()) {
            // Print MAC address, MTU and IP address(es) for all network devices.
            final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
            for (Device dev : dm.getDevicesByAPI(NetDeviceAPI.class)) {
                final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);
                out.format(fmt_devices, dev.getId(), api.getAddress(), api.getMTU(),
                           api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
            }
        } else {
            final Device dev = argDevice.getValue();
            final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);

            if (!argIPAddress.isSet()) {
                // Print IP address(es) for device
                out.format(fmt_ip, dev.getId(), api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
            } else {
                // Set IP address for device
                final IPv4Address ip = argIPAddress.getValue();
                final IPv4Address mask = argSubnetMask.getValue();
                final IPv4ConfigurationService cfg = InitialNaming.lookup(IPv4ConfigurationService.NAME);
                cfg.configureDeviceStatic(dev, ip, mask, true);

                // FIXME ... this doesn't show the device's new address because the
                // IPv4 ConfigurationServiceImpl calls processor.apply with the
                // waitUntilReady parameter == false.  (The comment in the code
                // talks about avoiding deadlocks.)
                out.format(fmt_set_ip, dev.getId(), api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
            }
        }
    }
View Full Code Here

            final int protoID = skbuf.getProtocolID();
            final Device dev = skbuf.getDevice();
            if (dev == null) {
                throw new NetworkException("Device not set on SocketBuffer");
            }
            final NetDeviceAPI deviceAPI;
            try {
                deviceAPI = dev.getAPI(NetDeviceAPI.class);
            } catch (ApiNotFoundException ex) {
                throw new NetworkException("Device in SocketBuffer is not a network device");
            }
View Full Code Here

TOP

Related Classes of org.jnode.driver.net.NetDeviceAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.