Examples of NetworkException


Examples of org.jnode.driver.net.NetworkException

        // Set the network layer header
        skbuf.setNetworkLayerHeader(hdr);

        // The destination address must have been set, check it
        if (hdr.getDestination() == null) {
            throw new NetworkException("The destination address must have been set");
        }
        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);
            sendPacket(api, hwDstAddr, hdr, skbuf);
        } else if (hdr.isDontFragment()) {
            // This packet cannot be send of this device
            throw new NetworkException("Packet is too large, mtu=" + mtu);
        } else {
            // Fragment the packet and send the fragments
            fragmentPacket(api, hwDstAddr, hdr, skbuf, mtu);
        }
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

     */
    private IPv4Address getSourceAddress(IPv4Route route, IPv4Header hdr, SocketBuffer skbuf)
        throws NetworkException {
        final Object addrInfo = route.getDeviceAPI().getProtocolAddressInfo(ETH_P_IP);
        if (addrInfo == null) {
            throw new NetworkException("Source IP address not configured for device " +
                    route.getDevice().getId());
        }
        if (!(addrInfo instanceof IPv4ProtocolAddressInfo)) {
            throw new NetworkException("Source IP address not valid class for device " +
                    route.getDevice().getId());
        }
        return (IPv4Address) ((IPv4ProtocolAddressInfo) addrInfo).getDefaultAddress();
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

            dstAddr = hdr.getDestination();
        }
        try {
            return arp.getHardwareAddress(dstAddr, hdr.getSource(), route.getDevice(), arpTimeout);
        } catch (TimeoutException ex) {
            throw new NetworkException("Cannot find hardware address of " + dstAddr, ex);
        }
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

            return null;
        } else {
            try {
                return arp.getHardwareAddress(destination, hdr.getSource(), device, arpTimeout);
            } catch (TimeoutException ex) {
                throw new NetworkException("Cannot find hardware address of " + destination, ex);
            }
        }
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

     * @throws NetworkException
     */
    private void fragmentPacket(NetDeviceAPI api, HardwareAddress dstHwAddr, IPv4Header hdr,
            SocketBuffer skbuf, int mtu) throws NetworkException {
        if ((hdr.getLength() + IP_MIN_FRAG_SIZE) > mtu) {
            throw new NetworkException("MTU is too small for IP, mtu=" + mtu);
        }

        // The complete packet
        final byte[] packet = skbuf.toByteArray();
        int length = packet.length;
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

        if (arp == null) {
            try {
                arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(
                                EthernetConstants.ETH_P_ARP);
            } catch (NoSuchProtocolException ex) {
                throw new NetworkException("Cannot find ARP layer", ex);
            }
        }
        return arp;
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

                    }
                });
            } catch (SecurityException ex) {
                log.error("No permission to set DatagramSocketImplFactory", ex);
            } catch (PrivilegedActionException ex) {
                throw new NetworkException(ex.getException());
            }
        } catch (IOException ex) {
            throw new NetworkException(ex);
        }
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

            // Find the device ourselves
            final DeviceManager dm;
            try {
                dm = InitialNaming.lookup(DeviceManager.NAME);
            } catch (NameNotFoundException ex) {
                throw new NetworkException("Cannot find DeviceManager", ex);
            }
            device = findDevice(dm, target, target.getDefaultSubnetmask());
        }

        final IPv4NetworkLayer ipNL;
        try {
            ipNL = (IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_IP);
        } catch (NoSuchProtocolException ex) {
            throw new NetworkException("Cannot find IPv4 network layer", ex);
        }
        final IPv4RoutingTable rt = ipNL.getRoutingTable();
        rt.add(new IPv4Route(target, null, gateway, device));
    }
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

        throws NetworkException {
        final IPv4NetworkLayer ipNL;
        try {
            ipNL = (IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_IP);
        } catch (NoSuchProtocolException ex) {
            throw new NetworkException("Cannot find IPv4 network layer", ex);
        }
        final IPv4RoutingTable rt = ipNL.getRoutingTable();

        for (IPv4Route route : rt.entries()) {
            if (!route.getDestination().equals(target)) {
View Full Code Here

Examples of org.jnode.driver.net.NetworkException

                }
            } catch (ApiNotFoundException ex) {
                // Should not happen, but if it happens anyway, just ignore it.
            }
        }
        throw new NetworkException("No device found for " + target + '/' + mask);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.