当前位置: 首页>>代码示例>>Java>>正文


Java IpV4Packet.Builder方法代码示例

本文整理汇总了Java中org.pcap4j.packet.IpV4Packet.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java IpV4Packet.Builder方法的具体用法?Java IpV4Packet.Builder怎么用?Java IpV4Packet.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pcap4j.packet.IpV4Packet的用法示例。


在下文中一共展示了IpV4Packet.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildIPV4Packet

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
/**
 * Build IPV4 packet
 *
 * @param packetData
 * @return
 * @throws IOException
 * @throws InterruptedException
 * @throws PcapNativeException
 * @throws NotOpenException
 * @throws java.net.URISyntaxException
 */
public TrexEthernetPacket buildIPV4Packet(PacketData packetData) throws IOException, InterruptedException, PcapNativeException, NotOpenException, URISyntaxException {

    LOG.info("create ethernet packet");
    int packetLength = PacketBuilderHelper.getPacketLength(packetData.getPacketLength().getLengthType(), packetData.getPacketLength().getFrameLength(), packetData.getPacketLength().getMaxLength());
    Payload payload = packetUtil.getPayload(packetData.getPayload());
    TrexEthernetPacket ethernetPacket = packetUtil.prepareEthernetPacket(packetData, packetLength, payload);

    // define VLAN 
    IpV4Packet.Builder ipV4Packet = getIPV4PacketBuilder(PacketBuilderHelper.getIPV4TotalLength(packetData.isTaggedVlan()), packetLength, payload, packetData);
    if (!packetData.isTaggedVlan()) {
        LOG.info("Add IPV4 packet");
        ethernetPacket.buildPacket(ipV4Packet);
    } else {
        packetUtil.addVlanToPacket(ethernetPacket, ipV4Packet);
    }

    return ethernetPacket;
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:30,代码来源:AbstractIPV4Test.java

示例2: createSyncAck

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
static Packet createSyncAck(
		MacAddress srcAddress_mac,
		MacAddress dstAddrress_mac,
		Inet4Address srcAddress,short srcPort,
		Inet4Address dstAddress,short dstPort,
		int ack_sequence,int sequence,short ident){

	TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
	//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
	builder_tcp.correctChecksumAtBuild(true);
	builder_tcp.correctLengthAtBuild(true);
	builder_tcp.paddingAtBuild(true);
	builder_tcp.ack(true);
	builder_tcp.acknowledgmentNumber(ack_sequence);
	//builder_tcp.checksum(tcpHeader.getChecksum());
	//builder_tcp.dataOffset((byte) 8);
	builder_tcp.dstAddr(dstAddress);
	builder_tcp.dstPort(new TcpPort(dstPort,""));
	//builder_tcp.fin(tcpHeader.getFin());


	ArrayList<TcpOption> tcp_options=new ArrayList<TcpOption>();
	
	TcpNoOperationOption nop=TcpNoOperationOption.getInstance();

	TcpMaximumSegmentSizeOption seg_option=new TcpMaximumSegmentSizeOption.Builder().maxSegSize(mtu).correctLengthAtBuild(true).build();
	tcp_options.add(seg_option);
	
	tcp_options.add(nop);
	tcp_options.add(nop);

	TcpSackPermittedOption sack_permit_option=TcpSackPermittedOption.getInstance();
	tcp_options.add(sack_permit_option);
	
	tcp_options.add(nop);

	TcpWindowScaleOption win_option=new TcpWindowScaleOption.Builder().shiftCount(shiftCount).correctLengthAtBuild(true).build();
	tcp_options.add(win_option);

	builder_tcp.options(tcp_options);

	//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(true);
	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.paddingAtBuild(true);
	builder_ipv4.dstAddr(dstAddress);
	builder_ipv4.dontFragmentFlag(true);
	builder_ipv4.fragmentOffset((short)0);
	//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//	short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
	builder_ipv4.identification(ident);
	builder_ipv4.ihl((byte) 5);
	//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
	//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);
	//
	Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
	return p;

}
 
开发者ID:RCD-Y,项目名称:FinalSpeed-X,代码行数:82,代码来源:PacketUtils.java

示例3: buildPacket

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
/**
 *
 * @param builder
 * @param protocol
 */
public void buildPacket(AbstractPacket.AbstractBuilder builder, IpNumber protocol) {

    byte[] pad = new byte[1];
    String payloadPattern = payload.getPayloadPattern();
    String payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, (totalLength - 20) * 2);

    if (packetLength > DEFAULT_PACKET_LENGTH) {
        payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, payloadString.length() + ((packetLength - DEFAULT_PACKET_LENGTH) * 2));
        this.totalLength = (short) ((int) totalLength + (packetLength - DEFAULT_PACKET_LENGTH));
    }
    pad = payload.getPayloadPad(payloadString, totalLength - 20);

    ipV4Builder = new IpV4Packet.Builder();
    ipV4Builder.version(version)
            .ihl(ihl)
            .tos(tos)
            .totalLength(totalLength)
            .identification(identification)
            .reservedFlag(reservedFlag)
            .ttl(ttl)
            .fragmentOffset((short) 0)
            .protocol(protocol)
            .headerChecksum(headerChecksum)
            .srcAddr(srcAddr)
            .dstAddr(dstAddr)
            .protocol(protocol)
            .correctChecksumAtBuild(true)
            //  .correctLengthAtBuild(true)
            .payloadBuilder(builder);

    if (protocol != IpNumber.TCP && protocol != IpNumber.UDP) {
        ipV4Builder.paddingAtBuild(false)
                .padding(pad);
    } else {
        ipV4Builder.paddingAtBuild(true).correctLengthAtBuild(true);
    }

    this.packet1 = ipV4Builder.build();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:45,代码来源:TrexIpV4Packet.java

