### Install libpcap on Mac
Source: https://www.pcap4j.org/post/install_native_library
Use Homebrew to install the libpcap library.
```bash
brew install libpcap
```
--------------------------------
### Install libpcap on Ubuntu
Source: https://www.pcap4j.org/post/install_native_library
Use the apt package manager to install the libpcap development headers.
```bash
apt-get install libpcap-dev
```
--------------------------------
### Install WinPcap on Windows
Source: https://www.pcap4j.org/post/install_native_library
Use the Chocolatey package manager to install WinPcap.
```bash
choco install winpcap
```
--------------------------------
### Install libpcap on CentOS
Source: https://www.pcap4j.org/post/install_native_library
Use the yum package manager to install the libpcap development headers.
```bash
yum install libpcap-devel
```
--------------------------------
### Extract IPv4 Source Address from Packet
Source: https://www.pcap4j.org/post/get_information_from_the_packet
Use the Packet API to get the IPv4 packet and then extract the source IP address from its header. Ensure the packet contains an IPv4 layer.
```java
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
Inet4Address srcAddr = ipV4Packet.getHeader().getSrcAddr();
System.out.println(srcAddr);
```
--------------------------------
### Configure Pcap4J Dependencies
Source: https://www.pcap4j.org/post/add_pcap4j_to_your_project
Add the core and static packet factory libraries to your project build configuration.
```gradle
compile 'org.pcap4j:pcap4j-core:1.+'
compile 'org.pcap4j:pcap4j-packetfactory-static:1.+'
```
```xml
org.pcap4j
pcap4j-core
[1.0, 2.0)
org.pcap4j
pcap4j-packetfactory-static
[1.0, 2.0)
```
--------------------------------
### Open Pcap Handle for Packet Capture
Source: https://www.pcap4j.org
Opens a live pcap handle from a network interface with specified snapshot length, promiscuous mode, and timeout. Administrator/root privileges may be needed.
```java
int snapLen = 65536;
PromiscuousMode mode = PromiscuousMode.PROMISCUOUS;
int timeout = 10;
PcapHandle handle = nif.openLive(snapLen, mode, timeout);
```
--------------------------------
### Add Pcap4J Dependencies to Gradle
Source: https://www.pcap4j.org
Adds the Pcap4J core and packet factory static dependencies to a Gradle project.
```gradle
compile 'org.pcap4j:pcap4j-core:1.+'
compile 'org.pcap4j:pcap4j-packetfactory-static:1.+'
```
--------------------------------
### Add Pcap4J Dependencies to Maven
Source: https://www.pcap4j.org
Adds the Pcap4J core and packet factory static dependencies to a Maven project.
```xml
org.pcap4j
pcap4j-core
[1.0, 2.0)
org.pcap4j
pcap4j-packetfactory-static
[1.0, 2.0)
```
--------------------------------
### Find Network Interface by IP Address
Source: https://www.pcap4j.org/post/find_a_nif
Use this snippet to find a network interface associated with a specific IP address. Administrator/root privileges may be required.
```java
InetAddress addr = InetAddress.getByName("192.168.10.100");
PcapNetworkInterface nif = Pcaps.getDevByAddress(addr);
```
--------------------------------
### Capture and Close Pcap Handle
Source: https://www.pcap4j.org
Captures the next available packet using the pcap handle and then closes the handle. Ensure the handle is closed after use to release resources.
```java
Packet packet = handle.getNextPacketEx();
handle.close();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.