class PcapNetworkInterface {

  public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis)
      throws PcapNativeException {
    if (mode == null) {
      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();
      to.tv_sec = new NativeLong(0);
      to.tv_usec = new NativeLong(0);

      int rc =
          PcapLibrary.INSTANCE.strioctl(
              NativeMappings.getFdFromPcapT(handle),
              NativeMappings.SBIOCSTIME,
              to.size(),
              to.getPointer());

      if (rc < 0) {
        throw new PcapNativeException(
            "SBIOCSTIME: "
                + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0));
      }
    }

    return new PcapHandle(handle, TimestampPrecision.MICRO);
  }

  private  PcapNetworkInterface(pcap_if pif, boolean local);

}