Package org.pcap4j.packet

Examples of org.pcap4j.packet.IpV4Packet$IpV4Header


            if (log.isDebugEnabled()) {
                log.debug("receive: me=[" + this + "], hdr=[" + hdr + ']');
            }
        }

        final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
        final boolean ack = hdr.isFlagAcknowledgeSet();
        final boolean rst = hdr.isFlagResetSet();

        if (rst) {
            receiveProcessReset(ipHdr, hdr, skbuf);
View Full Code Here


        // Create the FIN TCP reply
        final TCPHeader replyHdr = createOutgoingTCPHeader(extraFlags | TCPF_ACK, ackNr);
        // ACK takes 0 seq-nrs, so don't increment snd_next

        // Create the IP reply header
        final IPv4Header replyIp = createOutgoingIPv4Header();

        // Send the reply
        outChannel.send(replyIp, replyHdr);
    }
View Full Code Here

        // Create the FIN TCP reply
        final TCPHeader replyHdr =
            createOutgoingTCPHeader(TCPF_FIN | TCPF_ACK, inChannel.getRcvNext());

        // Create the IP reply header
        final IPv4Header replyIp = createOutgoingIPv4Header();

        // Send the reply
        outChannel.send(replyIp, replyHdr);
    }
View Full Code Here

        // Create the RST TCP reply
        final TCPHeader replyHdr = createOutgoingTCPHeader(TCPF_RST, 0);
        // RST takes 0 seg-nrs TODO is this correct????

        // Create the IP reply header
        final IPv4Header replyIp = createOutgoingIPv4Header();

        // Send the reply
        outChannel.send(replyIp, replyHdr);
    }
View Full Code Here

        // Create the SYN TCP
        final TCPHeader hdr = createOutgoingTCPHeader(TCPF_SYN, 0);

        // Create the IP reply header
        final IPv4Header ipHdr = createOutgoingIPv4Header();

        // Send the reply
        outChannel.send(ipHdr, hdr);
    }
View Full Code Here

        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

TOP

Related Classes of org.pcap4j.packet.IpV4Packet$IpV4Header

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.