public static final int OK = 0; public static native int PcapActivate(Pcap pcap) throws PcapCloseException; public static native void PcapBreakLoop(Pcap pcap) throws PcapCloseException; public static native int PcapCanSetRfMon(Pcap pcap) throws PcapCloseException, NativeException; public static native int PcapCheckActivated(Pcap pcap); public static native void PcapClose(Pcap pcap) throws PcapCloseException; public static native int PcapCompile(Pcap pcap, BpfProgram fp, String str, int optimize, int netmask) throws PcapCloseException; public static native int PcapCompileNoPcap(int snaplenArg, int linktypeArg, BpfProgram program, String buf, int optimize, int mask)
		throws BpfProgramCloseException; public static native Pcap PcapCreate(String source, StringBuilder errbuf); public static native int PcapDataLink(Pcap pcap) throws PcapCloseException; public static native int PcapDataLinkNameToVal(String name); public static native String PcapDataLinkValToDescription(int dtl); public static native String PcapDataLinkValToName(int dtl); public static native <T> int PcapDispatch(Pcap pcap, int cnt, PcapHandler<T> callback, T user) throws PcapCloseException; @Incubating
public static native <T> int PcapDispatch0(Pcap pcap, int cnt, RawPcapHandler<T> callback, T user) throws PcapCloseException; public static native void PcapDump(PcapDumper pcapDumper, PcapPktHdr h, ByteBuffer sp) throws PcapDumperCloseException; public static native void PcapDumpClose(PcapDumper pcapDumper) throws PcapDumperCloseException; public static native long PcapDumpFTell(PcapDumper pcapDumper) throws PcapDumperCloseException; public static native int PcapDumpFlush(PcapDumper pcapDumper) throws PcapDumperCloseException; public static native PcapDumper PcapDumpOpen(Pcap pcap, String fname) throws PcapCloseException; public static native int PcapFindAllDevs(List<PcapIf> alldevsp, StringBuilder errbuf); public static native void PcapFreeCode(BpfProgram bpfProgram) throws BpfProgramCloseException; public static native String PcapGetErr(Pcap pcap) throws PcapCloseException; public static native int PcapGetNonBlock(Pcap pcap, StringBuilder errbuf) throws PcapCloseException; public static native int PcapGetTStampPrecision(Pcap pcap) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapIsSwapped(Pcap pcap) throws PcapCloseException; public static native String PcapLibVersion(); public static native int PcapListDataLinks(Pcap pcap, List<Integer> dtlBuffer) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapListTStampTypes(Pcap pcap, List<Integer> tstampTypesp) throws PcapCloseException, PlatformNotSupportedException; public static native <T> int PcapLoop(Pcap pcap, int cnt, PcapHandler<T> callback, T user) throws PcapCloseException; @Incubating
public static native <T> int PcapLoop0(Pcap pcap, int cnt, RawPcapHandler<T> callback, T user) throws PcapCloseException; public static native int PcapMajorVersion(Pcap pcap) throws PcapCloseException; public static native int PcapMinorVersion(Pcap pcap) throws PcapCloseException; public static native ByteBuffer PcapNext(Pcap pcap, PcapPktHdr h) throws PcapCloseException; public static native int PcapNextEx(Pcap pcap, PcapPktHdr pktHeader, ByteBuffer pktData) throws PcapCloseException; public static native int PcapOfflineFilter(BpfProgram fp, PcapPktHdr h, ByteBuffer pkt); public static native Pcap PcapOpenDead(int linktype, int snaplen); public static native Pcap PcapOpenDeadWithTStampPrecision(int linktype, int snaplen, int precision) throws PlatformNotSupportedException; public static native Pcap PcapOpenLive(String source, int snaplen, int promisc, int toMs, StringBuilder errbuf); public static native Pcap PcapOpenOffline(String fname, StringBuilder errbuf); public static native Pcap PcapOpenOfflineWithTStampPrecision(String fname, int tstampPrecision, StringBuilder errbuf)
		throws PlatformNotSupportedException; public static native void PcapPError(Pcap pcap, String prefix) throws PcapCloseException; public static native int PcapSetDataLink(Pcap pcap, int dtl) throws PcapCloseException, NativeException; public static native int PcapSetDirection(Pcap pcap, PcapDirection direction) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapSetFilter(Pcap pcap, BpfProgram fp) throws PcapCloseException; public static native int PcapSetImmediateMode(Pcap pcap, int immediateMode) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapSetNonBlock(Pcap pcap, int nonblock, StringBuilder errbuf) throws PcapCloseException; public static native int PcapSetPromisc(Pcap pcap, int promisc) throws PcapCloseException; public static native int PcapSetRfMon(Pcap pcap, int rfmon) throws PcapCloseException; public static native int PcapSetSnaplen(Pcap pcap, int snaplen) throws PcapCloseException; public static native int PcapSetTStampPrecision(Pcap pcap, int tstampPrecision) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapSetTStampType(Pcap pcap, int type) throws PcapCloseException, PlatformNotSupportedException; public static native int PcapSetTimeout(Pcap pcap, int timeout) throws PcapCloseException; public static native int PcapSnapshot(Pcap pcap) throws PcapCloseException; public static native int PcapStats(Pcap pcap, PcapStat pcapStat) throws PcapCloseException; public static native String PcapStatusToStr(int errnum) throws PlatformNotSupportedException; public static native String PcapStrError(int error); public static native int PcapTStampTypeNameToVal(String name) throws PlatformNotSupportedException; public static native String PcapTStampTypeValToDescription(int tstampType) throws PlatformNotSupportedException; public static native String PcapTStampTypeValToName(int tstampType) throws PlatformNotSupportedException; public class DeviceNotFoundException extends RuntimeException {

	private static final long serialVersionUID = -7426666725353676994L;

	public DeviceNotFoundException() {
		this("");
	}

	public DeviceNotFoundException(final String message) {
		this(message, new RuntimeException(message));
	}

	public DeviceNotFoundException(final Throwable cause) {
		this(cause.getMessage(), cause);
	}

	public DeviceNotFoundException(final String message, final Throwable cause) {
		super(message, cause);
	}

} public class NativeException extends RuntimeException {

	private static final long serialVersionUID = -3993889826336916332L;

	public NativeException() {
		this("");
	}

	public NativeException(final String message) {
		this(message, new RuntimeException(message));
	}

	public NativeException(final Throwable cause) {
		this(cause.getMessage(), cause);
	}

	public NativeException(final String message, final Throwable cause) {
		super(message, cause);
	}

} public class PlatformNotSupportedException extends RuntimeException {

    private static final long serialVersionUID = -5714154798477963289L;

    public PlatformNotSupportedException() {
        this("");
    }

    public PlatformNotSupportedException(final String message) {
        this(message, new RuntimeException(message));
    }

    public PlatformNotSupportedException(final Throwable cause) {
        this(cause.getMessage(), cause);
    }

    public PlatformNotSupportedException(final String message, final Throwable cause) {
        super(message, cause);
    }

}
import static com.ardikars.jxnet.Jxnet.OK;
import static com.ardikars.jxnet.Jxnet.PcapActivate;
import static com.ardikars.jxnet.Jxnet.PcapBreakLoop;
import static com.ardikars.jxnet.Jxnet.PcapCanSetRfMon;
import static com.ardikars.jxnet.Jxnet.PcapCheckActivated;
import static com.ardikars.jxnet.Jxnet.PcapClose;
import static com.ardikars.jxnet.Jxnet.PcapCompile;
import static com.ardikars.jxnet.Jxnet.PcapCompileNoPcap;
import static com.ardikars.jxnet.Jxnet.PcapCreate;
import static com.ardikars.jxnet.Jxnet.PcapDataLink;
import static com.ardikars.jxnet.Jxnet.PcapDataLinkNameToVal;
import static com.ardikars.jxnet.Jxnet.PcapDataLinkValToDescription;
import static com.ardikars.jxnet.Jxnet.PcapDataLinkValToName;
import static com.ardikars.jxnet.Jxnet.PcapDispatch;
import static com.ardikars.jxnet.Jxnet.PcapDispatch0;
import static com.ardikars.jxnet.Jxnet.PcapDump;
import static com.ardikars.jxnet.Jxnet.PcapDumpClose;
import static com.ardikars.jxnet.Jxnet.PcapDumpFTell;
import static com.ardikars.jxnet.Jxnet.PcapDumpFlush;
import static com.ardikars.jxnet.Jxnet.PcapDumpOpen;
import static com.ardikars.jxnet.Jxnet.PcapFindAllDevs;
import static com.ardikars.jxnet.Jxnet.PcapFreeCode;
import static com.ardikars.jxnet.Jxnet.PcapGetErr;
import static com.ardikars.jxnet.Jxnet.PcapGetNonBlock;
import static com.ardikars.jxnet.Jxnet.PcapGetTStampPrecision;
import static com.ardikars.jxnet.Jxnet.PcapIsSwapped;
import static com.ardikars.jxnet.Jxnet.PcapLibVersion;
import static com.ardikars.jxnet.Jxnet.PcapListDataLinks;
import static com.ardikars.jxnet.Jxnet.PcapListTStampTypes;
import static com.ardikars.jxnet.Jxnet.PcapLoop;
import static com.ardikars.jxnet.Jxnet.PcapLoop0;
import static com.ardikars.jxnet.Jxnet.PcapMajorVersion;
import static com.ardikars.jxnet.Jxnet.PcapMinorVersion;
import static com.ardikars.jxnet.Jxnet.PcapNext;
import static com.ardikars.jxnet.Jxnet.PcapNextEx;
import static com.ardikars.jxnet.Jxnet.PcapOfflineFilter;
import static com.ardikars.jxnet.Jxnet.PcapOpenDead;
import static com.ardikars.jxnet.Jxnet.PcapOpenDeadWithTStampPrecision;
import static com.ardikars.jxnet.Jxnet.PcapOpenLive;
import static com.ardikars.jxnet.Jxnet.PcapOpenOffline;
import static com.ardikars.jxnet.Jxnet.PcapOpenOfflineWithTStampPrecision;
import static com.ardikars.jxnet.Jxnet.PcapPError;
import static com.ardikars.jxnet.Jxnet.PcapSetDataLink;
import static com.ardikars.jxnet.Jxnet.PcapSetDirection;
import static com.ardikars.jxnet.Jxnet.PcapSetFilter;
import static com.ardikars.jxnet.Jxnet.PcapSetImmediateMode;
import static com.ardikars.jxnet.Jxnet.PcapSetNonBlock;
import static com.ardikars.jxnet.Jxnet.PcapSetPromisc;
import static com.ardikars.jxnet.Jxnet.PcapSetRfMon;
import static com.ardikars.jxnet.Jxnet.PcapSetSnaplen;
import static com.ardikars.jxnet.Jxnet.PcapSetTStampPrecision;
import static com.ardikars.jxnet.Jxnet.PcapSetTStampType;
import static com.ardikars.jxnet.Jxnet.PcapSetTimeout;
import static com.ardikars.jxnet.Jxnet.PcapSnapshot;
import static com.ardikars.jxnet.Jxnet.PcapStats;
import static com.ardikars.jxnet.Jxnet.PcapStatusToStr;
import static com.ardikars.jxnet.Jxnet.PcapStrError;
import static com.ardikars.jxnet.Jxnet.PcapTStampTypeNameToVal;
import static com.ardikars.jxnet.Jxnet.PcapTStampTypeValToDescription;
import static com.ardikars.jxnet.Jxnet.PcapTStampTypeValToName;
import com.ardikars.common.net.Inet4Address;
import com.ardikars.common.net.MacAddress;
import com.ardikars.common.util.Platforms;
import com.ardikars.jxnet.exception.DeviceNotFoundException;
import com.ardikars.jxnet.exception.NativeException;
import com.ardikars.jxnet.exception.PlatformNotSupportedException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.MethodSorters;
                PcapClose(pcap);
                return;
            }
        } catch (NativeException e) {
            logger.warning(e.getMessage());
        }
        logger.info("Data Link Type (After): " + PcapDataLink(pcap));
        PcapClose(pcap);
    }

    @Test
    public void Test14_PcapBreakLoopAndPcapLoop() {
        cntPkt = 0;
        if ((resultCode = PcapLoop(pcap, maxPkt, new PcapHandler<String>() {
            @Override
            public void nextPacket(String user, PcapPktHdr h, ByteBuffer bytes) {
            if (cntPkt == (maxPkt / 2)) {
                logger.info("Break loop.");
                PcapBreakLoop(pcap);
            }
            logger.info("Argument    : " + user);
            logger.info("PacketHeader: " + h);
            logger.info("PacketBuffer: " + bytes);
            cntPkt++;
            }
        }, "This Is User Argument")) != OK) {
            logger.warning("PcapBreakLoopAndPcapLoop:PcapLoop(): " + PcapStrError(resultCode));
            return;
        }
    }

    @Test
    public void Test15_PcapLookupDev() {
        /*String device = PcapLookupDev(errbuf);
        if (device == null) {
            logger.warning("PcapLookupDev:PcapLookupDev(): " + errbuf.toString());
            return;
        }
        logger.info("Lookup device: " + device);*/
    }

    @Test
    public void Test16_PcapGetErr() {
        logger.info("Pcap Error: " + PcapGetErr(pcap));
    }

    @Test
    public void Test17_PcapLibVersionPcapMajorVersionAndPcapMinorVersion() {
        PcapPError(pcap, "Pcap Library Version : (" + PcapLibVersion() + ")");
        PcapPError(pcap, "Pcap Major Version   : (" + PcapMajorVersion(pcap) + ")");
        PcapPError(pcap, "Pcap Minor Version   : (" + PcapMinorVersion(pcap) + ")");
    }

    @Test
    public void Test18_PcapIsSwapped() {
        logger.info("Pcap is swapped: " + PcapIsSwapped(pcap));
    }

    @Test
    public void Test19_PcapSnapshot() {
        logger.info("Snapshot: " + PcapSnapshot(pcap));
    }

    @Test
    public void Test20_PcapDataLinkValToNamePcapDataLinkValToDescriptionAndPcapDataLinkNameToVal() {
        String dataLinkName = PcapDataLinkValToName(DataLinkType.EN10MB.getValue());
        logger.info("Data Link Name: " + dataLinkName);
        logger.info("Data Link Description: " + PcapDataLinkValToDescription(DataLinkType.EN10MB.getValue()));
        logger.info("Data Link Value: " + PcapDataLinkNameToVal(dataLinkName));
    }

    @Test
    public void Test21_PcapSetNonBlockPcapGetNonBlock() {
        int blocking = PcapGetNonBlock(pcap, errbuf);
        logger.info("Blocking (Before) : " + blocking);
        logger.info("Error Buffer      : " + errbuf.toString());
        if ((resultCode = PcapSetNonBlock(pcap, (blocking == 0) ? 1 : 0, errbuf)) != OK) {
            logger.warning("PcapSetNonBlockPcapGetNonBlock:PcapSetNonBlock(): " + errbuf.toString());
            return;
        }
        logger.info("Blocking (After)  : " + PcapGetNonBlock(pcap, errbuf));
        logger.info("Error Buffer      : " + errbuf.toString());
        if ((resultCode = PcapSetNonBlock(pcap, (blocking == 0) ? 0 : 1, errbuf)) != OK) {
            logger.warning("PcapSetNonBlockPcapGetNonBlock:PcapSetNonBlock(): " + errbuf.toString());
            return;
        }
        logger.info("Blocking          : " + PcapGetNonBlock(pcap, errbuf));
        logger.info("Error Buffer      : " + errbuf.toString());
    }

    @Test
    public void Test22_PcapCompileNoPcapSetFilterAndPcapLoop() {
        if ((resultCode = PcapCompileNoPcap(snaplen, DataLinkType.EN10MB.getValue(),
                bpfProgram, filter, optimize, maskp.toInt())) != OK) {
            logger.warning("PcapCompileNoPcapSetFilterAndPcapLoop:PcapCompileNoPcap(): " + errbuf.toString());
            return;
        }
        if ((resultCode = PcapSetFilter(pcap, bpfProgram)) != OK) {
            logger.warning("PcapCompileNoPcapSetFilterAndPcapLoop:PcapSetFilter(): " + PcapStrError(resultCode));
            return;
        }
        if ((resultCode = PcapLoop(pcap, maxPkt, callback, "This Is User Argument")) != OK) {
            logger.warning("PcapCompileNoPcapSetFilterAndPcapLoop:PcapLoop(): " + PcapStrError(resultCode));
            return;
        }
    }

    @Test
    public void Test23_PcapPError() {
        PcapPError(pcap, "Message: ");
    }

    @Test
    public void Test24_PcapSetBufferSize() throws Exception {
        // throw new Exception("Not implemented yet.");
    }

    @Test
    public void Test25_PcapCanSetRfMonAndPcapSetRfMon() {
        if (PcapCanSetRfMon(pcap) == 1) {
            if ((resultCode = PcapSetRfMon(pcap, 1)) != OK) {