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


Java ByteArrays类代码示例

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


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

示例1: getRawData

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
@Override
public byte[] getRawData() {
  byte[] rawData = new byte[length()];
  rawData[0] = kind.value();
  rawData[1] = length;

  int offset = 2;
  for (Sack sack: sacks) {
    System.arraycopy(
      ByteArrays.toByteArray(sack.leftEdge), 0,
      rawData, offset, INT_SIZE_IN_BYTES
    );
    System.arraycopy(
      ByteArrays.toByteArray(sack.rightEdge), 0,
      rawData, offset + INT_SIZE_IN_BYTES, INT_SIZE_IN_BYTES
    );
    offset += INT_SIZE_IN_BYTES * 2;
  }

  return rawData;
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:22,代码来源:CustomTcpSackOption.java

示例2: getLinkLayerAddress

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
/**
 *   IPv6 Neighbor Discovery Source Link Layer Address header
 *
 *   0                   1                   2                   3
 *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  |     Type      |    Length     |    Link-Layer Address ...
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 */
private String getLinkLayerAddress(IpV6Packet pkt) {
    final int TYPE_OFFSET = 0;
    final int TYPE_SIZE = BYTE_SIZE_IN_BYTES;
    final int LENGTH_OFFSET = TYPE_OFFSET + TYPE_SIZE;
    final int LENGTH_SIZE = BYTE_SIZE_IN_BYTES;
    final int LINK_LAYER_ADDRESS_OFFSET = LENGTH_OFFSET + LENGTH_SIZE;
    final int LINK_LAYER_ADDRESS_LENGTH = 6; // MAC address
    
    IcmpV6NeighborSolicitationPacket nsPkt = pkt.get(IcmpV6NeighborSolicitationPacket.class);

    IpV6NeighborDiscoveryOption linkLayerAddressOption = nsPkt.getHeader().getOptions().get(0);

    byte[] linkLayerAddress = ByteArrays.getSubArray(linkLayerAddressOption.getRawData(), LINK_LAYER_ADDRESS_OFFSET, LINK_LAYER_ADDRESS_LENGTH);

    return ByteArrays.toHexString(linkLayerAddress, ":");
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:26,代码来源:IPv6NeighborDiscoveryService.java

示例3: _getPacketBuilder4IPv4

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

示例4: getRawData

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
@Override
public byte[] getRawData() {
    byte[] rawData = new byte[length()];
    rawData[0] = kind.value();
    rawData[1] = length;

    int offset = 2;
    for (Sack sack : sacks) {
        System.arraycopy(
                ByteArrays.toByteArray(sack.leftEdge), 0,
                rawData, offset, INT_SIZE_IN_BYTES
        );
        System.arraycopy(
                ByteArrays.toByteArray(sack.rightEdge), 0,
                rawData, offset + INT_SIZE_IN_BYTES, INT_SIZE_IN_BYTES
        );
        offset += INT_SIZE_IN_BYTES * 2;
    }

    return rawData;
}
 
开发者ID:Bpazy,项目名称:finalspeed,代码行数:22,代码来源:CustomTcpSackOption.java

示例5: generateVirtualMacAddress

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
public MacAddress generateVirtualMacAddress() {
  int serialNumber;
  synchronized (counterLock) {
    if (counter > MAX_SERIAL_NUMBER) {
      throw new AssertionError("too many MAC addresses.");
    }
    serialNumber = counter;
    counter++;
  }

  // TODO IPv6
  byte[] rawAddr = new byte[6];
  System.arraycopy(
    VIRTUAL_MACADDRESS_OUI.valueAsByteArray(), 0, rawAddr, 0, 3
  );
  System.arraycopy(
    ByteArrays.toByteArray(serialNumber), 1, rawAddr, 3, 3
  );

  MacAddress macAddr = MacAddress.getByAddress(rawAddr);
  return macAddr;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:23,代码来源:MacAddressManager.java

示例6: isSameNetwork

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
public static boolean isSameNetwork(
  Inet6Address addr1, Inet6Address addr2, int prefixLength
) {
  if (prefixLength < 0 || prefixLength > 128) {
    throw new IllegalArgumentException(
            "Invalid prefix length: " + prefixLength
          );
  }

  if (prefixLength <= 64) {
    long addr1Bitmap = ByteArrays.getLong(addr1.getAddress(), 0);
    long addr2Bitmap = ByteArrays.getLong(addr2.getAddress(), 0);
    return isSamePrefix(addr1Bitmap, addr2Bitmap, prefixLength);
  }
  else {
    long addr1Bitmap1h = ByteArrays.getLong(addr1.getAddress(), 0);
    long addr2Bitmap1h = ByteArrays.getLong(addr2.getAddress(), 0);
    if (addr1Bitmap1h != addr2Bitmap1h) {
      return false;
    }
    long addr1Bitmap2h = ByteArrays.getLong(addr1.getAddress(), 16);
    long addr2Bitmap2h = ByteArrays.getLong(addr2.getAddress(), 16);
    return isSamePrefix(addr1Bitmap2h, addr2Bitmap2h, prefixLength - 64);
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:26,代码来源:IpV6Helper.java

示例7: buildArpPkt

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
private static EthernetPacket buildArpPkt(String srcMac, String srcIp, String dstIp) {
    ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
    MacAddress srcMacAddress = MacAddress.getByName(srcMac);
    try {
        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(srcMacAddress)
                .srcProtocolAddr(InetAddress.getByName(srcIp))
                .dstHardwareAddr(MacAddress.getByName("00:00:00:00:00:00"))
                .dstProtocolAddr(InetAddress.getByName(dstIp));
    } catch (UnknownHostException e) {
        throw new IllegalArgumentException(e);
    }

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

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

示例8: buildArpPkt

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

示例9: extract

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
public static short extract(byte[] payload, byte[] header) {
    if(payload.length < DEAUTH_CONTENT_LENGTH+1) {
        return -1;
    }

    byte[] reasonBytes = {
            payload[DEAUTH_CONTENT_LENGTH],
            payload[DEAUTH_CONTENT_LENGTH +1]
    };

    return ByteArrays.getShort(reasonBytes, 0, ByteOrder.LITTLE_ENDIAN);
}
 
开发者ID:lennartkoopmann,项目名称:nzyme,代码行数:13,代码来源:Dot11LeavingReason.java

示例10: compare

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
public int compare(RealNetworkInterfaceConfigurationDto o1, RealNetworkInterfaceConfigurationDto o2) {
  byte[] o1Addr = ByteArrays.parseByteArray(o1.getMacAddress(), ":");
  byte[] o2Addr = ByteArrays.parseByteArray(o2.getMacAddress(), ":");

  for (int i = 0; i < o1Addr.length; i++) {
    if (o1Addr[i] != o2Addr[i]) {
      return (0xFF & o2Addr[i]) - (0xFF & o1Addr[i]);
    }
  }

  return 0;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:13,代码来源:RealNetworkInterfaceConfigurationGridAction.java

示例11: isSameNetwork

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
public static boolean isSameNetwork(
  Inet4Address addr1, Inet4Address addr2, Inet4Address subnetmask
) {
  int addr1Bitmap = ByteArrays.getInt(addr1.getAddress(), 0);
  int addr2Bitmap = ByteArrays.getInt(addr2.getAddress(), 0);
  int subnetmaskBitmap = ByteArrays.getInt(subnetmask.getAddress(), 0);
  return (addr1Bitmap & subnetmaskBitmap) == (addr2Bitmap & subnetmaskBitmap);
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:9,代码来源:IpV4Helper.java

示例12: getNextHop

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
private Inet4Address getNextHop(Inet4Address dst) {
  Collection<IpV4RoutingTableEntry> values = null;

  synchronized (entries) {
    IpV4RoutingTableEntry justMatchedEntry = entries.get(dst);
    if (justMatchedEntry != null) {
      return justMatchedEntry.gw;
    }

    values = entries.values();
  }

  int dstBitmap = ByteArrays.getInt(dst.getAddress(), 0);
  IpV4RoutingTableEntry mostMatchedEntry = null;
  for (IpV4RoutingTableEntry entry: values) {
    if (
      entry.dstBitmap
        == (dstBitmap & entry.maskBitmap)
    ) {
      if (mostMatchedEntry == null) {
        mostMatchedEntry = entry;
      }
      else if (entry.prefixLength > mostMatchedEntry.prefixLength) {
        mostMatchedEntry = entry;
      }
      else if (
           entry.prefixLength == mostMatchedEntry.prefixLength
        && entry.metric < mostMatchedEntry.metric
      ) {
        mostMatchedEntry = entry;
      }
    }
  }

  if (mostMatchedEntry == null) {
    return null;
  }

  return mostMatchedEntry.gw;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:41,代码来源:IpV4Helper.java

示例13: IpV4RoutingTableEntry

import org.pcap4j.util.ByteArrays; //导入依赖的package包/类
private IpV4RoutingTableEntry(
  Inet4Address dst,
  Inet4Address mask,
  Inet4Address gw,
  int metric
) {
  this.dst = dst;
  this.dstBitmap = ByteArrays.getInt(dst.getAddress(), 0);
  this.mask = mask;
  this.maskBitmap = ByteArrays.getInt(mask.getAddress(), 0);
  this.prefixLength = getPrefixLengthFrom(mask);
  this.gw = gw;
  this.metric = metric;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:15,代码来源:IpV4Helper.java

示例14: reply

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

示例15: sendRequest

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


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