pcap_open_live Subroutine

Purpose

Opens a network device for packet capture.

Library

pcap Library (libpcap.a)

Syntax

#include <pcap.h>

pcap_t *pcap_open_live( const char * device, const int snaplen,
const int promisc, const int to_ms, char * ebuf);

Description

The pcap_open_live subroutine opens the specified network device for packet capture. The term "live" is to indicate that a network device is being opened, as opposed to a file that contains packet capture data. This subroutine must be called before any packet capturing can occur. All other routines dealing with packet capture require the packet capture descriptor that is created and initialized with this routine. See the pcap_open_offline (pcap_open_offline Subroutine) subroutine for more details on opening a previously saved file that contains packet capture data.

Parameters

Item Description
device Specifies a string that contains the name of the network device to open for packet capture, for example, en0.
ebuf Returns error text and is only set when the pcap_open_live subroutine fails.
promisc Specifies that the device is to be put into promiscuous mode. A value of 1 (True) turns promiscuous mode on. If this parameter is 0 (False), the device will remain unchanged. In this case, if it has already been set to promiscuous mode (for some other reason), it will remain in this mode.
snaplen Specifies the maximum number of bytes to capture per packet.
to_ms Specifies the read timeout in milliseconds.

Return Values

Upon successful completion, the pcap_open_live subroutine will return a pointer to the packet capture descriptor that was created. If the pcap_open_live subroutine is unsuccessful, Null is returned, and text indicating the specific error is written into the ebuf buffer.