Package org.jnode.net.ipv4.layer

Examples of org.jnode.net.ipv4.layer.IPv4NetworkLayer


        while (length > 0) {
            final int chunk = Math.min(length, mss);
            // Create the TCP header
            final TCPHeader hdr = createOutgoingTCPHeader(TCPF_ACK, inChannel.getRcvNext());
            // Create the IP header
            final IPv4Header ipHdr = createOutgoingIPv4Header();
            // Send the chunk of data
            outChannel.send(ipHdr, hdr, data, offset, chunk);
            // Update length & offset
            offset += chunk;
            length -= chunk;
View Full Code Here


        this.windowSize = skbuf.get16(14);

        final int checksum = skbuf.get16(16);
        this.urgentPointer = skbuf.get16(18);

        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        this.tcpLength = ipHdr.getDataLength() - headerLength;

        if (checksum == 0) {
            log.debug("No checksum set");
            this.checksumOk = true;
        } else {
            // Create the pseudo header for checksum calculation
            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, tcpLength + headerLength);
            phdr.append(skbuf);

            final int ccs2 = IPv4Utils.calcChecksum(phdr, 0, headerLength + tcpLength + 12);
            this.checksumOk = (ccs2 == 0);
            if (!checksumOk) {
                log.debug("Found invalid TCP checksum 0x" + NumberUtils.hex(ccs2, 4) +
                        ", tcpLength 0x" + NumberUtils.hex(tcpLength, 4) + ", ipDataLength 0x" +
                        NumberUtils.hex(ipHdr.getDataLength(), 4) + ", tcpHdrLen 0x" +
                        NumberUtils.hex(headerLength, 4));
            }
        }
    }
View Full Code Here

    public int getWindowSize() {
        return windowSize;
    }

    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, tcpLength + headerLength);
        phdr.append(offset, skbuf);
        final int csLength = headerLength + tcpLength + 12;
        return IPv4Utils.calcChecksum(phdr, 0, csLength);
    }
View Full Code Here

        // Increment stats
        stat.ipackets.inc();

        // Get the IP header
        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();

        // Read the TCP header
        final TCPHeader hdr = new TCPHeader(skbuf);

        // Set the TCP header in the buffer-field
        skbuf.setTransportLayerHeader(hdr);
        // Remove the TCP header from the head of the buffer
        skbuf.pull(hdr.getLength());
        // Trim the buffer up to the length in the TCP header
        skbuf.trim(hdr.getDataLength());

        if (!hdr.isChecksumOk()) {
            if (DEBUG) {
                if (log.isDebugEnabled()) {
                    log.debug("Receive: badsum: " + hdr);
                }
            }
            stat.badsum.inc();
        } else {
            if (DEBUG) {
                if (log.isDebugEnabled()) {
                    log.debug("Receive: " + hdr);
                }
            }

            // Find the corresponding control block
            final TCPControlBlock cb =
                (TCPControlBlock) controlBlocks.lookup(ipHdr.getSource(), hdr.getSrcPort(),
                    ipHdr.getDestination(), hdr.getDstPort(), true);
            if (cb == null) {
                final boolean ack = hdr.isFlagAcknowledgeSet();
                final boolean rst = hdr.isFlagResetSet();

                stat.noport.inc();
View Full Code Here

    private void processPortUnreachable(IPv4Header ipHdr, TCPHeader hdr) throws SocketException {
        final TCPHeader replyHdr =
            new TCPHeader(hdr.getDstPort(), hdr.getSrcPort(), 0, 0, hdr.getSequenceNr() + 1, 0,
                0);
        replyHdr.setFlags(TCPF_ACK | TCPF_RST);
        final IPv4Header replyIpHdr = new IPv4Header(ipHdr);
        replyIpHdr.swapAddresses();
        send(replyIpHdr, replyHdr, new SocketBuffer());
    }
View Full Code Here

            getError().getPrintWriter().format(fmt_unknown_host, ex.getLocalizedMessage());
            exit(1);
        }
        final PrintWriter out = getOutput().getPrintWriter();
       
        final IPv4Header netHeader =
                new IPv4Header(0, this.ttl, IPv4Constants.IPPROTO_ICMP, this.dst, 8);
        netHeader.setDontFragment(this.dontFragment);

        final IPv4NetworkLayer netLayer =
                (IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_IP);
        final ICMPProtocol icmpProtocol =
                (ICMPProtocol) netLayer.getProtocol(ICMPProtocol.IPPROTO_ICMP);
View Full Code Here

    }

    public void packetReceived(SocketBuffer skbuf) {
        long received = System.currentTimeMillis();

        IPv4Header hdr1 = (IPv4Header) skbuf.getNetworkLayerHeader();
        ICMPEchoHeader hdr2 = (ICMPEchoHeader) skbuf.getTransportLayerHeader();

        int seq = hdr2.getSeqNumber();
        Request r = removeRequest(seq);
        if (r == null || r.Obsolete()) {
View Full Code Here

        // Update statistics
        stat.ipackets.inc();

        // Get IP header
        final IPv4Header hdr = new IPv4Header(skbuf);
        if (!hdr.isChecksumOk()) {
            stat.badsum.inc();
            return;
        }
        // Set the header object in the buffer-field
        skbuf.setNetworkLayerHeader(hdr);

        // Remove header from skbuf-data
        skbuf.pull(hdr.getLength());
        // Trim the end of the message, to we have a valid length
        skbuf.trim(hdr.getDataLength());

        // Now test if the size of the buffer equals the datalength in the
        // header, if now ignore the packet
        if (skbuf.getSize() < hdr.getDataLength()) {
            stat.badlen.inc();
            return;
        }

        // 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();
        }
        if (!shouldProcess) {
            // log.debug("IPPacket not for me, ignoring (dst=" + dstAddr + ")");
            return;
        }

        // Is it a fragment?
        if (hdr.isFragment()) {
            // Yes it is a fragment
            stat.fragments.inc();
            deliverFragment(hdr, skbuf);
        } else {
            // It is a complete packet, find the protocol handler
View Full Code Here

            if (flist.isAlive()) {
                flist.add(skbuf);
                if (flist.isComplete()) {
                    // The fragmentlist is now complete, deliver it
                    final SocketBuffer pbuf = flist.getPacket();
                    final IPv4Header phdr = (IPv4Header) pbuf.getNetworkLayerHeader();
                    stat.reassembled.inc();
                    deliver(phdr, pbuf);
                }
            } else {
                // Timeout of fragmentlist, destroy it
View Full Code Here

        if (checksum == 0) {
            log.debug("No checksum set");
            this.checksumOk = true;
        } else {
            // Create the pseudo header for checksum calculation
            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(skbuf);
            final int ccs2 = IPv4Utils.calcChecksum(phdr, 0, udpLength + 12);
            this.checksumOk = (ccs2 == 0);
            if (!checksumOk) {
View Full Code Here

TOP

Related Classes of org.jnode.net.ipv4.layer.IPv4NetworkLayer

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.