API Examples

A list of examples that demonstrate the various ways jNetPcap SDK is used.

jNetPcap follows very similar programming paradigm as the native libpcap library. In most cases you will need to follow similar steps in getting ready to use the jNetPcap functionality. First, you will need to acquire a list of available network interfaces for working with the live network (see Pcap.findAllDevs()). Second, you will need to use one of the static open calls found in the Pcap class (see Pcap.openXXXX()). Third, after the open call succeeds, do something through the return Pcap class instance such as read packets, write packets or acquire some information about the network interface (see Pcap.sendPacket(), Pcap.loop(), Pcap.dispatch().)

The most common way of receiving packets is to use Pcap.dispatch() to which you supply a handler, a call back function, that will receive all the incoming packets. The call back function then does the programs logic. In more complex and advanced programs the handler puts the incoming packets on a queue shared with another thread, that awaits for the queue to have some packets. It then retrieves those packets and does something with them.

Here are several examples and code samples that present various features and usage of jNetPcap SDK.