示例4: addVlanToPacket

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
/**
 * Add VLan to the generated packet
 *
 * @param ethernetPacket
 * @param ipV4Packet
 */
public void addVlanToPacket(TrexEthernetPacket ethernetPacket, IpV4Packet.Builder ipV4Packet) {
    LOG.info("Add VLAN data");
    ethernetPacket.setType(EtherType.DOT1Q_VLAN_TAGGED_FRAMES.value());
    TrexVlanPacket vlanPacket = new TrexVlanPacket();
    if (ipV4Packet == null) {
        ethernetPacket.setAddPad(true);
        vlanPacket.setType((short) 0xFFFF);
    } else {
        vlanPacket.setType(EtherType.IPV4.value());
    }
    vlanPacket.buildPacket(ipV4Packet);
    ethernetPacket.buildPacket(vlanPacket.getBuilder());
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:20,代码来源:PacketUtil.java

示例5: getIPV4PacketBuilder

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
@Override
protected IpV4Packet.Builder getIPV4PacketBuilder(int totalLength, int packetLength, Payload payload, PacketData packetData) throws UnknownHostException {
    LOG.info("Create IPV4 Packet");
    TrexIpV4Packet ipV4Packet = prepareIPV4Packet(totalLength, packetLength, payload, packetData);

    int ipv4PacketLength = PacketBuilderHelper.getIPV4PacketLength(packetData.isTaggedVlan(), packetLength, totalLength);
    ipV4Packet.setPacketLength(ipv4PacketLength);
    int tcpPacketLength = PacketBuilderHelper.getTcpUdpPacketLength(packetData.isTaggedVlan(), packetLength, totalLength);
    // build  packet
    ipV4Packet.buildPacket(getTcpPacket(payload, tcpPacketLength, packetData).getBuilder(), IpNumber.TCP);

    return ipV4Packet.getBuilder();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:14,代码来源:TCPTest.java

示例6: getIPV4PacketBuilder

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
@Override
protected IpV4Packet.Builder getIPV4PacketBuilder(int totalLength, int packetLength, Payload payload, PacketData packetData) throws UnknownHostException {
    LOG.info("Create IPV4 Packet");
    TrexIpV4Packet ipV4Packet = prepareIPV4Packet(totalLength, packetLength, payload, packetData);

    int ipv4PacketLength = PacketBuilderHelper.getIPV4PacketLength(packetData.isTaggedVlan(), packetLength, totalLength);
    ipV4Packet.setPacketLength(ipv4PacketLength);
    int udpPacketLength = PacketBuilderHelper.getTcpUdpPacketLength(packetData.isTaggedVlan(), packetLength, totalLength);
    // build  packet
    ipV4Packet.buildPacket(getUdpPacket(payload, udpPacketLength, packetData).getBuilder(), IpNumber.UDP);

    return ipV4Packet.getBuilder();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:14,代码来源:UDPTest.java

示例7: pack

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
public static IpV4Packet pack(
  final Packet payload, Inet4Address src, Inet4Address dst, int ttl, short id
) {
  IpNumber ipNum;
  if (payload instanceof UdpPacket) {
    ipNum = IpNumber.UDP;
  }
  else if (payload instanceof IcmpV4CommonPacket) {
    ipNum = IpNumber.ICMPV4;
  }
  else if (payload instanceof TcpPacket) {
    ipNum = IpNumber.TCP;
  }
  else {
    throw new AssertionError();
  }

  IpV4Packet.Builder builder = new IpV4Packet.Builder();
  return
    builder.version(IpVersion.IPV4)
           .tos(IpV4Rfc791Tos.newInstance((byte)0))
           .identification(id)
           .ttl((byte)ttl)
           .protocol(ipNum)
           .srcAddr(src)
           .dstAddr(dst)
           .payloadBuilder(new SimpleBuilder(payload))
           .correctChecksumAtBuild(true)
           .correctLengthAtBuild(true)
           .build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:32,代码来源:IpV4Helper.java

示例8: decrementTtl

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
public static IpV4Packet decrementTtl(
  IpV4Packet packet
) throws TimeoutException {
  int ttl = packet.getHeader().getTtlAsInt();
  if (ttl <= 1) {
    throw new TimeoutException();
  }

  ttl--;
  IpV4Packet.Builder b
    = packet.getBuilder().ttl((byte)ttl).correctChecksumAtBuild(true);

  return b.build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:15,代码来源:IpV4Helper.java

示例9: buildIpV4

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
public static Packet buildIpV4(
		MacAddress srcAddress_mac,
		MacAddress dstAddrress_mac,
		IpV4Packet.Builder builder_ipv4){

	org.pcap4j.packet.Packet.Builder builder=null;
	EtherType etherType=null;
	Packet p=null;
	if(ppp){
		etherType=EtherType.PPPOE_SESSION_STAGE;
		
		UnknownPacket.Builder pppBuilder=new UnknownPacket.Builder();
		byte[] ipData=builder_ipv4.build().getRawData();
		
		byte[] lenb=new byte[2];
		ByteShortConvert.toByteArray((short) (ipData.length+2), lenb, 0);
		
		byte[] pppHead=new byte[8];
		System.arraycopy(pppHead_static, 0, pppHead, 0, pppHead.length);
		System.arraycopy(lenb, 0, pppHead, 4, 2);
		
		byte[] newData=new byte[pppHead.length+ipData.length];
		System.arraycopy(pppHead, 0, newData, 0, pppHead.length);
		System.arraycopy(ipData, 0, newData, 8, ipData.length);
		pppBuilder.rawData(newData);
		
		builder=pppBuilder;
	}else {
		etherType=EtherType.IPV4;
		builder=builder_ipv4;
	}
	
	EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
	etherBuilder.dstAddr(dstAddrress_mac)
	.srcAddr(srcAddress_mac)
	.type(etherType)
	.payloadBuilder(builder)
	.paddingAtBuild(true);
	
	p = etherBuilder.build();
	
	return p;
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:44,代码来源:PacketUtils.java

示例10: createDataPacket

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
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;
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:63,代码来源:PacketUtils.java

示例11: createAck

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
static Packet createAck(
		MacAddress srcAddress_mac,
		MacAddress dstAddrress_mac,
		Inet4Address srcAddress,short srcPort,
		Inet4Address dstAddress,short dstPort,
		int ack_sequence,int sequence,short ident){

	TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
	//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
	builder_tcp.correctChecksumAtBuild(true);
	builder_tcp.correctLengthAtBuild(true);
	builder_tcp.paddingAtBuild(true);
	builder_tcp.ack(true);
	builder_tcp.acknowledgmentNumber(ack_sequence);
	//builder_tcp.checksum(tcpHeader.getChecksum());
	//builder_tcp.dataOffset((byte) 8);
	builder_tcp.dstAddr(dstAddress);
	builder_tcp.dstPort(new TcpPort( dstPort,""));
	//builder_tcp.fin(tcpHeader.getFin());

	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.paddingAtBuild(true);
	builder_ipv4.dstAddr(dstAddress);
	builder_ipv4.dontFragmentFlag(true);
	builder_ipv4.fragmentOffset( (short) 0);
	//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
	//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
	builder_ipv4.identification(ident);
	builder_ipv4.ihl((byte) 5);
	//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
	//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);
	//
	
	Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
	//System.out.println("自定义确认 "+" identification "+identification+" ack_sequence "+ack_sequence+" # "+tcpPacket.getHeader());
	return p;

}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:62,代码来源:PacketUtils.java

示例12: createAck

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
static Packet createAck(
		MacAddress srcAddress_mac,
		MacAddress dstAddrress_mac,
		Inet4Address srcAddress,short srcPort,
		Inet4Address dstAddress,short dstPort,
		int ack_sequence,int sequence,short ident){

	TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
	//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
	builder_tcp.correctChecksumAtBuild(true);
	builder_tcp.correctLengthAtBuild(true);
	builder_tcp.paddingAtBuild(true);
	builder_tcp.ack(true);
	builder_tcp.acknowledgmentNumber(ack_sequence);
	//builder_tcp.checksum(tcpHeader.getChecksum());
	//builder_tcp.dataOffset((byte) 8);
	builder_tcp.dstAddr(dstAddress);
	builder_tcp.dstPort(new TcpPort( dstPort,""));
	//builder_tcp.fin(tcpHeader.getFin());

	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.paddingAtBuild(true);
	builder_ipv4.dstAddr(dstAddress);
	builder_ipv4.dontFragmentFlag(true);
	builder_ipv4.fragmentOffset( (short) 0);
	//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
	//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
	builder_ipv4.identification(ident);
	builder_ipv4.ihl((byte) 5);
	//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
	//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);
	//
	
	Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
	return p;

}
 
开发者ID:RCD-Y,项目名称:FinalSpeed-X,代码行数:61,代码来源:PacketUtils.java

示例13: gotPacket

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
@Override
public void gotPacket(Packet rawPacket) {
    try {
        LOG.info("Read raw " + rawPacket);
        IpV4Packet ipPacket = rawPacket.get(IpV4Packet.class);
        UdpPacket udpPacket = rawPacket.get(UdpPacket.class);
        byte[] dhcpData = udpPacket.getPayload().getRawData();
        InetSocketAddress remoteAddress = new InetSocketAddress(ipPacket.getHeader().getSrcAddr(), udpPacket.getHeader().getSrcPort().valueAsInt());
        InetSocketAddress localAddress = new InetSocketAddress(ipPacket.getHeader().getDstAddr(), udpPacket.getHeader().getDstPort().valueAsInt());
        DhcpRequestContext context = new DhcpRequestContext(interfaceAddresses, remoteAddress, localAddress);
        DhcpMessage request = decoder.decode(ByteBuffer.wrap(dhcpData));
        LOG.info("Read DHCP " + request);
        DhcpMessage reply = service.getReplyFor(context, request);
        if (reply == null)
            return;
        byte[] replyData = new byte[1536];
        ByteBuffer buffer = ByteBuffer.wrap(replyData);
        encoder.encode(buffer, reply);
        replyData = Arrays.copyOf(replyData, buffer.position());    // Truncate array to writer position.
        UnknownPacket.Builder dhcpBuilder = new UnknownPacket.Builder()
                .rawData(replyData);
        UdpPacket.Builder udpBuilder = new UdpPacket.Builder()
                .payloadBuilder(dhcpBuilder)
                .srcPort(udpPacket.getHeader().getDstPort())
                .dstPort(udpPacket.getHeader().getSrcPort())
                .correctChecksumAtBuild(true)
                .correctLengthAtBuild(true);
        IpV4Packet.Builder ipBuilder = new IpV4Packet.Builder()
                .payloadBuilder(udpBuilder)
                .srcAddr(null) // TODO
                .dstAddr(null) // TODO
                .protocol(IpNumber.UDP)
                .correctChecksumAtBuild(true)
                .correctLengthAtBuild(true)
                .paddingAtBuild(true);
        EthernetPacket.Builder ethernetBuilder = new EthernetPacket.Builder()
                .payloadBuilder(ipBuilder)
                .type(EtherType.IPV4)
                .paddingAtBuild(true);
        Packet replyPacket = ethernetBuilder.build();
        // handle.sendPacket(replyPacket);
    } catch (Exception e) {
        LOG.error("DHCP failed", e);
    }
}
 
开发者ID:shevek,项目名称:dhcp4j,代码行数:46,代码来源:DhcpPacketListener.java

示例14: getBuilder

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
/**
 *
 * @return
 */
public IpV4Packet.Builder getBuilder() {
    return ipV4Builder;
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:8,代码来源:TrexIpV4Packet.java

示例15: getIPV4PacketBuilder

import org.pcap4j.packet.IpV4Packet; //导入方法依赖的package包/类
/**
 * Create IPV4 packet
 *
 * @param totalLength
 * @param packetLength
 * @param payload
 * @param packetData
 * @return IPV4 packet
 */
protected abstract IpV4Packet.Builder getIPV4PacketBuilder(int totalLength, int packetLength, Payload payload, PacketData packetData) throws UnknownHostException;
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:11,代码来源:AbstractIPV4Test.java


注:本文中的org.pcap4j.packet.IpV4Packet.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。