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


Java EtherType类代码示例

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


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

示例1: _getPacketBuilder4IPv4

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
private EthernetPacket.Builder _getPacketBuilder4IPv4(InetAddress remoteAddress, MacAddress localMacAddress, InetAddress
        localIpAdress) {
    ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
    arpBuilder
            .hardwareType(ArpHardwareType.ETHERNET)
            .protocolType(EtherType.IPV4)
            .hardwareAddrLength((byte) MacAddress.SIZE_IN_BYTES)
            .protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
            .srcHardwareAddr(localMacAddress)
            .srcProtocolAddr(localIpAdress)
            .dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
            .operation(ArpOperation.REQUEST)
            .dstProtocolAddr(remoteAddress);


    EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
    etherBuilder.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
            .srcAddr(localMacAddress)
            .type(EtherType.ARP)
            .payloadBuilder(arpBuilder)
            .paddingAtBuild(true);

    return etherBuilder;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:25,代码来源:MacAddressHelper.java

示例2: buildPacket

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
/**
 *
 * @param builder
 */
public void buildPacket(AbstractPacket.AbstractBuilder builder) {

    if (!this.type.equals(EtherType.getInstance((short) 0x0000))) {
        // do nothing if type not 0x0000
    } else if (builder == null) {
        this.type = EtherType.getInstance((short) 0xFFFF);
    } else {
        this.type = EtherType.IPV4;
    }
    db = new Dot1qVlanTagPacket.Builder();
    db.priority(priority)
            .cfi(cfi)
            .vid(vid)
            .type(type)
            .payloadBuilder(builder);
    this.packet = db.build();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:22,代码来源:TrexVlanPacket.java

示例3: tag

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
public static Packet tag(Packet packet, int vid) {
  EthernetPacket ep = packet.get(EthernetPacket.class);
  if (ep == null) {
    return packet;
  }

  Dot1qVlanTagPacket.Builder vb = new Dot1qVlanTagPacket.Builder();
  vb.vid((short)vid)
    .type(ep.getHeader().getType())
    .payloadBuilder(new SimpleBuilder(ep.getPayload()));

  Packet.Builder pb = packet.getBuilder();
  pb.get(EthernetPacket.Builder.class)
    .type(EtherType.DOT1Q_VLAN_TAGGED_FRAMES)
    .payloadBuilder(vb);

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

示例4: buildArpPkt

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
private static EthernetPacket buildArpPkt() {
    ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
    MacAddress srcMac = MacAddress.getByName("00:50:56:94:21:df");
    try {
        String strSrcIpAddress = "192.168.9.27";
        String strDstIpAddress = "192.168.9.28";
        arpBuilder
                .hardwareType(ArpHardwareType.ETHERNET)
                .protocolType(EtherType.IPV4)
                .hardwareAddrLength((byte) MacAddress.SIZE_IN_BYTES)
                .protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
                .operation(ArpOperation.REQUEST)
                .srcHardwareAddr(srcMac)
                .srcProtocolAddr(InetAddress.getByName(strSrcIpAddress))
                .dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
                .dstProtocolAddr(InetAddress.getByName(strDstIpAddress));
    } catch (UnknownHostException e) {
        throw new IllegalArgumentException(e);
    }

    EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
    etherBuilder.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
            .srcAddr(srcMac)
            .type(EtherType.ARP)
            .payloadBuilder(arpBuilder)
            .paddingAtBuild(true);

    return etherBuilder.build();
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:30,代码来源:TRexClientTest.java

示例5: processEthernetPacket

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
public static void processEthernetPacket(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
    if (packet == null) {
        return; // skip empty packets
    }
    try {
        log.trace("Converting to ethernet packet");
        EthernetPacket ethernetPacket = EthernetPacket.newPacket(packet.getRawData(), 0, packet.length());
        EthernetPacket.EthernetHeader ethernetHeader = ethernetPacket.getHeader();
        MacAddress sourceMac = ethernetHeader.getSrcAddr();
        log.trace("Source MAC: " + sourceMac);
        packetInfo.put(PacketInfo.SOURCE_MAC, sourceMac.toString());
        MacAddress destMac = ethernetHeader.getDstAddr();
        log.trace("Destination MAC: " + destMac);
        packetInfo.put(PacketInfo.DESTINATION_MAC, destMac.toString());
        EtherType etherType = ethernetHeader.getType();
        log.trace("EtherType: " + etherType.toString());
        packetInfo.put(PacketInfo.ETHERTYPE, etherType.toString());
        Packet payload = ethernetPacket.getPayload();
        if (etherType == EtherType.IPV4) {
            IpPacketProcessor.processIpv4Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if (etherType == EtherType.IPV6) {
            IpPacketProcessor.processIpv6Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if ((mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) && (etherType == EtherType.ARP)) {
            pcapFileSummary.nonIpPacketCount++;
            ArpPacketProcessor.processArpPacket(payload, pcapFileSummary);
        } else {
            pcapFileSummary.nonIpPacketCount++;
            log.trace("Skipping packet with EtherType: " + etherType);
        }
    } catch (IllegalRawDataException e) {
        log.error("Exception occurred while processing a packet. Exception was: " + e);
    }
}
 
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:34,代码来源:PcapFileProcessor.java

示例6: TrexEthernetPacket

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
/**
 *
 */
public TrexEthernetPacket() {

    this.srcAddr = MacAddress.getByName("00:00:00:00:00:00");
    this.dstAddr = MacAddress.getByName("00:00:00:00:00:00");
    this.type = EtherType.IPV4;
    this.addPad = false;
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:11,代码来源:TrexEthernetPacket.java

示例7: buildPacket

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
/**
 *
 * @param builder
 */
public void buildPacket(AbstractPacket.AbstractBuilder builder) {

    if (builder == null) {

        this.type = EtherType.getInstance((short) 0xFFFF);
    }

    ethernetBuilder = new EthernetPacket.Builder();
    ethernetBuilder.dstAddr(dstAddr)
            .srcAddr(srcAddr)
            .type(type)
            .payloadBuilder(builder);

    byte[] pad;
    if (builder == null || addPad) {

        if (payload != null) {
            String payloadString = payload.getPayloadType().getPadPayloadString(payload.getPayloadPattern(), 100000);
            pad = new BigInteger(payloadString, 16).toByteArray();
        } else {
            pad = new byte[0];
        }

        ethernetBuilder.paddingAtBuild(false).pad(pad);
        this.packet = ethernetBuilder.build();
        fixPacketLength();
    } else {
        ethernetBuilder.paddingAtBuild(true);
        this.packet = ethernetBuilder.build();
    }
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:36,代码来源:TrexEthernetPacket.java

示例8: TrexVlanPacket

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
/**
 *
 */
public TrexVlanPacket() {
    this.priority = (byte) 0;
    this.cfi = false;
    this.vid = (short) 0;
    this.type = EtherType.getInstance((short) 0x0000);
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:10,代码来源:TrexVlanPacket.java

示例9: addVlanToPacket

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

示例10: pack

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
public static EthernetPacket pack(
  final Packet payload, MacAddress src, MacAddress dst
) {
  EtherType type;
  if (payload instanceof IpV4Packet) {
    type = EtherType.IPV4;
  }
  else if (payload instanceof IpV6Packet) {
    type = EtherType.IPV6;
  }
  else if (payload instanceof ArpPacket) {
    type = EtherType.ARP;
  }
  else if (payload instanceof Dot1qVlanTagPacket) {
    type = EtherType.DOT1Q_VLAN_TAGGED_FRAMES;
  }
  else {
    throw new AssertionError(payload.getClass().getName());
  }

  EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
  return etherBuilder.dstAddr(dst)
                     .srcAddr(src)
                     .type(type)
                     .payloadBuilder(
                        new AbstractBuilder() {
                          @Override
                          public Packet build() {
                            return payload;
                          }
                        }
                      )
                     .paddingAtBuild(true)
                     .build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:36,代码来源:EthernetHelper.java

示例11: reply

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
public static void reply(Packet packet, Node node, NetworkInterface nif) {
  ArpPacket arpPacket = packet.get(ArpPacket.class);
  if (arpPacket == null) {
    throw new IllegalArgumentException(packet.toString());
  }

  InetAddress srcIpAddr
    = arpPacket.getHeader().getSrcProtocolAddr();
  MacAddress srcMacAddr
    = arpPacket.getHeader().getSrcHardwareAddr();
  InetAddress dstIpAddr
    = arpPacket.getHeader().getDstProtocolAddr();

  ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
  arpBuilder.hardwareType(ArpHardwareType.ETHERNET)
            .protocolType(EtherType.IPV4)
            .hardwareAddrLength((byte)MacAddress.SIZE_IN_BYTES)
            .protocolAddrLength((byte)ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
            .operation(ArpOperation.REPLY)
            .srcHardwareAddr(nif.getMacAddress())
            .srcProtocolAddr(dstIpAddr)
            .dstHardwareAddr(srcMacAddr)
            .dstProtocolAddr(srcIpAddr);
  try {
    node.sendL3Packet(arpBuilder.build(), nif);
  } catch (SendPacketException e) {
    // TODO 自動生成された catch ブロック
    e.printStackTrace();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:31,代码来源:ArpHelper.java

示例12: sendRequest

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
public void sendRequest(
  InetAddress targetIpAddr,
  Node node,
  NetworkInterface nif
) {
  InetAddress srcIpAddr = null;
  for (NifIpAddress addr: nif.getIpAddresses()) {
    if (addr.getIpAddr() instanceof Inet4Address) {
      srcIpAddr = addr.getIpAddr();
    }
  }
  if (srcIpAddr == null) {
    throw new IllegalArgumentException("No IPv4 address is found in " + nif);
  }
  MacAddress srcMacAddr = nif.getMacAddress();

  ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
  arpBuilder.hardwareType(ArpHardwareType.ETHERNET)
            .protocolType(EtherType.IPV4)
            .hardwareAddrLength((byte)MacAddress.SIZE_IN_BYTES)
            .protocolAddrLength((byte)ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
            .operation(ArpOperation.REQUEST)
            .srcHardwareAddr(srcMacAddr)
            .srcProtocolAddr(srcIpAddr)
            .dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
            .dstProtocolAddr(targetIpAddr);
  try {
    node.sendL3Packet(arpBuilder.build(), nif);
  } catch (SendPacketException e) {
    // TODO 自動生成された catch ブロック
    e.printStackTrace();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:34,代码来源:ArpHelper.java

示例13: buildIpV4

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的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:breakEval13,项目名称:NSS,代码行数:44,代码来源:PacketUtils.java

示例14: _getPacketBuilder4IPv6

import org.pcap4j.packet.namednumber.EtherType; //导入依赖的package包/类
private EthernetPacket.Builder _getPacketBuilder4IPv6(Inet6Address remoteAddress, MacAddress localMacAddress, Inet6Address
        localIpAdress) throws UnknownHostException {
    MacAddress broadcastMacAddress = _getBroadcastMacAddress4IPv6(remoteAddress);
    Inet6Address broadcasetIPAddress = _getBroadcastIPAddress4IPv6(remoteAddress);

    IcmpV6NeighborSolicitationPacket.Builder v6Builder = new IcmpV6NeighborSolicitationPacket.Builder();
    v6Builder.targetAddress(remoteAddress);
    v6Builder.reserved(0);
    IpV6NeighborDiscoverySourceLinkLayerAddressOption.Builder optionBuilder = new IpV6NeighborDiscoverySourceLinkLayerAddressOption
            .Builder();
    IpV6NeighborDiscoverySourceLinkLayerAddressOption option = optionBuilder
            .linkLayerAddress(localMacAddress.getAddress())
            .correctLengthAtBuild(true)
            .build();
    List<IcmpV6CommonPacket.IpV6NeighborDiscoveryOption> options = new ArrayList<>();
    options.add(option);
    v6Builder.options(options);


    IcmpV6CommonPacket.Builder icmpV6b = new IcmpV6CommonPacket.Builder();
    icmpV6b.type(IcmpV6Type.NEIGHBOR_SOLICITATION)
            .code(IcmpV6Code.NO_CODE)
            .srcAddr(localIpAdress)
            .dstAddr(broadcasetIPAddress)
            .payloadBuilder(v6Builder)
            .correctChecksumAtBuild(true);


    IpV6Packet.Builder ipv6b = new IpV6Packet.Builder();
    ipv6b.version(IpVersion.IPV6)
            .trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0x12))
            .flowLabel(IpV6SimpleFlowLabel.newInstance(0))
            .nextHeader(IpNumber.ICMPV6)
            .hopLimit((byte) 255)
            .srcAddr(localIpAdress)
            .dstAddr(broadcasetIPAddress) // "fe80:0:0:0:250:56ff:febc:2688" -> "FF02::1:FFbc:2688"
            .correctLengthAtBuild(true)
            .payloadBuilder(icmpV6b);

    EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
    etherBuilder.dstAddr(broadcastMacAddress)
            .srcAddr(localMacAddress)
            .type(EtherType.IPV6)
            .payloadBuilder(ipv6b)
            .paddingAtBuild(true);

    return etherBuilder;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:49,代码来源:MacAddressHelper.java

示例15: buildIpV4

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


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