• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java UnknownPacket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



UnknownPacket类属于org.pcap4j.packet包,在下文中一共展示了UnknownPacket类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleDnsResponse

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
/**
 * Handles a responsePayload from an upstream DNS server
 *
 * @param requestPacket   The original request packet
 * @param responsePayload The payload of the response
 */
void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) {
    UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload();
    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket)
            .srcPort(udpOutPacket.getHeader().getDstPort())
            .dstPort(udpOutPacket.getHeader().getSrcPort())
            .srcAddr(requestPacket.getHeader().getDstAddr())
            .dstAddr(requestPacket.getHeader().getSrcAddr())
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(responsePayload)
            );


    IpPacket ipOutPacket;
    if (requestPacket instanceof IpV4Packet) {
        ipOutPacket = new IpV4Packet.Builder((IpV4Packet) requestPacket)
                .srcAddr((Inet4Address) requestPacket.getHeader().getDstAddr())
                .dstAddr((Inet4Address) requestPacket.getHeader().getSrcAddr())
                .correctChecksumAtBuild(true)
                .correctLengthAtBuild(true)
                .payloadBuilder(payLoadBuilder)
                .build();

    } else {
        ipOutPacket = new IpV6Packet.Builder((IpV6Packet) requestPacket)
                .srcAddr((Inet6Address) requestPacket.getHeader().getDstAddr())
                .dstAddr((Inet6Address) requestPacket.getHeader().getSrcAddr())
                .correctLengthAtBuild(true)
                .payloadBuilder(payLoadBuilder)
                .build();
    }

    eventLoop.queueDeviceWrite(ipOutPacket);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:43,代码来源:DnsPacketProxy.java


示例2: testHandleDnsRequestNotUdpPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotUdpPacket() throws Exception {
    TcpPacket.Builder payLoadBuilder = new TcpPacket.Builder()
            .srcPort(TcpPort.HTTP)
            .dstPort(TcpPort.HTTP)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(new byte[0])
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
    assertNull(mockEventLoop.lastOutgoing);
    assertNull(mockEventLoop.lastResponse);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:30,代码来源:DnsPacketProxyTest.java


示例3: testHandleDnsRequestNotDnsPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotDnsPacket() throws Exception {
    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.HTTP)
            .dstPort(UdpPort.HTTP)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(new byte[]{1, 2, 3, 4, 5})
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
    assertNull(mockEventLoop.lastOutgoing);
    assertNull(mockEventLoop.lastResponse);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:30,代码来源:DnsPacketProxyTest.java


示例4: testDnsQuery

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testDnsQuery() throws Exception {
    Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
            0x01,
            3600,
            Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
    ));

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(message.toWire())
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNull(mockEventLoop.lastResponse);
    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:38,代码来源:DnsPacketProxyTest.java


示例5: testNoQueryDnsQuery

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testNoQueryDnsQuery() throws Exception {
    Message message = new Message();

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(message.toWire())
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNull(mockEventLoop.lastResponse);
    assertNull(mockEventLoop.lastOutgoing);
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:34,代码来源:DnsPacketProxyTest.java


示例6: buildPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
/**
 * Build packet
 *
 * @throws java.net.UnknownHostException
 */
public void buildPacket() throws UnknownHostException {

    int calculatedLength = getPacketLength();
    String payloadString = payload.getPayloadType().getPadPayloadString(payload.getPayloadPattern(), calculatedLength * 2);

    udpBuilder = new UdpPacket.Builder();
    UnknownPacket.Builder unknownb = new UnknownPacket.Builder();
    unknownb.rawData(payload.getPayloadPad(payloadString, calculatedLength));
    Inet4Address srcAddr = (Inet4Address) InetAddress.getByAddress(
            new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0}
    );
    Inet4Address dstAddr = (Inet4Address) InetAddress.getByAddress(
            new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0}
    );

    udpBuilder.srcPort(UdpPort.getInstance((short) srcPort.value()))
            .dstPort(UdpPort.getInstance((short) dstPort.value()))
            .srcAddr(srcAddr)
            .dstAddr(dstAddr)
            .length((short) calculatedLength)
            .payloadBuilder(unknownb)
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(false);

    this.packet = udpBuilder.build();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:32,代码来源:TrexUdpPacket.java


示例7: buildIpV4

import org.pcap4j.packet.UnknownPacket; //导入依赖的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


示例8: createDataPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的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


示例9: testHandleDnsRequestEmptyPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testHandleDnsRequestEmptyPacket() throws Exception {
    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(new byte[0])
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(0, mockEventLoop.lastOutgoing.getLength());
    assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());

    assertNull(mockEventLoop.lastResponse);

    // Check the same thing with one upstream DNS server configured.
    tinySetUp();
    dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, 2}));
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNull(mockEventLoop.lastOutgoing);
    assertNull(mockEventLoop.lastResponse);

    // Check the same thing with enough upstream DNS servers configured.
    tinySetUp();
    for (byte i = 2; i < 9; i++)
        dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, i}));
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(0, mockEventLoop.lastOutgoing.getLength());
    assertEquals(Inet4Address.getByAddress(new byte[]{1, 1, 1, 8}), mockEventLoop.lastOutgoing.getAddress());
    assertNull(mockEventLoop.lastResponse);

}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:54,代码来源:DnsPacketProxyTest.java


