---
name: "pcap_open_offline"
section: "3pcap"
platform: "macos"
package: "libpcap"
version: "146"
release: "macOS 26.5"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/pcap_open_offline/3pcap"
---

# pcap\_open\_offline(3pcap)

open a saved capture file for reading

## NAME

pcap\_open\_offline, pcap\_open\_offline\_with\_tstamp\_precision, pcap\_fopen\_offline, pcap\_fopen\_offline\_with\_tstamp\_precision - open a saved capture file for reading

## SYNOPSIS

```
#include <pcap/pcap.h>
```

```
char errbuf[PCAP_ERRBUF_SIZE];
```

**pcap\_t \*pcap\_open\_offline(const char \*fname, char \*errbuf);** **pcap\_t \*pcap\_open\_offline\_with\_tstamp\_precision(const char \*fname,**\
     **u\_int precision, char \*errbuf);** **pcap\_t \*pcap\_fopen\_offline(FILE \*fp, char \*errbuf);** **pcap\_t \*pcap\_fopen\_offline\_with\_tstamp\_precision(FILE \*fp,**\
     **u\_int precision, char \*errbuf);**

## DESCRIPTION

**pcap\_open\_offline**() and **pcap\_open\_offline\_with\_tstamp\_precision**() are called to open a \`\`savefile'' for reading.

*fname* specifies the name of the file to open. The file can have the pcap file format as described in [**pcap-savefile**(5)](/pcap-savefile/5.md), which is the file format used by, among other programs, [**tcpdump**(1)](/tcpdump/1.md) and [**tcpslice**(1)](/tcpslice/1.md), or can have the pcapng file format, although not all pcapng files can be read. The name "-" is a synonym for **stdin**.

**pcap\_open\_offline\_with\_tstamp\_precision**() takes an additional *precision* argument specifying the time stamp precision desired; if **PCAP\_TSTAMP\_PRECISION\_MICRO** is specified, packet time stamps will be supplied in seconds and microseconds, and if **PCAP\_TSTAMP\_PRECISION\_NANO** is specified, packet time stamps will be supplied in seconds and nanoseconds.  If the time stamps in the file do not have the same precision as the requested precision, they will be scaled up or down as necessary before being supplied.

Alternatively, you may call **pcap\_fopen\_offline**() or **pcap\_fopen\_offline\_with\_tstamp\_precision**() to read dumped data from an existing open stream *fp*. **pcap\_fopen\_offline\_with\_tstamp\_precision**() takes an additional *precision* argument as described above. Note that on Windows, that stream should be opened in binary mode.

## RETURN VALUE

**pcap\_open\_offline**(), **pcap\_open\_offline\_with\_tstamp\_precision**(), **pcap\_fopen\_offline**(), and **pcap\_fopen\_offline\_with\_tstamp\_precision**() return a *pcap\_t \** on success and **NULL** on failure. If **NULL** is returned, *errbuf* is filled in with an appropriate error message. *errbuf* is assumed to be able to hold at least **PCAP\_ERRBUF\_SIZE** chars.

## BACKWARD COMPATIBILITY

**pcap\_open\_offline\_with\_tstamp\_precision**() and **pcap\_fopen\_offline\_with\_tstamp\_precision**() became available in libpcap release 1.5.1.  In previous releases, time stamps from a savefile are always given in seconds and microseconds.

## SEE ALSO

**pcap**(3PCAP), [**pcap-savefile**(5)](/pcap-savefile/5.md)
