Module org.jnetpcap
Package org.jnetpcap

Class PcapIf

java.lang.Object
org.jnetpcap.PcapIf

public class PcapIf extends Object
A Java representation of the native pcap_if_t structure which contains information about a network interface. This class provides access to interface properties such as name, addresses, flags, and hardware information.

Structure Members

The native pcap_if_t structure contains the following members:
  • next - Points to the next interface in the list, or NULL if this is the last interface
  • name - A string containing the name of the interface (e.g., "eth0", "en0")
  • description - A human-readable string describing the interface, may be NULL
  • addresses - A pointer to the first element in a linked list of addresses for the interface
  • flags - Interface flags indicating various interface properties and states

Interface Flags

The flags field can include the following values:
  • PCAP_IF_LOOPBACK - Set if the interface is a loopback interface
  • PCAP_IF_UP - Set if the interface is up (active)
  • PCAP_IF_RUNNING - Set if the interface is running
  • PCAP_IF_WIRELESS - Set if the interface is wireless (includes IrDA, IEEE 802.15.4, IEEE 802.11)

Connection Status

The flags field also includes connection status information through PCAP_IF_CONNECTION_STATUS:
  • PCAP_IF_CONNECTION_STATUS_UNKNOWN - Connection status is unknown
  • PCAP_IF_CONNECTION_STATUS_CONNECTED - Interface is connected
  • PCAP_IF_CONNECTION_STATUS_DISCONNECTED - Interface is disconnected
  • PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE - Connection status doesn't apply (e.g., loopback)

Network Addresses

The interface may have multiple network addresses, accessible through the addresses() method. Each address is represented by a PcapIf.PcapAddr object which may contain:
  • Network address (IPv4, IPv6, or other)
  • Netmask (if applicable)
  • Broadcast address (if the interface supports broadcasts)
  • Destination address (for point-to-point interfaces)

Address Types

The addresses can be of different types, determined by the sa_family field:
  • AF_INET - IPv4 addresses (struct sockaddr_in)
  • AF_INET6 - IPv6 addresses (struct sockaddr_in6)
  • Other address types may be present depending on the platform

Usage Example


 PcapIf iface = ...;
 
 // Get interface name
 String name = iface.name();
 
 // Check if interface is up and running
 Set<PcapIfFlag> flags = iface.flagsAsEnumSet();
 boolean isUp = flags.contains(PcapIfFlag.UP);
 
 // Get IPv4 address if available
 Optional<PcapAddr<InetSockAddr>> ipv4Addr = iface.findAddressOfType(InetSockAddr.class);
 
Since:
libpcap 0.7
See Also: