1 .\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.66 2005-05-03 18:54:01 guy Exp $
3 .\" Copyright (c) 1994, 1996, 1997
4 .\" The Regents of the University of California. All rights reserved.
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.
22 .TH PCAP 3 "27 February 2004"
24 pcap \- Packet Capture library
33 char errbuf[PCAP_ERRBUF_SIZE];
37 pcap_t *pcap_open_live(const char *device, int snaplen,
39 int promisc, int to_ms, char *errbuf)
40 pcap_t *pcap_open_dead(int linktype, int snaplen)
41 pcap_t *pcap_open_offline(const char *fname, char *errbuf)
42 pcap_t *pcap_fopen_offline(FILE *fp, char *errbuf)
43 pcap_dumper_t *pcap_dump_open(pcap_t *p, const char *fname)
44 pcap_dumper_t *pcap_dump_fopen(pcap_t *p, FILE *fp)
48 int pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf);
49 int pcap_getnonblock(pcap_t *p, char *errbuf);
53 int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
54 void pcap_freealldevs(pcap_if_t *alldevs)
55 char *pcap_lookupdev(char *errbuf)
56 int pcap_lookupnet(const char *device, bpf_u_int32 *netp,
58 bpf_u_int32 *maskp, char *errbuf)
62 typedef void (*pcap_handler)(u_char *user, const struct pcap_pkthdr *h,
66 int pcap_dispatch(pcap_t *p, int cnt,
68 pcap_handler callback, u_char *user)
69 int pcap_loop(pcap_t *p, int cnt,
71 pcap_handler callback, u_char *user)
72 void pcap_dump(u_char *user, struct pcap_pkthdr *h,
78 int pcap_compile(pcap_t *p, struct bpf_program *fp,
80 char *str, int optimize, bpf_u_int32 netmask)
81 int pcap_setfilter(pcap_t *p, struct bpf_program *fp)
82 void pcap_freecode(struct bpf_program *)
83 int pcap_setdirection(pcap_t *p, direction_t d)
87 const u_char *pcap_next(pcap_t *p, struct pcap_pkthdr *h)
88 int pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
90 const u_char **pkt_data)
94 void pcap_breakloop(pcap_t *)
98 int pcap_inject(pcap_t *p, const void *buf, size_t size)
99 int pcap_sendpacket(pcap_t *p, const u_char *buf, int size)
103 int pcap_datalink(pcap_t *p)
104 int pcap_list_datalinks(pcap_t *p, int **dlt_buf);
105 int pcap_set_datalink(pcap_t *p, int dlt);
106 int pcap_datalink_name_to_val(const char *name);
107 const char *pcap_datalink_val_to_name(int dlt);
108 const char *pcap_datalink_val_to_description(int dlt);
109 int pcap_snapshot(pcap_t *p)
110 int pcap_is_swapped(pcap_t *p)
111 int pcap_major_version(pcap_t *p)
112 int pcap_minor_version(pcap_t *p)
113 int pcap_stats(pcap_t *p, struct pcap_stat *ps)
114 FILE *pcap_file(pcap_t *p)
115 int pcap_fileno(pcap_t *p)
116 int pcap_get_selectable_fd(pcap_t *p);
117 void pcap_perror(pcap_t *p, char *prefix)
118 char *pcap_geterr(pcap_t *p)
119 char *pcap_strerror(int error)
120 const char *pcap_lib_version(void)
124 void pcap_close(pcap_t *p)
125 int pcap_dump_flush(pcap_dumper_t *p)
126 FILE *pcap_dump_file(pcap_dumper_t *p)
127 void pcap_dump_close(pcap_dumper_t *p)
131 The Packet Capture library
132 provides a high level interface to packet capture systems. All packets
133 on the network, even those destined for other hosts, are accessible
134 through this mechanism.
140 .BR pcap_open_live() ,
141 .BR pcap_open_dead() ,
142 .BR pcap_open_offline() ,
143 .BR pcap_fopen_offline() ,
144 .BR pcap_setnonblock() ,
145 .BR pcap_getnonblock() ,
146 .BR pcap_findalldevs() ,
147 .BR pcap_lookupdev() ,
150 is assumed to be able to hold at least
155 is used to obtain a packet capture descriptor to look
156 at packets on the network.
158 is a string that specifies the network device to open; on Linux systems
159 with 2.2 or later kernels, a
163 can be used to capture packets from all interfaces.
165 specifies the maximum number of bytes to capture. If this value is less
166 than the size of a packet that is captured, only the first
168 bytes of that packet will be captured and provided as packet data. A
169 value of 65535 should be sufficient, on most if not all networks, to
170 capture all the data available from the packet.
172 specifies if the interface is to be put into promiscuous mode.
173 (Note that even if this parameter is false, the interface
174 could well be in promiscuous mode for some other reason.) For now, this
175 doesn't work on the "any" device; if an argument of "any" or NULL is
180 specifies the read timeout in milliseconds. The read timeout is used to
181 arrange that the read not necessarily return immediately when a packet
182 is seen, but that it wait for some amount of time to allow more packets
183 to arrive and to read multiple packets from the OS kernel in one
184 operation. Not all platforms support a read timeout; on platforms that
185 don't, the read timeout is ignored. A zero value for
187 on platforms that support a read timeout,
188 will cause a read to wait forever to allow enough packets to
189 arrive, with no timeout.
191 is used to return error or warning text. It will be set to error text when
196 may also be set to warning text when
198 succeds; to detect this case the caller should store a zero-length string in
202 and display the warning to the user if
204 is no longer a zero-length string.
207 is used for creating a
209 structure to use when calling the other functions in libpcap. It is
210 typically used when just using libpcap for compiling BPF code.
212 .B pcap_open_offline()
213 is called to open a ``savefile'' for reading.
215 specifies the name of the file to open. The file has
216 the same format as those used by
220 The name "-" in a synonym for
222 Alternatively, you may call
223 .B pcap_fopen_offline()
224 to read dumped data from an existing open stream
226 Note that on Windows, that stream should be opened in binary mode.
228 is used to return error text and is only set when
229 .B pcap_open_offline()
231 .B pcap_fopen_offline()
236 is called to open a ``savefile'' for writing. The name "-" in a synonym
240 is returned on failure.
244 struct as returned by
245 .B pcap_open_offline()
247 .BR pcap_open_live() .
249 specifies the name of the file to open. Alternatively, you may call
251 to write data to an existing open stream
253 Note that on Windows, that stream should be opened in binary mode.
258 can be used to get the error text.
261 .B pcap_setnonblock()
262 puts a capture descriptor, opened with
263 .BR pcap_open_live() ,
264 into ``non-blocking'' mode, or takes it out of ``non-blocking'' mode,
265 depending on whether the
267 argument is non-zero or zero. It has no effect on ``savefiles''.
268 If there is an error, \-1 is returned and
270 is filled in with an appropriate error message; otherwise, 0 is
273 ``non-blocking'' mode, an attempt to read from the capture descriptor
276 will, if no packets are currently available to be read, return 0
277 immediately rather than blocking waiting for packets to arrive.
281 will not work in ``non-blocking'' mode.
283 .B pcap_getnonblock()
284 returns the current ``non-blocking'' state of the capture descriptor; it
285 always returns 0 on ``savefiles''.
286 If there is an error, \-1 is returned and
288 is filled in with an appropriate error message.
290 .B pcap_findalldevs()
291 constructs a list of network devices that can be opened with
292 .BR pcap_open_live() .
293 (Note that there may be network devices that cannot be opened with
297 .BR pcap_findalldevs() ,
298 because, for example, that process might not have sufficient privileges
299 to open them for capturing; if so, those devices will not appear on the
302 is set to point to the first element of the list; each element of the
305 and has the following members:
311 a pointer to the next element in the list;
313 for the last element of the list
316 a pointer to a string giving a name for the device to pass to
322 a pointer to a string giving a human-readable description of the device
325 a pointer to the first element of a list of addresses for the interface
332 set if the interface is a loopback interface
336 Each element of the list of addresses is of type
338 and has the following members:
344 a pointer to the next element in the list;
346 for the last element of the list
351 containing an address
358 that contains the netmask corresponding to the address pointed to by
366 that contains the broadcast address corresponding to the address pointed
369 may be null if the interface doesn't support broadcasts
376 that contains the destination address corresponding to the address pointed
379 may be null if the interface isn't a point-to-point interface
382 Note that not all the addresses in the list of addresses are
383 necessarily IPv4 or IPv6 addresses - you must check the
387 before interpreting the contents of the address.
390 is returned on failure, in which case
392 is filled in with an appropriate error message;
394 is returned on success.
396 .B pcap_freealldevs()
397 is used to free a list allocated by
398 .BR pcap_findalldevs() .
401 returns a pointer to a network device suitable for use with
404 .BR pcap_lookupnet() .
405 If there is an error,
409 is filled in with an appropriate error message.
412 is used to determine the network number and mask
413 associated with the network device
422 A return of \-1 indicates an error in which case
424 is filled in with an appropriate error message.
427 is used to collect and process packets.
429 specifies the maximum number of packets to process before returning.
430 This is not a minimum number; when reading a live capture, only one
431 bufferful of packets is read at a time, so fewer than
433 packets may be processed. A
435 of \-1 processes all the packets received in one buffer when reading a
436 live capture, or all the packets in the file when reading a
439 specifies a routine to be called with three arguments:
442 pointer which is passed in from
443 .BR pcap_dispatch() ,
445 .I const struct pcap_pkthdr
446 pointer to a structure with the following members:
452 containing the time when the packet was captured
457 giving the number of bytes of the packet that are available from the
463 giving the length of the packet, in bytes (which might be more than the
464 number of bytes available from the capture, if the length of the packet
465 is larger than the maximum number of bytes to capture)
473 .I struct pcap_pkthdr
474 a pointer to which is passed to the callback routine)
475 bytes of data from the packet (which won't necessarily be the entire
476 packet; to capture the entire packet, you will have to provide a value
481 that is sufficiently large to get all of the packet's data - a value of
482 65535 should be sufficient on most if not all networks).
484 The number of packets read is returned.
485 0 is returned if no packets were read from a live capture (if, for
486 example, they were discarded because they didn't pass the packet filter,
487 or if, on platforms that support a read timeout that starts before any
488 packets arrive, the timeout expires before any packets arrive, or if the
489 file descriptor for the capture device is in non-blocking mode and no
490 packets were available to be read) or if no more packets are available
491 in a ``savefile.'' A return of \-1 indicates
492 an error in which case
496 may be used to display the error text.
497 A return of \-2 indicates that the loop terminated due to a call to
499 before any packets were processed.
501 If your application uses pcap_breakloop(),
502 make sure that you explicitly check for \-1 and \-2, rather than just
503 checking for a return value < 0.
507 when reading a live capture,
509 will not necessarily return when the read times out; on some platforms,
510 the read timeout isn't supported, and, on other platforms, the timer
511 doesn't start until at least one packet arrives. This means that the
514 be used in, for example, an interactive application, to allow the packet
515 capture loop to ``poll'' for user input periodically, as there's no
518 will return after the timeout expires.
523 except it keeps reading packets until
525 packets are processed or an error occurs.
528 return when live read timeouts occur.
529 Rather, specifying a non-zero read timeout to
533 allows the reception and processing of any packets that arrive when the
539 to loop forever (or at least until an error occurs). \-1 is returned on
540 an error; 0 is returned if
542 is exhausted; \-2 is returned if the loop terminated due to a call to
544 before any packets were processed.
546 If your application uses pcap_breakloop(),
547 make sure that you explicitly check for \-1 and \-2, rather than just
548 checking for a return value < 0.
552 reads the next packet (by calling
558 pointer to the data in that packet. (The
560 struct for that packet is not supplied.)
562 is returned if an error occured, or if no packets were read from a live
563 capture (if, for example, they were discarded because they didn't pass
564 the packet filter, or if, on platforms that support a read timeout that
565 starts before any packets arrive, the timeout expires before any packets
566 arrive, or if the file descriptor for the capture device is in
567 non-blocking mode and no packets were available to be read), or if no
568 more packets are available in a ``savefile.'' Unfortunately, there is
569 no way to determine whether an error occured or not.
572 reads the next packet and returns a success/failure indication:
576 the packet was read without problems
579 packets are being read from a live capture, and the timeout expired
582 an error occurred while reading the packet
585 packets are being read from a ``savefile'', and there are no more
586 packets to read from the savefile.
589 If the packet was read without problems, the pointer pointed to by the
591 argument is set to point to the
593 struct for the packet, and the
594 pointer pointed to by the
596 argument is set to point to the data in the packet.
599 sets a flag that will force
603 to return rather than looping; they will return the number of packets
604 that have been processed so far, or \-2 if no packets have been
607 This routine is safe to use inside a signal handler on UNIX or a console
608 control handler on Windows, as it merely sets a flag that is checked
611 The flag is checked in loops reading packets from the OS - a signal by
612 itself will not necessarily terminate those loops - as well as in loops
613 processing a set of packets returned by the OS.
615 Note that if you are catching signals on UNIX systems that support
616 restarting system calls after a signal, and calling pcap_breakloop()
617 in the signal handler, you must specify, when catching those signals,
618 that system calls should NOT be restarted by that signal. Otherwise,
619 if the signal interrupted a call reading packets in a live capture,
620 when your signal handler returns after calling pcap_breakloop(), the
621 call will be restarted, and the loop will not terminate until more
622 packets arrive and the call completes.
624 Note also that, in a multi-threaded application, if one thread is
626 .BR pcap_dispatch() ,
633 in a different thread will not unblock that thread; you will need to use
634 whatever mechanism the OS provides for breaking a thread out of blocking
635 calls in order to unblock the thread, such as thread cancellation in
636 systems that support POSIX threads.
641 will, on some platforms, loop reading packets from the OS; that loop
642 will not necessarily be terminated by a signal, so
644 should be used to terminate packet processing even if
649 does not guarantee that no further packets will be processed by
653 after it is called; at most one more packet might be processed.
655 If \-2 is returned from
659 the flag is cleared, so a subsequent call will resume reading packets.
660 If a positive number is returned, the flag is not cleared, so a
661 subsequent call will return \-2 and clear the flag.
664 sends a raw packet through the network interface;
666 points to the data of the packet, including the link-layer header, and
668 is the number of bytes in the packet.
669 It returns the number of bytes written on success. A return of \-1
670 indicates an error in which case
674 may be used to display the error text.
675 Note that, even if you successfully open the network interface, you
676 might not have permission to send packets on it, or it might not support
679 doesn't have a flag to indicate whether to open for capturing, sending,
680 or capturing and sending, you cannot request an open that supports
681 sending and be notified at open time whether sending will be possible.
682 Note also that some devices might not support sending packets.
684 Note that, on some platforms, the link-layer header of the packet that's
685 sent might not be the same as the link-layer header of the packet
688 as the source link-layer address, if the header contains such an
689 address, might be changed to be the address assigned to the interface on
690 which the packet it sent, if the platform doesn't support sending
691 completely raw and unchanged packets.
696 but it returns 0 on success and \-1 on failure.
700 comes from WinPcap. Both are provided for compatibility.)
703 outputs a packet to the ``savefile'' opened with
704 .BR pcap_dump_open() .
705 Note that its calling arguments are suitable for use with
709 If called directly, the
714 .BR pcap_dump_open() .
717 is used to compile the string
719 into a filter program.
723 struct and is filled in by
726 controls whether optimization on the resulting code is performed.
728 specifies the IPv4 netmask of the network on which packets are being
729 captured; it is used only when checking for IPv4 broadcast addresses in
730 the filter program. If the netmask of the network on which packets are
731 being captured isn't known to the program, or if packets are being
732 captured on the Linux "any" pseudo-interface that can capture on more
733 than one network, a value of 0 can be supplied; tests for IPv4 broadcast
734 addreses won't be done correctly, but all other tests in the filter
735 program will be OK. A return of \-1 indicates an error in which case
737 may be used to display the error text.
739 .B pcap_compile_nopcap()
742 except that instead of passing a pcap structure, one passes the
743 snaplen and linktype explicitly. It is intended to be used for
744 compiling filters for direct BPF usage, without necessarily having
747 A return of \-1 indicates an error; the error text is unavailable.
748 .RB ( pcap_compile_nopcap()
750 .BR pcap_open_dead() ,
754 the latter three routines can be used directly in order to get the error
755 text for a compilation error.)
759 is used to specify a filter program.
763 struct, usually the result of a call to
766 is returned on failure, in which case
768 may be used to display the error text;
770 is returned on success.
773 is used to free up allocated memory pointed to by a
777 when that BPF program is no longer needed, for example after it
778 has been made the filter program for a pcap structure by a call to
779 .BR pcap_setfilter() .
781 .B pcap_setdirection()
782 is used to specify a direction that packets will be captured.
784 is one of the constants
790 will only capture packets received by the device,
792 will only capture packets sent by the device and
794 will capture packets received by or sent by the device.
796 is the default setting if this function is not called. This isn't
797 necessarily supported on all platforms; some platforms might return an
798 error, and some other platforms might not support
801 is returned on failure,
803 is returned on success.
806 returns the link layer type; link layer types it can return include:
811 BSD loopback encapsulation; the link layer header is a 4-byte field, in
813 byte order, containing a PF_ value from
815 for the network-layer protocol of the packet.
817 Note that ``host byte order'' is the byte order of the machine on which
818 the packets are captured, and the PF_ values are for the OS of the
819 machine on which the packets are captured; if a live capture is being
820 done, ``host byte order'' is the byte order of the machine capturing the
821 packets, and the PF_ values are those of the OS of the machine capturing
822 the packets, but if a ``savefile'' is being read, the byte order and PF_
825 necessarily those of the machine reading the capture file.
828 Ethernet (10Mb, 100Mb, 1000Mb, and up)
831 IEEE 802.5 Token Ring
837 SLIP; the link layer header contains, in order:
840 a 1-byte flag, which is 0 for packets received by the machine and 1 for
841 packets sent by the machine;
843 a 1-byte field, the upper 4 bits of which indicate the type of packet,
848 an unmodified IP datagram (TYPE_IP);
851 an uncompressed-TCP IP datagram (UNCOMPRESSED_TCP), with that byte being
852 the first byte of the raw IP header on the wire, containing the
853 connection number in the protocol field;
856 a compressed-TCP IP datagram (COMPRESSED_TCP), with that byte being the
857 first byte of the compressed TCP/IP datagram header;
860 for UNCOMPRESSED_TCP, the rest of the modified IP header, and for
861 COMPRESSED_TCP, the compressed TCP/IP datagram header;
865 for a total of 16 bytes; the uncompressed IP datagram follows the header.
869 PPP; if the first 2 bytes are 0xff and 0x03, it's PPP in HDLC-like
870 framing, with the PPP header following those two bytes, otherwise it's
871 PPP without framing, and the packet begins with the PPP header.
877 RFC 1483 LLC/SNAP-encapsulated ATM; the packet begins with an IEEE 802.2
881 raw IP; the packet begins with an IP header.
884 PPP in HDLC-like framing, as per RFC 1662, or Cisco PPP with HDLC
885 framing, as per section 4.3.1 of RFC 1547; the first byte will be 0xFF
886 for PPP in HDLC-like framing, and will be 0x0F or 0x8F for Cisco PPP
890 PPPoE; the packet begins with a PPPoE header, as per RFC 2516.
893 Cisco PPP with HDLC framing, as per section 4.3.1 of RFC 1547.
896 IEEE 802.11 wireless LAN
902 OpenBSD loopback encapsulation; the link layer header is a 4-byte field, in
904 byte order, containing a PF_ value from OpenBSD's
906 for the network-layer protocol of the packet.
908 Note that, if a ``savefile'' is being read, those PF_ values are
910 necessarily those of the machine reading the capture file.
913 Linux "cooked" capture encapsulation; the link layer header contains, in
917 a 2-byte "packet type", in network byte order, which is one of:
921 packet was sent to us by somebody else
924 packet was broadcast by somebody else
927 packet was multicast, but not broadcast, by somebody else
930 packet was sent by somebody else to somebody else
933 packet was sent by us
936 a 2-byte field, in network byte order, containing a Linux ARPHRD_ value
937 for the link layer device type;
939 a 2-byte field, in network byte order, containing the length of the
940 link layer address of the sender of the packet (which could be 0);
942 an 8-byte field containing that number of bytes of the link layer header
943 (if there are more than 8 bytes, only the first 8 are present);
945 a 2-byte field containing an Ethernet protocol type, in network byte
946 order, or containing 1 for Novell 802.3 frames without an 802.2 LLC
947 header or 4 for frames beginning with an 802.2 LLC header.
951 Apple LocalTalk; the packet begins with an AppleTalk LLAP header.
954 OpenBSD pflog; the link layer header contains, in order:
957 a 1-byte header length, in host byte order;
959 a 4-byte PF_ value, in host byte order;
961 a 2-byte action code, in network byte order, which is one of:
974 a 2-byte reason code, in network byte order, which is one of:
996 a 16-character interface name;
998 a 16-character ruleset name (only meaningful if subrule is set);
1000 a 4-byte rule number, in network byte order;
1002 a 4-byte subrule number, in network byte order;
1004 a 1-byte direction, in network byte order, which is one of:
1008 incoming or outgoing
1019 Prism monitor mode information followed by an 802.11 header.
1022 RFC 2625 IP-over-Fibre Channel, with the link-layer header being the
1023 Network_Header as described in that RFC.
1026 SunATM devices; the link layer header contains, in order:
1029 a 1-byte flag field, containing a direction flag in the uppermost bit,
1030 which is set for packets transmitted by the machine and clear for
1031 packets received by the machine, and a 4-byte traffic type in the
1032 low-order 4 bits, which is one of:
1042 LLC-encapsulated traffic
1059 a 2-byte VCI field, in network byte order.
1062 .B DLT_IEEE802_11_RADIO
1063 link-layer information followed by an 802.11 header - see
1064 http://www.shaftnet.org/~pizza/software/capturefrm.txt for a description
1065 of the link-layer information.
1068 ARCNET, with no exception frames, reassembled packets rather than raw
1069 frames, and an extra 16-bit offset field between the destination host
1073 Linux-IrDA packets, with a
1075 header followed by the IrLAP header.
1078 .B pcap_list_datalinks()
1079 is used to get a list of the supported data link types of the interface
1080 associated with the pcap descriptor.
1081 .B pcap_list_datalinks()
1082 allocates an array to hold the list and sets
1084 The caller is responsible for freeing the array.
1086 is returned on failure;
1087 otherwise, the number of data link types in the array is returned.
1089 .B pcap_set_datalink()
1090 is used to set the current data link type of the pcap descriptor
1091 to the type specified by
1094 is returned on failure.
1096 .B pcap_datalink_name_to_val()
1097 translates a data link type name, which is a
1101 removed, to the corresponding data link type value. The translation
1102 is case-insensitive.
1104 is returned on failure.
1106 .B pcap_datalink_val_to_name()
1107 translates a data link type value to the corresponding data link type
1108 name. NULL is returned on failure.
1110 .B pcap_datalink_val_to_description()
1111 translates a data link type value to a short description of that data
1112 link type. NULL is returned on failure.
1115 returns the snapshot length specified when
1119 .B pcap_is_swapped()
1120 returns true if the current ``savefile'' uses a different byte order
1121 than the current system.
1123 .B pcap_major_version()
1124 returns the major number of the file format of the savefile;
1125 .B pcap_minor_version()
1126 returns the minor number of the file format of the savefile. The
1127 version number is stored in the header of the savefile.
1130 returns the standard I/O stream of the ``savefile,'' if a ``savefile''
1132 .BR pcap_open_offline() ,
1133 or NULL, if a network device was opened with
1134 .BR pcap_open_live() .
1137 returns 0 and fills in a
1139 struct. The values represent packet statistics from the start of the
1140 run to the time of the call. If there is an error or the underlying
1141 packet capture doesn't support packet statistics, \-1 is returned and
1142 the error text can be obtained with
1147 is supported only on live captures, not on ``savefiles''; no statistics
1148 are stored in ``savefiles'', so no statistics are available when reading
1149 from a ``savefile''.
1152 returns the file descriptor number from which captured packets are read,
1153 if a network device was opened with
1154 .BR pcap_open_live() ,
1155 or \-1, if a ``savefile'' was opened with
1156 .BR pcap_open_offline() .
1158 .B pcap_get_selectable_fd()
1159 returns, on UNIX, a file descriptor number for a file descriptor on
1165 to wait for it to be possible to read packets without blocking, if such
1166 a descriptor exists, or \-1, if no such descriptor exists. Some network
1173 (for example, regular network devices on FreeBSD 4.3 and 4.4, and Endace
1174 DAG devices), so \-1 is returned for those devices.
1176 Note that on most versions of most BSDs (including Mac OS X)
1180 do not work correctly on BPF devices;
1181 .B pcap_get_selectable_fd()
1182 will return a file descriptor on most of those versions (the exceptions
1183 being FreeBSD 4.3 and 4.4), a simple
1187 will not return even after a timeout specified in
1189 expires. To work around this, an application that uses
1193 to wait for packets to arrive must put the
1195 in non-blocking mode, and must arrange that the
1199 have a timeout less than or equal to the timeout specified in
1200 .BR pcap_open_live() ,
1201 and must try to read packets after that timeout expires, regardless of
1206 indicated that the file descriptor for the
1208 is ready to be read or not. (That workaround will not work in FreeBSD
1209 4.3 and later; however, in FreeBSD 4.6 and later,
1213 work correctly on BPF devices, so the workaround isn't necessary,
1214 although it does no harm.)
1216 .B pcap_get_selectable_fd()
1217 is not available on Windows.
1220 prints the text of the last pcap library error on
1226 returns the error text pertaining to the last pcap library error.
1228 the pointer it returns will no longer point to a valid error message
1231 passed to it is closed; you must use or copy the string before closing
1240 .B pcap_lib_version()
1241 returns a pointer to a string giving information about the version of
1242 the libpcap library being used; note that it contains more information
1243 than just a version number.
1246 closes the files associated with
1248 and deallocates resources.
1251 returns the standard I/O stream of the ``savefile'' opened by
1252 .BR pcap_dump_open().
1254 .B pcap_dump_flush()
1255 flushes the output buffer to the ``savefile,'' so that any packets
1258 but not yet written to the ``savefile'' will be written.
1260 is returned on error, 0 on success.
1262 .B pcap_dump_close()
1263 closes the ``savefile.''
1266 tcpdump(1), tcpslice(1)
1268 The original authors are:
1272 Steven McCanne, all of the
1273 Lawrence Berkeley National Laboratory, University of California, Berkeley, CA.
1275 The current version is available from "The Tcpdump Group"'s Web site at
1278 .I http://www.tcpdump.org/
1281 Please send problems, bugs, questions, desirable enhancements, etc. to:
1284 tcpdump-workers@tcpdump.org
1287 Please send source code contributions, etc. to: