blob: 1408deb23bd9dc1b7b04aeae4ec0598cfa62461c [file] [log] [blame]
JP Abgrall511eca32014-02-12 13:46:45 -08001.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3pcap.in,v 1.1 2008-10-21 07:33:01 guy Exp $
2.\"
3.\" Copyright (c) 1994, 1996, 1997
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that: (1) source code distributions
8.\" retain the above copyright notice and this paragraph in its entirety, (2)
9.\" distributions including binary code include the above copyright notice and
10.\" this paragraph in its entirety in the documentation or other materials
11.\" provided with the distribution, and (3) all advertising materials mentioning
12.\" features or use of this software display the following acknowledgement:
13.\" ``This product includes software developed by the University of California,
14.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15.\" the University nor the names of its contributors may be used to endorse
16.\" or promote products derived from this software without specific prior
17.\" written permission.
18.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21.\"
22.TH PCAP 3PCAP "1 July 2013"
23.SH NAME
24pcap \- Packet Capture library
25.SH SYNOPSIS
26.nf
27.ft B
28#include <pcap/pcap.h>
29.LP
30.ft B
31.ft
32.fi
33.SH DESCRIPTION
34The Packet Capture library
35provides a high level interface to packet capture systems. All packets
36on the network, even those destined for other hosts, are accessible
37through this mechanism.
38It also supports saving captured packets to a ``savefile'', and reading
39packets from a ``savefile''.
40.SS Opening a capture handle for reading
41To open a handle for a live capture, given the name of the network or
42other interface on which the capture should be done, call
43.BR pcap_create (),
44set the appropriate options on the handle, and then activate it with
45.BR pcap_activate ().
46.PP
47To obtain a list of devices that can be opened for a live capture, call
48.BR pcap_findalldevs ();
49to free the list returned by
50.BR pcap_findalldevs (),
51call
52.BR pcap_freealldevs ().
53.BR pcap_lookupdev ()
54will return the first device on that list that is not a ``loopback``
55network interface.
56.PP
57To open a handle for a ``savefile'' from which to read packets, given the
58pathname of the ``savefile'', call
59.BR pcap_open_offline ();
60to set up a handle for a ``savefile'', given a
61.B "FILE\ *"
62referring to a file already opened for reading, call
63.BR pcap_fopen_offline ().
64.PP
65In order to get a ``fake''
66.B pcap_t
67for use in routines that require a
68.B pcap_t
69as an argument, such as routines to open a ``savefile'' for writing and
70to compile a filter expression, call
71.BR pcap_open_dead ().
72.PP
73.BR pcap_create (),
74.BR pcap_open_offline (),
75.BR pcap_fopen_offline (),
76and
77.BR pcap_open_dead ()
78return a pointer to a
79.BR pcap_t ,
80which is the handle used for reading packets from the capture stream or
81the ``savefile'', and for finding out information about the capture
82stream or ``savefile''.
83To close a handle, use
84.BR pcap_close ().
85.PP
86The options that can be set on a capture handle include
87.IP "snapshot length"
88If, when capturing, you capture the entire contents of the packet, that
89requires more CPU time to copy the packet to your application, more disk
90and possibly network bandwidth to write the packet data to a file, and
91more disk space to save the packet. If you don't need the entire
92contents of the packet - for example, if you are only interested in the
93TCP headers of packets - you can set the "snapshot length" for the
94capture to an appropriate value. If the snapshot length is set to
95.IR snaplen ,
96and
97.I snaplen
98is less
99than the size of a packet that is captured, only the first
100.I snaplen
101bytes of that packet will be captured and provided as packet data.
102.IP
103A snapshot length of 65535 should be sufficient, on most if not all
104networks, to capture all the data available from the packet.
105.IP
106The snapshot length is set with
107.BR pcap_set_snaplen ().
108.IP "promiscuous mode"
109On broadcast LANs such as Ethernet, if the network isn't switched, or if
110the adapter is connected to a "mirror port" on a switch to which all
111packets passing through the switch are sent, a network adapter receives
112all packets on the LAN, including unicast or multicast packets not sent
113to a network address that the network adapter isn't configured to
114recognize.
115.IP
116Normally, the adapter will discard those packets; however, many network
117adapters support "promiscuous mode", which is a mode in which all
118packets, even if they are not sent to an address that the adapter
119recognizes, are provided to the host. This is useful for passively
120capturing traffic between two or more other hosts for analysis.
121.IP
122Note that even if an application does not set promiscuous mode, the
123adapter could well be in promiscuous mode for some other reason.
124.IP
125For now, this doesn't work on the "any" device; if an argument of "any"
126or NULL is supplied, the setting of promiscuous mode is ignored.
127.IP
128Promiscuous mode is set with
129.BR pcap_set_promisc ().
130.IP "monitor mode"
131On IEEE 802.11 wireless LANs, even if an adapter is in promiscuous mode,
132it will supply to the host only frames for the network with which it's
133associated. It might also supply only data frames, not management or
134control frames, and might not provide the 802.11 header or radio
135information pseudo-header for those frames.
136.IP
137In "monitor mode", sometimes also called "rfmon mode" (for "Radio
138Frequency MONitor"), the adapter will supply all frames that it
139receives, with 802.11 headers, and might supply a pseudo-header with
140radio information about the frame as well.
141.IP
142Note that in monitor mode the adapter might disassociate from the
143network with which it's associated, so that you will not be able to use
144any wireless networks with that adapter. This could prevent accessing
145files on a network server, or resolving host names or network addresses,
146if you are capturing in monitor mode and are not connected to another
147network with another adapter.
148.IP
149Monitor mode is set with
150.BR pcap_set_rfmon (),
151and
152.BR pcap_can_set_rfmon ()
153can be used to determine whether an adapter can be put into monitor
154mode.
155.IP "read timeout"
156If, when capturing, packets are delivered as soon as they arrive, the
157application capturing the packets will be woken up for each packet as it
158arrives, and might have to make one or more calls to the operating
159system to fetch each packet.
160.IP
161If, instead, packets are not delivered as soon as they arrive, but are
162delivered after a short delay (called a "read timeout"), more than one
163packet can be accumulated before the packets are delivered, so that a
164single wakeup would be done for multiple packets, and each set of calls
165made to the operating system would supply multiple packets, rather than
166a single packet. This reduces the per-packet CPU overhead if packets
167are arriving at a high rate, increasing the number of packets per second
168that can be captured.
169.IP
170The read timeout is required so that an application won't wait for the
171operating system's capture buffer to fill up before packets are
172delivered; if packets are arriving slowly, that wait could take an
173arbitrarily long period of time.
174.IP
175Not all platforms support a read timeout; on platforms that
176don't, the read timeout is ignored. A zero value for the timeout,
177on platforms that support a read timeout, has platform-dependent
178behavior that could cause a read to wait for an unlimited amount
179of time until the capture buffer fills up or could cause a read timeout
180of 1 millisecond to be used. We recommend that a value of zero not be
181used.
182.IP
183.BR NOTE :
184the read timeout cannot be used to cause calls that read
185packets to return within a limited period of time, because, on some
186platforms, the read timeout isn't supported, and, on other platforms,
187the timer doesn't start until at least one packet arrives. This means
188that the read timeout should
189.B NOT
190be used, for example, in an interactive application to allow the packet
191capture loop to ``poll'' for user input periodically, as there's no
192guarantee that a call reading packets will return after the timeout
193expires even if no packets have arrived.
194.IP
195The read timeout is set with
196.BR pcap_set_timeout ().
197.IP "buffer size"
198Packets that arrive for a capture are stored in a buffer, so that they
199do not have to be read by the application as soon as they arrive. On
200some platforms, the buffer's size can be set; a size that's too small
201could mean that, if too many packets are being captured and the snapshot
202length doesn't limit the amount of data that's buffered, packets could
203be dropped if the buffer fills up before the application can read
204packets from it, while a size that's too large could use more
205non-pageable operating system memory than is necessary to prevent
206packets from being dropped.
207.IP
208The buffer size is set with
209.BR pcap_set_buffer_size ().
210.IP "timestamp type"
211On some platforms, the time stamp given to packets on live captures can
212come from different sources that can have different resolutions or that
213can have different relationships to the time values for the current time
214supplied by routines on the native operating system. See
215.BR pcap-tstamp (@MAN_MISC_INFO@)
216for a list of time stamp types.
217.IP
218The time stamp type is set with
219.BR pcap_set_tstamp_type ().
220.PP
221Reading packets from a network interface may require that you have
222special privileges:
223.TP
224.B Under SunOS 3.x or 4.x with NIT or BPF:
225You must have read access to
226.I /dev/nit
227or
228.IR /dev/bpf* .
229.TP
230.B Under Solaris with DLPI:
231You must have read/write access to the network pseudo device, e.g.
232.IR /dev/le .
233On at least some versions of Solaris, however, this is not sufficient to
234allow
235.I tcpdump
236to capture in promiscuous mode; on those versions of Solaris, you must
237be root, or the application capturing packets
238must be installed setuid to root, in order to capture in promiscuous
239mode. Note that, on many (perhaps all) interfaces, if you don't capture
240in promiscuous mode, you will not see any outgoing packets, so a capture
241not done in promiscuous mode may not be very useful.
242.IP
243In newer versions of Solaris, you must have been given the
244.B net_rawaccess
245privilege; this is both necessary and sufficient to give you access to the
246network pseudo-device - there is no need to change the privileges on
247that device. A user can be given that privilege by, for example, adding
248that privilege to the user's
249.B defaultpriv
250key with the
251.B usermod (1M)
252command.
253.TP
254.B Under HP-UX with DLPI:
255You must be root or the application capturing packets must be installed
256setuid to root.
257.TP
258.B Under IRIX with snoop:
259You must be root or the application capturing packets must be installed
260setuid to root.
261.TP
262.B Under Linux:
263You must be root or the application capturing packets must be installed
264setuid to root (unless your distribution has a kernel
265that supports capability bits such as CAP_NET_RAW and code to allow
266those capability bits to be given to particular accounts and to cause
267those bits to be set on a user's initial processes when they log in, in
268which case you must have CAP_NET_RAW in order to capture and
269CAP_NET_ADMIN to enumerate network devices with, for example, the
270.B \-D
271flag).
272.TP
273.B Under ULTRIX and Digital UNIX/Tru64 UNIX:
274Any user may capture network traffic.
275However, no user (not even the super-user) can capture in promiscuous
276mode on an interface unless the super-user has enabled promiscuous-mode
277operation on that interface using
278.IR pfconfig (8),
279and no user (not even the super-user) can capture unicast traffic
280received by or sent by the machine on an interface unless the super-user
281has enabled copy-all-mode operation on that interface using
282.IR pfconfig ,
283so
284.I useful
285packet capture on an interface probably requires that either
286promiscuous-mode or copy-all-mode operation, or both modes of
287operation, be enabled on that interface.
288.TP
289.B Under BSD (this includes Mac OS X):
290You must have read access to
291.I /dev/bpf*
292on systems that don't have a cloning BPF device, or to
293.I /dev/bpf
294on systems that do.
295On BSDs with a devfs (this includes Mac OS X), this might involve more
296than just having somebody with super-user access setting the ownership
297or permissions on the BPF devices - it might involve configuring devfs
298to set the ownership or permissions every time the system is booted,
299if the system even supports that; if it doesn't support that, you might
300have to find some other way to make that happen at boot time.
301.PP
302Reading a saved packet file doesn't require special privileges.
303.PP
304The packets read from the handle may include a ``pseudo-header''
305containing various forms of packet meta-data, and probably includes a
306link-layer header whose contents can differ for different network
307interfaces. To determine the format of the packets supplied by the
308handle, call
309.BR pcap_datalink ();
310.I http://www.tcpdump.org/linktypes.html
311lists the values it returns and describes the packet formats that
312correspond to those values.
313.PP
314Do
315.B NOT
316assume that the packets for a given capture or ``savefile`` will have
317any given link-layer header type, such as
318.B DLT_EN10MB
319for Ethernet. For example, the "any" device on Linux will have a
320link-layer header type of
321.B DLT_LINUX_SLL
322even if all devices on the system at the time the "any" device is opened
323have some other data link type, such as
324.B DLT_EN10MB
325for Ethernet.
326.PP
327To obtain the
328.B "FILE\ *"
329corresponding to a
330.B pcap_t
331opened for a ``savefile'', call
332.BR pcap_file ().
333.TP
334.B Routines
335.RS
336.TP
337.BR pcap_create (3PCAP)
338get a
339.B pcap_t
340for live capture
341.TP
342.BR pcap_activate (3PCAP)
343activate a
344.B pcap_t
345for live capture
346.TP
347.BR pcap_findalldevs (3PCAP)
348get a list of devices that can be opened for a live capture
349.TP
350.BR pcap_freealldevs (3PCAP)
351free list of devices
352.TP
353.BR pcap_lookupdev (3PCAP)
354get first non-loopback device on that list
355.TP
356.BR pcap_open_offline (3PCAP)
357open a
358.B pcap_t
359for a ``savefile'', given a pathname
360.TP
361.BR pcap_fopen_offline (3PCAP)
362open a
363.B pcap_t
364for a ``savefile'', given a
365.B "FILE\ *"
366.TP
367.BR pcap_open_dead (3PCAP)
368create a ``fake''
369.B pcap_t
370.TP
371.BR pcap_close (3PCAP)
372close a
373.B pcap_t
374.TP
375.BR pcap_set_snaplen (3PCAP)
376set the snapshot length for a not-yet-activated
377.B pcap_t
378for live capture
379.TP
380.BR pcap_snapshot (3PCAP)
381get the snapshot length for a
382.B pcap_t
383.TP
384.BR pcap_set_promisc (3PCAP)
385set promiscuous mode for a not-yet-activated
386.B pcap_t
387for live capture
388.TP
389.BR pcap_set_rfmon (3PCAP)
390set monitor mode for a not-yet-activated
391.B pcap_t
392for live capture
393.TP
394.BR pcap_can_set_rfmon (3PCAP)
395determine whether monitor mode can be set for a
396.B pcap_t
397for live capture
398.TP
399.BR pcap_set_timeout (3PCAP)
400set read timeout for a not-yet-activated
401.B pcap_t
402for live capture
403.TP
404.BR pcap_set_buffer_size (3PCAP)
405set buffer size for a not-yet-activated
406.B pcap_t
407for live capture
408.TP
409.BR pcap_set_tstamp_type (3PCAP)
410set time stamp type for a not-yet-activated
411.B pcap_t
412for live capture
413.TP
414.BR pcap_list_tstamp_types (3PCAP)
415get list of available time stamp types for a not-yet-activated
416.B pcap_t
417for live capture
418.TP
419.BR pcap_free_tstamp_types (3PCAP)
420free list of available time stamp types
421.TP
422.BR pcap_tstamp_type_val_to_name (3PCAP)
423get name for a time stamp type
424.TP
425.BR pcap_tstamp_type_val_to_description (3PCAP)
426get description for a time stamp type
427.TP
428.BR pcap_tstamp_name_to_val (3PCAP)
429get time stamp type corresponding to a name
430.TP
431.BR pcap_datalink (3PCAP)
432get link-layer header type for a
433.B pcap_t
434.TP
435.BR pcap_file (3PCAP)
436get the
437.B "FILE\ *"
438for a
439.B pcap_t
440opened for a ``savefile''
441.TP
442.BR pcap_is_swapped (3PCAP)
443determine whether a ``savefile'' being read came from a machine with the
444opposite byte order
445.TP
446.BR pcap_major_version (3PCAP)
447.PD 0
448.TP
449.BR pcap_minor_version (3PCAP)
450get the major and minor version of the file format version for a
451``savefile''
452.PD
453.RE
454.SS Selecting a link-layer header type for a live capture
455Some devices may provide more than one link-layer header type. To
456obtain a list of all link-layer header types provided by a device, call
457.BR pcap_list_datalinks ()
458on an activated
459.B pcap_t
460for the device.
461To free a list of link-layer header types, call
462.BR pcap_free_datalinks ().
463To set the link-layer header type for a device, call
464.BR pcap_set_datalink ().
465This should be done after the device has been activated but before any
466packets are read and before any filters are compiled or installed.
467.TP
468.B Routines
469.RS
470.TP
471.BR pcap_list_datalinks (3PCAP)
472get a list of link-layer header types for a device
473.TP
474.BR pcap_free_datalinks (3PCAP)
475free list of link-layer header types
476.TP
477.BR pcap_set_datalink (3PCAP)
478set link-layer header type for a device
479.TP
480.BR pcap_datalink_val_to_name (3PCAP)
481get name for a link-layer header type
482.TP
483.BR pcap_datalink_val_to_description (3PCAP)
484get description for a link-layer header type
485.TP
486.BR pcap_datalink_name_to_val (3PCAP)
487get link-layer header type corresponding to a name
488.RE
489.SS Reading packets
490Packets are read with
491.BR pcap_dispatch ()
492or
493.BR pcap_loop (),
494which process one or more packets, calling a callback routine for each
495packet, or with
496.BR pcap_next ()
497or
498.BR pcap_next_ex (),
499which return the next packet.
500The callback for
501.BR pcap_dispatch ()
502and
503.BR pcap_loop ()
504is supplied a pointer to a
505.IR "struct pcap_pkthdr" ,
506which includes the following members:
507.RS
508.TP
509.B ts
510a
511.I struct timeval
512containing the time when the packet was captured
513.TP
514.B caplen
515a
516.I bpf_u_int32
517giving the number of bytes of the packet that are available from the
518capture
519.TP
520.B len
521a
522.I bpf_u_int32
523giving the length of the packet, in bytes (which might be more than the
524number of bytes available from the capture, if the length of the packet
525is larger than the maximum number of bytes to capture).
526.RE
527.PP
528The callback is also supplied a
529.I const u_char
530pointer to the first
531.B caplen
532(as given in the
533.I struct pcap_pkthdr
534mentioned above)
535bytes of data from the packet. This won't necessarily be the entire
536packet; to capture the entire packet, you will have to provide a value
537for
538.I snaplen
539in your call to
540.BR pcap_set_snaplen ()
541that is sufficiently large to get all of the packet's data - a value of
54265535 should be sufficient on most if not all networks). When reading
543from a ``savefile'', the snapshot length specified when the capture was
544performed will limit the amount of packet data available.
545.PP
546.BR pcap_next ()
547is passed an argument that points to a
548.I struct pcap_pkthdr
549structure, and fills it in with the time stamp and length values for the
550packet. It returns a
551.I const u_char
552to the first
553.B caplen
554bytes of the packet on success, and NULL on error.
555.PP
556.BR pcap_next_ex ()
557is passed two pointer arguments, one of which points to a
558.IR struct pcap_pkthdr *
559and one of which points to a
560.IR "const u_char" *.
561It sets the first pointer to point to a
562.I struct pcap_pkthdr
563structure with the time stamp and length values for the packet, and sets
564the second pointer to point to the first
565.B caplen
566bytes of the packet.
567.PP
568To force the loop in
569.BR pcap_dispatch ()
570or
571.BR pcap_loop ()
572to terminate, call
573.BR pcap_breakloop ().
574.PP
575By default, when reading packets from an interface opened for a live
576capture,
577.BR pcap_dispatch (),
578.BR pcap_next (),
579and
580.BR pcap_next_ex ()
581will, if no packets are currently available to be read, block waiting
582for packets to become available. On some, but
583.I not
584all, platforms, if a read timeout was specified, the wait will terminate
585after the read timeout expires; applications should be prepared for
586this, as it happens on some platforms, but should not rely on it, as it
587does not happen on other platforms.
588.PP
589A handle can be put into ``non-blocking mode'', so that those routines
590will, rather than blocking, return an indication that no packets are
591available to read. Call
592.BR pcap_setnonblock ()
593to put a handle into non-blocking mode or to take it out of non-blocking
594mode; call
595.BR pcap_getnonblock ()
596to determine whether a handle is in non-blocking mode. Note that
597non-blocking mode does not work correctly in Mac OS X 10.6.
598.PP
599Non-blocking mode is often combined with routines such as
600.BR select (2)
601or
602.BR poll (2)
603or other routines a platform offers to wait for the availability of data
604on any of a set of descriptors. To obtain, for a handle, a descriptor
605that can be used in those routines, call
606.BR pcap_get_selectable_fd ().
607Not all handles have such a descriptor available;
608.BR pcap_get_selectable_fd ()
609will return \-1 if no such descriptor exists. In addition, for various
610reasons, one or more of those routines will not work properly with the
611descriptor; the documentation for
612.BR pcap_get_selectable_fd ()
613gives details.
614.TP
615.B Routines
616.RS
617.TP
618.BR pcap_dispatch (3PCAP)
619read a bufferful of packets from a
620.B pcap_t
621open for a live capture or the full set of packets from a
622.B pcap_t
623open for a ``savefile''
624.TP
625.BR pcap_loop (3PCAP)
626read packets from a
627.B pcap_t
628until an interrupt or error occurs
629.TP
630.BR pcap_next (3PCAP)
631read the next packet from a
632.B pcap_t
633without an indication whether an error occurred
634.TP
635.BR pcap_next_ex (3PCAP)
636read the next packet from a
637.B pcap_t
638with an error indication on an error
639.TP
640.BR pcap_breakloop (3PCAP)
641prematurely terminate the loop in
642.BR pcap_dispatch ()
643or
644.BR pcap_loop ()
645.TP
646.BR pcap_setnonblock (3PCAP)
647set or clear non-blocking mode on a
648.B pcap_t
649.TP
650.BR pcap_getnonblock (3PCAP)
651get the state of non-blocking mode for a
652.B pcap_t
653.TP
654.BR pcap_get_selectable_fd (3PCAP)
655attempt to get a descriptor for a
656.B pcap_t
657that can be used in calls such as
658.BR select (2)
659and
660.BR poll (2)
661.RE
662.SS Filters
663In order to cause only certain packets to be returned when reading
664packets, a filter can be set on a handle. For a live capture, the
665filtering will be performed in kernel mode, if possible, to avoid
666copying ``uninteresting'' packets from the kernel to user mode.
667.PP
668A filter can be specified as a text string; the syntax and semantics of
669the string are as described by
670.BR pcap-filter (@MAN_MISC_INFO@).
671A filter string is compiled into a program in a pseudo-machine-language
672by
673.BR pcap_compile ()
674and the resulting program can be made a filter for a handle with
675.BR pcap_setfilter ().
676The result of
677.BR pcap_compile ()
678can be freed with a call to
679.BR pcap_freecode ().
680.BR pcap_compile ()
681may require a network mask for certain expressions in the filter string;
682.BR pcap_lookupnet ()
683can be used to find the network address and network mask for a given
684capture device.
685.PP
686A compiled filter can also be applied directly to a packet that has been
687read using
688.BR pcap_offline_filter ().
689.TP
690.B Routines
691.RS
692.TP
693.BR pcap_compile (3PCAP)
694compile filter expression to a pseudo-machine-language code program
695.TP
696.BR pcap_freecode (3PCAP)
697free a filter program
698.TP
699.BR pcap_setfilter (3PCAP)
700set filter for a
701.B pcap_t
702.TP
703.BR pcap_lookupnet (3PCAP)
704get network address and network mask for a capture device
705.TP
706.BR pcap_offline_filter (3PCAP)
707apply a filter program to a packet
708.RE
709.SS Incoming and outgoing packets
710By default, libpcap will attempt to capture both packets sent by the
711machine and packets received by the machine. To limit it to capturing
712only packets received by the machine or, if possible, only packets sent
713by the machine, call
714.BR pcap_setdirection ().
715.TP
716.BR Routines
717.RS
718.TP
719.BR pcap_setdirection (3PCAP)
720specify whether to capture incoming packets, outgoing packets, or both
721.RE
722.SS Capture statistics
723To get statistics about packets received and dropped in a live capture,
724call
725.BR pcap_stats ().
726.TP
727.B Routines
728.RS
729.TP
730.BR pcap_stats (3PCAP)
731get capture statistics
732.RE
733.SS Opening a handle for writing captured packets
734To open a ``savefile`` to which to write packets, given the pathname the
735``savefile'' should have, call
736.BR pcap_dump_open ().
737To open a ``savefile`` to which to write packets, given the pathname the
738``savefile'' should have, call
739.BR pcap_dump_open ();
740to set up a handle for a ``savefile'', given a
741.B "FILE\ *"
742referring to a file already opened for writing, call
743.BR pcap_dump_fopen ().
744They each return pointers to a
745.BR pcap_dumper_t ,
746which is the handle used for writing packets to the ``savefile''. If it
747succeeds, it will have created the file if it doesn't exist and
748truncated the file if it does exist.
749To close a
750.BR pcap_dumper_t ,
751call
752.BR pcap_dump_close ().
753.TP
754.B Routines
755.RS
756.TP
757.BR pcap_dump_open (3PCAP)
758open a
759.B pcap_dumper_t
760for a ``savefile``, given a pathname
761.TP
762.BR pcap_dump_fopen (3PCAP)
763open a
764.B pcap_dumper_t
765for a ``savefile``, given a
766.B "FILE\ *"
767.TP
768.BR pcap_dump_close (3PCAP)
769close a
770.B pcap_dumper_t
771.TP
772.BR pcap_dump_file (3PCAP)
773get the
774.B "FILE\ *"
775for a
776.B pcap_dumper_t
777opened for a ``savefile''
778.RE
779.SS Writing packets
780To write a packet to a
781.BR pcap_dumper_t ,
782call
783.BR pcap_dump ().
784Packets written with
785.BR pcap_dump ()
786may be buffered, rather than being immediately written to the
787``savefile''. Closing the
788.B pcap_dumper_t
789will cause all buffered-but-not-yet-written packets to be written to the
790``savefile''.
791To force all packets written to the
792.BR pcap_dumper_t ,
793and not yet written to the ``savefile'' because they're buffered by the
794.BR pcap_dumper_t ,
795to be written to the ``savefile'', without closing the
796.BR pcap_dumper_t ,
797call
798.BR pcap_dump_flush ().
799.TP
800.B Routines
801.RS
802.TP
803.BR pcap_dump (3PCAP)
804write packet to a
805.B pcap_dumper_t
806.TP
807.BR pcap_dump_flush (3PCAP)
808flush buffered packets written to a
809.B pcap_dumper_t
810to the ``savefile''
811.TP
812.BR pcap_dump_ftell (3PCAP)
813get current file position for a
814.B pcap_dumper_t
815.RE
816.SS Injecting packets
817If you have the required privileges, you can inject packets onto a
818network with a
819.B pcap_t
820for a live capture, using
821.BR pcap_inject ()
822or
823.BR pcap_sendpacket ().
824(The two routines exist for compatibility with both OpenBSD and WinPcap;
825they perform the same function, but have different return values.)
826.TP
827.B Routines
828.RS
829.TP
830.BR pcap_inject (3PCAP)
831.PD 0
832.TP
833.BR pcap_sendpacket (3PCAP)
834transmit a packet
835.PD
836.RE
837.SS Reporting errors
838Some routines return error or warning status codes; to convert them to a
839string, use
840.BR pcap_statustostr ().
841.TP
842.B Routines
843.RS
844.TP
845.BR pcap_statustostr (3PCAP)
846get a string for an error or warning status code
847.RE
848.SS Getting library version information
849To get a string giving version information about libpcap, call
850.BR pcap_library_version ().
851.TP
852.B Routines
853.RS
854.TP
855.BR pcap_library_version (3PCAP)
856get library version string
857.RE
858.SH BACKWARDS COMPATIBILITY
859.PP
860In versions of libpcap prior to 1.0, the
861.B pcap.h
862header file was not in a
863.B pcap
864directory on most platforms; if you are writing an application that must
865work on versions of libpcap prior to 1.0, include
866.BR <pcap.h> ,
867which will include
868.B <pcap/pcap.h>
869for you, rather than including
870.BR <pcap/pcap.h> .
871.PP
872.BR pcap_create ()
873and
874.BR pcap_activate ()
875were not available in versions of libpcap prior to 1.0; if you are
876writing an application that must work on versions of libpcap prior to
8771.0, either use
878.BR pcap_open_live ()
879to get a handle for a live capture or, if you want to be able to use the
880additional capabilities offered by using
881.BR pcap_create ()
882and
883.BR pcap_activate (),
884use an
885.BR autoconf (1)
886script or some other configuration script to check whether the libpcap
8871.0 APIs are available and use them only if they are.
888.SH SEE ALSO
889autoconf(1), tcpdump(1), tcpslice(1), pcap-filter(@MAN_MISC_INFO@), pfconfig(8),
890usermod(1M)
891.SH AUTHORS
892The original authors of libpcap are:
893.LP
894Van Jacobson,
895Craig Leres and
896Steven McCanne, all of the
897Lawrence Berkeley National Laboratory, University of California, Berkeley, CA.
898.LP
899The current version is available from "The Tcpdump Group"'s Web site at
900.LP
901.RS
902.I http://www.tcpdump.org/
903.RE
904.SH BUGS
905Please send problems, bugs, questions, desirable enhancements, etc. to:
906.LP
907.RS
908tcpdump-workers@lists.tcpdump.org
909.RE