Examples of PcapErrbuf


Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

    this.handle = handle;
    this.dlt = getDltByNative();
  }

  private PcapHandle(Builder builder) throws PcapNativeException {
    PcapErrbuf errbuf = new PcapErrbuf();
    this.handle
      = NativeMappings.pcap_create(
          builder.deviceName,
          errbuf
        );
    if (handle == null || errbuf.length() != 0) {
      throw new PcapNativeException(errbuf.toString());
    }

    try {
      if (builder.isSnaplenSet) {
        int rc = NativeMappings.pcap_set_snaplen(handle, builder.snaplen);
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

    try {
      if (!open) {
        throw new NotOpenException();
      }

      PcapErrbuf errbuf = new PcapErrbuf();
      int rc = NativeMappings.pcap_setnonblock(handle, mode.getValue(), errbuf);
      if (rc < 0) {
        throw new PcapNativeException(errbuf.toString(), rc);
      }
    } finally {
      handleLock.readLock().unlock();
    }
  }
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

  public BlockingMode getBlockingMode() throws PcapNativeException, NotOpenException {
    if (!open) {
      throw new NotOpenException();
    }

    PcapErrbuf errbuf = new PcapErrbuf();
    int rc;
    if (!handleLock.readLock().tryLock()) {
      throw new NotOpenException();
    }
    try {
      if (!open) {
        throw new NotOpenException();
      }
      rc = NativeMappings.pcap_getnonblock(handle, errbuf);
    } finally {
      handleLock.readLock().unlock();
    }

    if (rc == 0) {
      return BlockingMode.BLOCKING;
    }
    else if (rc > 0) {
      return BlockingMode.NONBLOCKING;
    }
    else {
      throw new PcapNativeException(errbuf.toString(), rc);
    }
  }
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

      StringBuilder sb = new StringBuilder();
      sb.append("mode: ").append(mode);
      throw new NullPointerException(sb.toString());
    }

    PcapErrbuf errbuf = new PcapErrbuf();
    Pointer handle
      = NativeMappings.pcap_open_live(
          name,
          snaplen,
          mode.getValue(),
          timeoutMillis,
          errbuf
        );
    if (handle == null || errbuf.length() != 0) {
      throw new PcapNativeException(errbuf.toString());
    }

    if (timeoutMillis == 0 && Platform.isSolaris()) {
      // disable buffering
      timeval to = new timeval();
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

   * @throws PcapNativeException
   */
  public static
  List<PcapNetworkInterface> findAllDevs() throws PcapNativeException {
    PointerByReference alldevsPP = new PointerByReference();
    PcapErrbuf errbuf = new PcapErrbuf();

    int rc = NativeMappings.pcap_findalldevs(alldevsPP, errbuf);
    if (rc != 0) {
      StringBuilder sb = new StringBuilder(50);
      sb.append("Return code: ")
        .append(rc)
        .append(", Message: ")
        .append(errbuf);
      throw new PcapNativeException(sb.toString(), rc);
    }
    if (errbuf.length() != 0) {
      logger.warn("{}", errbuf);
    }

    Pointer alldevsp = alldevsPP.getValue();
    if (alldevsp == null) {
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

   *
   * @return a name of a network interface.
   * @throws PcapNativeException
   */
  public static String lookupDev() throws PcapNativeException {
    PcapErrbuf errbuf = new PcapErrbuf();
    Pointer result = NativeMappings.pcap_lookupdev(errbuf);

    if (result == null || errbuf.length() != 0) {
      throw new PcapNativeException(errbuf.toString());
    }

    return result.getWideString(0);
  }
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

      StringBuilder sb = new StringBuilder();
      sb.append("devName: ").append(devName);
      throw new NullPointerException(sb.toString());
    }

    PcapErrbuf errbuf = new PcapErrbuf();
    IntByReference netp = new IntByReference();
    IntByReference maskp = new IntByReference();
    int rc = NativeMappings.pcap_lookupnet(devName, netp, maskp, errbuf);

    if (rc < 0) {
      throw new PcapNativeException(errbuf.toString(), rc);
    }

    int net = netp.getValue();
    int mask = maskp.getValue();
View Full Code Here

Examples of org.pcap4j.core.NativeMappings.PcapErrbuf

      StringBuilder sb = new StringBuilder();
      sb.append("filePath: ").append(filePath);
      throw new NullPointerException(sb.toString());
    }

    PcapErrbuf errbuf = new PcapErrbuf();
    Pointer handle
      = NativeMappings.pcap_open_offline(filePath, errbuf);

    if (handle == null || errbuf.length() != 0) {
      throw new PcapNativeException(errbuf.toString());
    }

    return new PcapHandle(handle);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.