Ejemplo n.º 1
0
        static Packet createDataPacket(
            MacAddress srcAddress_mac,
            MacAddress dstAddrress_mac,
            Inet4Address srcAddress, short srcPort,
            Inet4Address dstAddress, short dstPort,
            int sequence, int ack, byte[] data, short ident)
        {
            Packet p = null;

            TcpPacket.Builder builder_tcp = new TcpPacket.Builder();
            builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(data));
            builder_tcp.correctChecksumAtBuild(true);
            builder_tcp.correctLengthAtBuild(true);
            builder_tcp.paddingAtBuild(true);
            builder_tcp.ack(true);
            builder_tcp.acknowledgmentNumber(ack);
            //builder_tcp.checksum(tcpHeader.getChecksum());
            //builder_tcp.dataOffset((byte)8);
            builder_tcp.dstAddr(dstAddress);
            builder_tcp.dstPort(new TcpPort(dstPort, ""));
            builder_tcp.fin(false);
            //builder_tcp.options(tcpHeader.getOptions());
            //builder_tcp.padding(tcpHeader.getPadding());
            builder_tcp.psh(false);
            builder_tcp.reserved((byte)0);
            builder_tcp.rst(false);
            builder_tcp.sequenceNumber(sequence);
            builder_tcp.srcAddr(srcAddress);
            builder_tcp.srcPort(new TcpPort(srcPort, ""));
            builder_tcp.syn(false);
            builder_tcp.urg(false);
            //builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
            builder_tcp.window(window);

            IpV4Packet.Builder builder_ipv4 = new IpV4Packet.Builder();
            builder_ipv4.correctChecksumAtBuild(true);
            builder_ipv4.correctLengthAtBuild(true);
            builder_ipv4.dontFragmentFlag(true);
            builder_ipv4.paddingAtBuild(true);
            builder_ipv4.dstAddr(dstAddress);
            builder_ipv4.fragmentOffset((short)0);
            //builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
            //short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
            //identification=ident;
            builder_ipv4.identification(ident);
            builder_ipv4.ihl((byte)5);
            builder_ipv4.moreFragmentFlag(false);
            //builder_ipv4.options(ipV4Header.getOptions());
            //builder_ipv4.padding(ipV4Header.getPadding());

            builder_ipv4.protocol(IpNumber.TCP);
            //builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
            builder_ipv4.srcAddr(srcAddress);
            builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte)0));
            //builder_ipv4.totalLength( 52);
            builder_ipv4.ttl(ttl);
            builder_ipv4.version(IpVersion.IPV4);
            builder_ipv4.payloadBuilder(builder_tcp);

            p = buildIpV4(srcAddress_mac, dstAddrress_mac, builder_ipv4);

            return(p);
        }