Package org.jnode.net.ipv4.tftp

Examples of org.jnode.net.ipv4.tftp.TFTPClient


    public String toString() {
        return "UDP srcPort=" + srcPort + ", dstPort=" + dstPort + ", dataLength=" + getDataLength();
    }

    private int calcChecksum(SocketBuffer skbuf, int offset) {
        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        final SocketBuffer phdr = new SocketBuffer(12);
        phdr.insert(12);
        ipHdr.getSource().writeTo(phdr, 0);
        ipHdr.getDestination().writeTo(phdr, 4);
        phdr.set(8, 0);
        phdr.set(9, ipHdr.getProtocol());
        phdr.set16(10, udpLength);
        phdr.append(offset, skbuf);
        final int csLength = udpLength + 12;
        return IPv4Utils.calcChecksum(phdr, 0, csLength);
    }
View Full Code Here


    /**
     * @see java.net.DatagramSocketImpl#receive(java.net.DatagramPacket)
     */
    protected void onReceive(DatagramPacket p, SocketBuffer skbuf) throws IOException {
        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        final UDPHeader udpHdr = (UDPHeader) skbuf.getTransportLayerHeader();
        p.setData(skbuf.toByteArray(), 0, skbuf.getSize());
        p.setAddress(ipHdr.getSource().toInetAddress());
        p.setPort(udpHdr.getSrcPort());
    }
View Full Code Here

     * @see java.net.DatagramSocketImpl#send(java.net.DatagramPacket)
     */
    protected void send(DatagramPacket p) throws IOException {

        final IPv4Address dstAddress = new IPv4Address(p.getAddress());
        final IPv4Header ipHdr;
        ipHdr = new IPv4Header(getTos(), getTimeToLive(), IPPROTO_UDP, dstAddress, p.getLength() + UDP_HLEN);
        if (!getLocalAddress().isAnyLocalAddress() || (getDevice() != null)) {
            ipHdr.setSource(new IPv4Address(getLocalAddress()));
        }
        final UDPHeader udpHdr;
        final int srcPort = getLocalPort();
        // final int srcPort = p.getPort(); // or getLocalPort???? TODO Fix
        // srcPort issue
View Full Code Here

     * @param hdr
     * @param skbuf
     */
    private synchronized void deliver(UDPHeader hdr, SocketBuffer skbuf) throws SocketException {
        final Integer lport = hdr.getDstPort();
        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        final UDPDatagramSocketImpl socket = (UDPDatagramSocketImpl) sockets.get(lport);
        if (socket != null) {
            final InetAddress laddr = socket.getLocalAddress();
            if (laddr.isAnyLocalAddress() || laddr.equals(ipHdr.getDestination().toInetAddress())) {
                if (socket.deliverReceived(skbuf)) {
                    return;
                }
            }
        }
        stat.noport.inc();
        if (ipHdr.getDestination().isBroadcast()) {
            stat.noportbcast.inc();
        }
        // Send a port unreachable back
        icmp.sendPortUnreachable(skbuf);
    }
View Full Code Here

     *
     * @param hdr
     * @param skbuf
     */
    private void sendEchoReply(ICMPEchoHeader hdr, SocketBuffer skbuf) throws SocketException {
        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        final IPv4Header ipReplyHdr = new IPv4Header(ipHdr);
        ipReplyHdr.swapAddresses();
        ipReplyHdr.setTtl(0xFF);
        send(ipReplyHdr, hdr.createReplyHeader(), new SocketBuffer(skbuf));
    }
View Full Code Here

        if (srcBuf.getLinkLayerHeader().getDestinationAddress().isBroadcast()) {
            return;
        }

        // Gets the original IP header
        final IPv4Header origIpHdr = (IPv4Header) srcBuf.getNetworkLayerHeader();

        // Do not respond to networklayer broadcast/multicast messages
        if (origIpHdr.getDestination().isBroadcast() || origIpHdr.getDestination().isMulticast()) {
            return;
        }

        final int tos = 0;
        final int ttl = 0xFF;
        final IPv4Address dstAddr = origIpHdr.getSource();

        // Build the response ICMP header
        final ICMPHeader icmpHdr = new ICMPUnreachableHeader(code);
        // Build the response IP header
        final IPv4Header ipHdr = new IPv4Header(tos, ttl, IPv4Constants.IPPROTO_ICMP, dstAddr, 0);

        // Unpull the original transportlayer header
        srcBuf.unpull(srcBuf.getTransportLayerHeader().getLength());

        // Unpull the original IP header
View Full Code Here

     *
     * @param hdr
     * @param skbuf
     */
    private void deliver(IPv4Header hdr, SocketBuffer skbuf) throws SocketException {
        final IPv4Protocol protocol;
        try {
            protocol = getProtocol(hdr.getProtocol());
            protocol.receive(skbuf);
        } catch (NoSuchProtocolException ex) {
            log.debug("Found unknown IP src=" + hdr.getSource() + ", dst=" + hdr.getDestination() +
                    ", prot=0x" + NumberUtils.hex(hdr.getProtocol(), 2));
        }
    }
View Full Code Here

     * @param protocolID
     * @throws NoSuchProtocolException
     *             No protocol with the given ID was found.
     */
    public IPv4Protocol getProtocol(int protocolID) throws NoSuchProtocolException {
        final IPv4Protocol protocol;
        protocol = (IPv4Protocol) protocols.get(protocolID);
        if (protocol == null) {
            throw new NoSuchProtocolException("with ID " + protocolID);
        }
        return protocol;
View Full Code Here

        }

        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

        // Update the ARP cache for the source address
        updateARPCache(skbuf.getLinkLayerHeader().getSourceAddress(), hdr.getSourceAddress());

        // Get my IP address
        final IPv4ProtocolAddressInfo myAddrInfo =
                (IPv4ProtocolAddressInfo) deviceAPI.getProtocolAddressInfo(getProtocolID());
        if (myAddrInfo == null) {
            stat.nodevaddr.inc();
        }

        // Should I process this packet, or is it for somebody else?
        final IPv4Address dstAddr = hdr.getDestination();
        final boolean shouldProcess;
        if (myAddrInfo != null) {
            shouldProcess = myAddrInfo.contains(dstAddr);
        } else {
            // I don't have an IP address yet, if the linklayer says
            // it is for me, we'll process it, otherwise we'll drop it.
            shouldProcess = !skbuf.getLinkLayerHeader().getDestinationAddress().isBroadcast();
        }
View Full Code Here

TOP

Related Classes of org.jnode.net.ipv4.tftp.TFTPClient

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.