示例10: testBlockedDnsQuery

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testBlockedDnsQuery() throws Exception {
    Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
            0x01,
            3600,
            Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
    ));

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(message.toWire())
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNotNull(mockEventLoop.lastResponse);
    assertNull(mockEventLoop.lastOutgoing);
    assertTrue(mockEventLoop.lastResponse instanceof IpPacket);
    assertTrue(mockEventLoop.lastResponse.getPayload() instanceof UdpPacket);

    Message responseMsg = new Message(mockEventLoop.lastResponse.getPayload().getPayload().getRawData());
    assertEquals(NOERROR, responseMsg.getHeader().getRcode());
    assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER));
    assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length);
    assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord);
    assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:46,代码来源:DnsPacketProxyTest.java


示例11: testBlockedInet6DnsQuery

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
@Test
public void testBlockedInet6DnsQuery() throws Exception {
    Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
            0x01,
            3600,
            Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
    ));

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr((Inet6Address) Inet6Address.getByName("::0"))
            .dstAddr((Inet6Address) Inet6Address.getByName("::1"))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(message.toWire())
            );

    IpPacket ipOutPacket = new IpV6Packet.Builder()
            .version(IpVersion.IPV6)
            .trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0))
            .flowLabel(IpV6SimpleFlowLabel.newInstance(0))
            .nextHeader(IpNumber.UDP)
            .srcAddr((Inet6Address) Inet6Address.getByName("::0"))
            .dstAddr((Inet6Address) Inet6Address.getByName("::1"))
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNotNull(mockEventLoop.lastResponse);
    assertNull(mockEventLoop.lastOutgoing);
    assertTrue(mockEventLoop.lastResponse instanceof IpPacket);
    assertTrue(mockEventLoop.lastResponse.getPayload() instanceof UdpPacket);

    Message responseMsg = new Message(mockEventLoop.lastResponse.getPayload().getPayload().getRawData());
    assertEquals(NOERROR, responseMsg.getHeader().getRcode());
    assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER));
    assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length);
    assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord);
    assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:46,代码来源:DnsPacketProxyTest.java


示例12: buildPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
/**
 * Build packet
 */
public void buildPacket() {

    int calculatedLength = getPacketLength() - 14;

    String payloadString = payload.getPayloadType().getPadPayloadString(payload.getPayloadPattern(), calculatedLength * 2);

    UnknownPacket.Builder unknownb = null;
    if (calculatedLength != 0) {
        unknownb = new UnknownPacket.Builder();
        unknownb.rawData(payload.getPayloadPad(payloadString, calculatedLength));
    }
    ArrayList<TcpOption> options = new ArrayList<TcpOption>();

    options.add(TcpEndOfOptionList.getInstance());

    tcpBuilder = new TcpPacket.Builder();
    tcpBuilder.dstPort(dstPort)
            .srcPort(srcPort)
            .sequenceNumber(sequenceNumber)
            .acknowledgmentNumber(acknowledgmentNumber)
            .dataOffset(dataOffset)
            .reserved(reserved)
            .urg(urg)
            .ack(ack)
            .psh(psh)
            .rst(rst)
            .syn(syn)
            .fin(fin)
            .window(window)
            .checksum(checksum)
            .urgentPointer(urgentPointer)
            .options(options)
            .padding(new byte[]{(byte) 0xaa})
            .correctChecksumAtBuild(false)
            .correctLengthAtBuild(false)
            .paddingAtBuild(false);

    if (calculatedLength != 0) {
        tcpBuilder.payloadBuilder(unknownb);
    }
    this.packet = tcpBuilder.build();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:46,代码来源:TrexTcpPacket.java


示例13: gotPacket

import org.pcap4j.packet.UnknownPacket; //导入依赖的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: sendSnmpMessage

import org.pcap4j.packet.UnknownPacket; //导入依赖的package包/类
public void sendSnmpMessage(
  InetAddress dstAddr, int dstPort,
  byte[] message
) throws SendPacketException {
  InetAddress srcAddr;
  int srcPort;
  NetworkInterface sender;

  SnmpContext context = agent.getContextfulWorkerPool().unregisterContext();
  if (context != null) {
    // response
    sender = context.getGetter();
    IpV4Packet ipV4Packet = context.getRequestPacket().get(IpV4Packet.class);
    if (ipV4Packet != null) {
      srcAddr = context.getRequestPacket().get(IpV4Packet.class).getHeader()
                  .getDstAddr();
    }
    else {
      srcAddr = context.getRequestPacket().get(IpV6Packet.class).getHeader()
                  .getDstAddr();
    }
    srcPort = context.getRequestPacket().get(UdpPacket.class).getHeader()
                .getDstPort().value() & 0xFFFF;
  }
  else {
    // trap
    if (dstAddr instanceof Inet4Address) {
      sender = getNifByDstIpAddr((Inet4Address)dstAddr);
    }
    else {
      sender = getNifByDstIpAddr((Inet6Address)dstAddr);
    }
    srcAddr = agent.getInetAddress();
    srcPort = TRAP_SRC_PORT;
  }
  UnknownPacket.Builder unknownb = new UnknownPacket.Builder();
  unknownb.rawData(message);

  UdpPacket udpp
    = UdpHelper.pack(
        unknownb.build(),
        UdpPort.getInstance((short)srcPort),
        UdpPort.getInstance((short)dstPort),
        srcAddr,
        dstAddr
      );

  sendL4Packet(udpp, srcAddr, dstAddr, sender);
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:50,代码来源:Node.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PersistenceProperty类代码示例发布时间:2022-05-23
下一篇:
Java TimeToLiveHFileCleaner类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap