Package org.jnode.net.ipv4.config.impl

Examples of org.jnode.net.ipv4.config.impl.Route


        }

        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;
                    }
                }
            } catch (ApiNotFoundException ex) {
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;
                    }
                }
            } catch (ApiNotFoundException ex) {
View Full Code Here

        // 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));
            }
View Full Code Here

            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

        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

        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)) {
                continue;
            }
            if (gateway != null) {
                if (!gateway.equals(route.getGateway())) {
                    continue;
                }
            }
            if (device != null) {
                if (device != route.getDevice()) {
                    continue;
                }
            }

            rt.remove(route);
            return;
        }
    }
View Full Code Here

    /**
     * @see org.jnode.net.ipv4.config.impl.NetDeviceConfig#apply(org.jnode.driver.Device)
     */
    public void doApply(Device device) throws NetworkException {
        final BOOTPClient bootp = new BOOTPClient();
        try {
            bootp.configureDevice(device);
        } catch (IOException ex) {
            throw new NetworkException(ex);
        }
    }
View Full Code Here

        this(hdr);
        messageType = msgType;
    }

    public DHCPMessage(SocketBuffer skbuf) {
        this(new BOOTPHeader(skbuf));
        int i = BOOTPHeader.SIZE + 4;
        int optionCode = skbuf.get(i);
        while (optionCode != END_OPTION) {
            if (optionCode == PAD_OPTION) {
                i++;
View Full Code Here

        return msg.toDatagramPacket();
    }

    protected boolean processResponse(int transactionID, DatagramPacket packet) throws IOException {
        DHCPMessage msg = new DHCPMessage(packet);
        BOOTPHeader hdr = msg.getHeader();
        if (hdr.getOpcode() != BOOTPHeader.BOOTREPLY) {
            // Not a response
            return false;
        }
        if (hdr.getTransactionID() != transactionID) {
            // Not for me
            return false;
        }

        // debug the DHCP message
        if (log.isDebugEnabled()) {
            log.debug("Got Client IP address  : " + hdr.getClientIPAddress());
            log.debug("Got Your IP address    : " + hdr.getYourIPAddress());
            log.debug("Got Server IP address  : " + hdr.getServerIPAddress());
            log.debug("Got Gateway IP address : " + hdr.getGatewayIPAddress());
            for (int n = 1; n < 255; n++) {
                byte[] value = msg.getOption(n);
                if (value != null) {
                    if (value.length == 1) {
                        log.debug("Option " + n + " : " + (int) (value[0]));
                    } else if (value.length == 2) {
                        log.debug("Option " + n + " : " + ((value[0] << 8) | value[1]));
                    } else if (value.length == 4) {
                        log.debug("Option " + n + " : " +
                                InetAddress.getByAddress(value).toString());
                    } else {
                        log.debug("Option " + n + " : " + new String(value));
                    }
                }
            }
        }

        switch (msg.getMessageType()) {
            case DHCPMessage.DHCPOFFER:
                byte[] serverID = msg.getOption(DHCPMessage.SERVER_IDENTIFIER_OPTION);
                byte[] requestedIP = hdr.getYourIPAddress().getAddress();
                hdr = new BOOTPHeader(
                        BOOTPHeader.BOOTREQUEST, transactionID, 0,
                        hdr.getClientIPAddress(), hdr.getClientHwAddress());
                msg = new DHCPMessage(hdr, DHCPMessage.DHCPREQUEST);
                msg.setOption(DHCPMessage.REQUESTED_IP_ADDRESS_OPTION, requestedIP);
                msg.setOption(DHCPMessage.SERVER_IDENTIFIER_OPTION, serverID);
                packet = msg.toDatagramPacket();
                packet.setAddress(IPv4Address.BROADCAST_ADDRESS);
View Full Code Here

TOP

Related Classes of org.jnode.net.ipv4.config.impl.Route

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.