コード例 #1
0
ファイル: Pcaps.java プロジェクト: Mehrkat/pcap4j
  /**
   * @param snaplen
   * @param dlt
   * @param bpfExpression
   * @param mode
   * @param netmask
   * @return a {@link org.pcap4j.core.BpfProgram BpfProgram} object.
   * @throws PcapNativeException
   */
  public static BpfProgram compileFilter(
      int snaplen,
      DataLinkType dlt,
      String bpfExpression,
      BpfCompileMode mode,
      Inet4Address netmask)
      throws PcapNativeException {
    if (dlt == null || bpfExpression == null || mode == null || netmask == null) {
      StringBuilder sb = new StringBuilder();
      sb.append("dlt: ")
          .append(dlt)
          .append(" bpfExpression: ")
          .append(bpfExpression)
          .append(" mode: ")
          .append(mode)
          .append(" netmask: ")
          .append(netmask);
      throw new NullPointerException(sb.toString());
    }

    bpf_program prog = new bpf_program();
    int rc =
        NativeMappings.pcap_compile_nopcap(
            snaplen,
            dlt.value(),
            prog,
            bpfExpression,
            mode.getValue(),
            ByteArrays.getInt(ByteArrays.toByteArray(netmask), 0));
    if (rc < 0) {
      throw new PcapNativeException("Failed to compile the BPF expression: " + bpfExpression, rc);
    }
    return new BpfProgram(prog, bpfExpression);
  }
 public byte[] getRawData() {
   byte[] rawData = new byte[length()];
   Iterator<TimestampWithAddress> iter = timestampsWithAddresses.iterator();
   for (int i = 0; i < rawData.length; i += INT_SIZE_IN_BYTES * 2) {
     TimestampWithAddress twa = iter.next();
     System.arraycopy(ByteArrays.toByteArray(twa.address), 0, rawData, i, INT_SIZE_IN_BYTES);
     if (twa.timestamp != null) {
       System.arraycopy(
           ByteArrays.toByteArray(twa.timestamp),
           0,
           rawData,
           i + INT_SIZE_IN_BYTES,
           INT_SIZE_IN_BYTES);
     }
   }
   return rawData;
 }
コード例 #3
0
 @Override
 protected List<byte[]> getRawFields() {
   List<byte[]> rawFields = new ArrayList<byte[]>();
   int tmp = 0x1FFFFFFF & reserved;
   if (routerFlag) {
     tmp |= 0x80000000;
   }
   if (solicitedFlag) {
     tmp |= 0x40000000;
   }
   if (overrideFlag) {
     tmp |= 0x20000000;
   }
   rawFields.add(ByteArrays.toByteArray(tmp));
   rawFields.add(ByteArrays.toByteArray(targetAddress));
   for (IpV6NeighborDiscoveryOption o : options) {
     rawFields.add(o.getRawData());
   }
   return rawFields;
 }
コード例 #4
0
ファイル: TcpSackOption.java プロジェクト: pjsg/pcap4j
  @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;
  }
コード例 #5
0
ファイル: RadiotapDataRate.java プロジェクト: kaitoy/pcap4j
 @Override
 public byte[] getRawData() {
   return ByteArrays.toByteArray(rate);
 }
コード例 #6
0
ファイル: IcmpV4RedirectPacket.java プロジェクト: pjsg/pcap4j
 @Override
 protected List<byte[]> getRawFields() {
   List<byte[]> rawFields = new ArrayList<byte[]>();
   rawFields.add(ByteArrays.toByteArray(gatewayInternetAddress));
   return rawFields;
 }