]> The Tcpdump Group git mirrors - libpcap/blob - pcap.3
Indicate when "pcap_next()" returns NULL, and that, unfortunately, you
[libpcap] / pcap.3
1 .\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.40 2002-12-17 07:32:55 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 3 "3 January 2001"
23 .SH NAME
24 pcap \- Packet Capture library
25 .SH SYNOPSIS
26 .nf
27 .ft B
28 #include <pcap.h>
29 .ft
30 .LP
31 .nf
32 .ft B
33 char errbuf[PCAP_ERRBUF_SIZE];
34 .ft
35 .LP
36 .ft B
37 pcap_t *pcap_open_live(char *device, int snaplen,
38 .ti +8
39 int promisc, int to_ms, char *errbuf)
40 pcap_t *pcap_open_dead(int linktype, int snaplen)
41 pcap_t *pcap_open_offline(char *fname, char *errbuf)
42 pcap_dumper_t *pcap_dump_open(pcap_t *p, char *fname)
43 .ft
44 .LP
45 .ft B
46 int pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf);
47 int pcap_getnonblock(pcap_t *p, char *errbuf);
48 .ft
49 .LP
50 .ft B
51 int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
52 void pcap_freealldevs(pcap_if_t *)
53 char *pcap_lookupdev(char *errbuf)
54 int pcap_lookupnet(char *device, bpf_u_int32 *netp,
55 .ti +8
56 bpf_u_int32 *maskp, char *errbuf)
57 .ft
58 .LP
59 .ft B
60 int pcap_dispatch(pcap_t *p, int cnt,
61 .ti +8
62 pcap_handler callback, u_char *user)
63 int pcap_loop(pcap_t *p, int cnt,
64 .ti +8
65 pcap_handler callback, u_char *user)
66 void pcap_dump(u_char *user, struct pcap_pkthdr *h,
67 .ti +8
68 u_char *sp)
69 .ft
70 .LP
71 .ft B
72 int pcap_compile(pcap_t *p, struct bpf_program *fp,
73 .ti +8
74 char *str, int optimize, bpf_u_int32 netmask)
75 int pcap_setfilter(pcap_t *p, struct bpf_program *fp)
76 void pcap_freecode(struct bpf_program *);
77 .ft
78 .LP
79 .ft B
80 u_char *pcap_next(pcap_t *p, struct pcap_pkthdr *h)
81 .ft
82 .LP
83 .ft B
84 int pcap_datalink(pcap_t *p)
85 int pcap_snapshot(pcap_t *p)
86 int pcap_is_swapped(pcap_t *p)
87 int pcap_major_version(pcap_t *p)
88 int pcap_minor_version(pcap_t *p)
89 int pcap_stats(pcap_t *p, struct pcap_stat *ps)
90 FILE *pcap_file(pcap_t *p)
91 int pcap_fileno(pcap_t *p)
92 void pcap_perror(pcap_t *p, char *prefix)
93 char *pcap_geterr(pcap_t *p)
94 char *pcap_strerror(int error)
95 .ft
96 .LP
97 .ft B
98 void pcap_close(pcap_t *p)
99 void pcap_dump_close(pcap_dumper_t *p)
100 .ft
101 .fi
102 .SH DESCRIPTION
103 The Packet Capture library
104 provides a high level interface to packet capture systems. All packets
105 on the network, even those destined for other hosts, are accessible
106 through this mechanism.
107 .PP
108 .SH ROUTINES
109 NOTE:
110 .I errbuf
111 in
112 .BR pcap_open_live() ,
113 .BR pcap_open_dead() ,
114 .BR pcap_open_offline() ,
115 .BR pcap_setnonblock() ,
116 .BR pcap_getnonblock() ,
117 .BR pcap_findalldevs() ,
118 .BR pcap_lookupdev() ,
119 and
120 .B pcap_lookupnet()
121 is assumed to be able to hold at least
122 .B PCAP_ERRBUF_SIZE
123 chars.
124 .PP
125 .B pcap_open_live()
126 is used to obtain a packet capture descriptor to look
127 at packets on the network.
128 .I device
129 is a string that specifies the network device to open; on Linux systems
130 with 2.2 or later kernels, a
131 .I device
132 argument of "any" or
133 .B NULL
134 can be used to capture packets from all interfaces.
135 .I snaplen
136 specifies the maximum number of bytes to capture. If this value is less
137 than the size of a packet that is captured, only the first
138 .I snaplen
139 bytes of that packet will be captured and provided as packet data. A
140 value of 65535 should be sufficient, on most if not all networks, to
141 capture all the data available from the packet.
142 .I promisc
143 specifies if the interface is to be put into promiscuous mode.
144 (Note that even if this parameter is false, the interface
145 could well be in promiscuous mode for some other reason.) For now, this
146 doesn't work on the "any" device; if an argument of "any" or NULL is
147 supplied, the
148 .I promisc
149 flag is ignored.
150 .I to_ms
151 specifies the read timeout in milliseconds. The read timeout is used to
152 arrange that the read not necessarily return immediately when a packet
153 is seen, but that it wait for some amount of time to allow more packets
154 to arrive and to read multiple packets from the OS kernel in one
155 operation. Not all platforms support a read timeout; on platforms that
156 don't, the read timeout is ignored. A zero value for
157 .IR to_ms ,
158 on platforms that support a read timeout,
159 will cause a read to wait forever to allow enough packets to
160 arrive, with no timeout.
161 .I errbuf
162 is used to return error or warning text. It will be set to error text when
163 .B pcap_open_live()
164 fails and returns
165 .BR NULL .
166 .I errbuf
167 may also be set to warning text when
168 .B pcap_open_live()
169 succeds; to detect this case the caller should store a zero-length string in
170 .I errbuf
171 before calling
172 .B pcap_open_live()
173 and display the warning to the user if
174 .I errbuf
175 is no longer a zero-length string.
176 .PP
177 .B pcap_open_dead()
178 is used for creating a
179 .B pcap_t
180 structure to use when calling the other functions in libpcap. It is
181 typically used when just using libpcap for compiling BPF code.
182 .PP
183 .B pcap_open_offline()
184 is called to open a ``savefile'' for reading.
185 .I fname
186 specifies the name of the file to open. The file has
187 the same format as those used by
188 .B tcpdump(1)
189 and
190 .BR tcpslice(1) .
191 The name "-" in a synonym for
192 .BR stdin .
193 .I errbuf
194 is used to return error text and is only set when
195 .B pcap_open_offline()
196 fails and returns
197 .BR NULL .
198 .PP
199 .B pcap_dump_open()
200 is called to open a ``savefile'' for writing. The name "-" in a synonym
201 for
202 .BR stdout .
203 .B NULL
204 is returned on failure.
205 .I p
206 is a
207 .I pcap
208 struct as returned by
209 .B pcap_open_offline()
210 or
211 .BR pcap_open_live() .
212 .I fname
213 specifies the name of the file to open.
214 If
215 .B NULL
216 is returned,
217 .B pcap_geterr()
218 can be used to get the error text.
219 .PP
220 .B pcap_setnonblock()
221 puts a capture descriptor, opened with
222 .BR pcap_open_live() ,
223 into ``non-blocking'' mode, or takes it out of ``non-blocking'' mode,
224 depending on whether the
225 .I nonblock
226 argument is non-zero or zero. It has no effect on ``savefiles''.
227 If there is an error, \-1 is returned and
228 .I errbuf
229 is filled in with an appropriate error message; otherwise, 0 is
230 returned.
231 In
232 ``non-blocking'' mode, an attempt to read from the capture descriptor
233 with
234 .B pcap_dispatch()
235 will, if no packets are currently available to be read, return 0
236 immediately rather than blocking waiting for packets to arrive.
237 .B pcap_loop()
238 and
239 .B pcap_next()
240 will not work in ``non-blocking'' mode.
241 .PP
242 .B pcap_getnonblock()
243 returns the current ``non-blocking'' state of the capture descriptor; it
244 always returns 0 on ``savefiles''.
245 If there is an error, \-1 is returned and
246 .I errbuf
247 is filled in with an appropriate error message.
248 .PP
249 .B pcap_findalldevs()
250 constructs a list of network devices that can be opened with
251 .BR pcap_open_live() .
252 (Note that there may be network devices that cannot be opened with
253 .BR pcap_open_live()
254 by the
255 process calling
256 .BR pcap_findalldevs() ,
257 because, for example, that process might not have sufficient privileges
258 to open them for capturing; if so, those devices will not appear on the
259 list.)
260 .I alldevsp
261 is set to point to the first element of the list; each element of the
262 list is of type
263 .BR pcap_if_t ,
264 and has the following members:
265 .RS
266 .TP
267 .B next
268 if not
269 .BR NULL ,
270 a pointer to the next element in the list;
271 .B NULL
272 for the last element of the list
273 .TP
274 .B name
275 a pointer to a string giving a name for the device to pass to
276 .B pcap_open_live()
277 .TP
278 .B description
279 if not
280 .BR NULL ,
281 a pointer to a string giving a human-readable description of the device
282 .TP
283 .B addresses
284 a pointer to the first element of a list of addresses for the interface
285 .TP
286 .B flags
287 interface flags:
288 .RS
289 .TP
290 .B PCAP_IF_LOOPBACK
291 set if the interface is a loopback interface
292 .RE
293 .RE
294 .PP
295 Each element of the list of addresses is of type
296 .BR pcap_addr_t ,
297 and has the following members:
298 .RS
299 .TP
300 .B next
301 if not
302 .BR NULL ,
303 a pointer to the next element in the list;
304 .B NULL
305 for the last element of the list
306 .TP
307 .B addr
308 a pointer to a
309 .B "struct sockaddr"
310 containing an address
311 .TP
312 .B netmask
313 if not
314 .BR NULL ,
315 a pointer to a
316 .B "struct sockaddr"
317 that contains the netmask corresponding to the address pointed to by
318 .B addr
319 .TP
320 .B broadaddr
321 if not
322 .BR NULL ,
323 a pointer to a
324 .B "struct sockaddr"
325 that contains the broadcast address corresponding to the address pointed
326 to by
327 .BR addr ;
328 may be null if the interface doesn't support broadcasts
329 .TP
330 .B dstaddr
331 if not
332 .BR NULL ,
333 a pointer to a
334 .B "struct sockaddr"
335 that contains the destination address corresponding to the address pointed
336 to by
337 .BR addr ;
338 may be null if the interface isn't a point-to-point interface
339 .RE
340 .PP
341 .B pcap_freealldevs()
342 is used to free a list allocated by
343 .BR pcap_findalldevs() .
344 .PP
345 .B pcap_lookupdev()
346 returns a pointer to a network device suitable for use with
347 .B pcap_open_live()
348 and
349 .BR pcap_lookupnet() .
350 If there is an error,
351 .B NULL
352 is returned and
353 .I errbuf
354 is filled in with an appropriate error message.
355 .PP
356 .B pcap_lookupnet()
357 is used to determine the network number and mask
358 associated with the network device
359 .BR device .
360 Both
361 .I netp
362 and
363 .I maskp
364 are
365 .I bpf_u_int32
366 pointers.
367 A return of \-1 indicates an error in which case
368 .I errbuf
369 is filled in with an appropriate error message.
370 .PP
371 .B pcap_dispatch()
372 is used to collect and process packets.
373 .I cnt
374 specifies the maximum number of packets to process before returning.
375 This is not a minimum number; when reading a live capture, only one
376 bufferful of packets is read at a time, so fewer than
377 .I cnt
378 packets may be processed. A
379 .I cnt
380 of \-1 processes all the packets received in one buffer when reading a
381 live capture, or all the packets in the file when reading a
382 ``savefile''.
383 .I callback
384 specifies a routine to be called with three arguments:
385 a
386 .I u_char
387 pointer which is passed in from
388 .BR pcap_dispatch() ,
389 a
390 .I const struct pcap_pkthdr
391 pointer to a structure with the following members:
392 .RS
393 .TP
394 .B ts
395 a
396 .I struct timeval
397 containing the time when the packet was captured
398 .TP
399 .B caplen
400 a
401 .I bpf_u_int32
402 giving the number of bytes of the packet that are available from the
403 capture
404 .TP
405 .B len
406 a
407 .I bpf_u_int32
408 giving the length of the packet, in bytes (which might be more than the
409 number of bytes available from the capture, if the length of the packet
410 is larger than the maximum number of bytes to capture)
411 .RE
412 .PP
413 and a
414 .I const u_char
415 pointer to the first
416 .B caplen
417 (as given in the
418 .I struct pcap_pkthdr
419 a pointer to which is passed to the callback routine)
420 bytes of data from the packet (which won't necessarily be the entire
421 packet; to capture the entire packet, you will have to provide a value
422 for
423 .I snaplen
424 in your call to
425 .B pcap_open_live()
426 that is sufficiently large to get all of the packet's data - a value of
427 65535 should be sufficient on most if not all networks).
428 .PP
429 The number of packets read is returned.
430 0 is returned if no packets were read from a live capture (if, for
431 example, they were discarded because they didn't pass the packet filter,
432 or if, on platforms that support a read timeout that starts before any
433 packets arrive, the timeout expires before any packets arrive, or if the
434 file descriptor for the capture device is in non-blocking mode and no
435 packets were available to be read) or if no more packets are available
436 in a ``savefile.'' A return of \-1 indicates
437 an error in which case
438 .B pcap_perror()
439 or
440 .B pcap_geterr()
441 may be used to display the error text.
442 .PP
443 .BR NOTE :
444 when reading a live capture,
445 .B pcap_dispatch()
446 will not necessarily return when the read times out; on some platforms,
447 the read timeout isn't supported, and, on other platforms, the timer
448 doesn't start until at least one packet arrives. This means that the
449 read timeout should
450 .B NOT
451 be used in, for example, an interactive application, to allow the packet
452 capture loop to ``poll'' for user input periodically, as there's no
453 guarantee that
454 .B pcap_dispatch()
455 will return after the timeout expires.
456 .PP
457 .B pcap_loop()
458 is similar to
459 .B pcap_dispatch()
460 except it keeps reading packets until
461 .I cnt
462 packets are processed or an error occurs.
463 It does
464 .B not
465 return when live read timeouts occur.
466 Rather, specifying a non-zero read timeout to
467 .B pcap_open_live()
468 and then calling
469 .B pcap_dispatch()
470 allows the reception and processing of any packets that arrive when the
471 timeout occurs.
472 A negative
473 .I cnt
474 causes
475 .B pcap_loop()
476 to loop forever (or at least until an error occurs). A negative number
477 is returned on an error; 0 is returned if
478 .I cnt
479 is exhausted.
480 .PP
481 .B pcap_next()
482 reads the next packet (by calling
483 .B pcap_dispatch()
484 with a
485 .I cnt
486 of 1) and returns a
487 .I u_char
488 pointer to the data in that packet. (The
489 .I pcap_pkthdr
490 struct for that packet is not supplied.)
491 .B NULL
492 is returned if an error occured, or if no packets were read from a live
493 capture (if, for example, they were discarded because they didn't pass
494 the packet filter, or if, on platforms that support a read timeout that
495 starts before any packets arrive, the timeout expires before any packets
496 arrive, or if the file descriptor for the capture device is in
497 non-blocking mode and no packets were available to be read), or if no
498 more packets are available in a ``savefile.'' Unfortunately, there is
499 no way to determine whether an error occured or not.
500 .PP
501 .B pcap_dump()
502 outputs a packet to the ``savefile'' opened with
503 .BR pcap_dump_open() .
504 Note that its calling arguments are suitable for use with
505 .B pcap_dispatch()
506 or
507 .BR pcap_loop() .
508 If called directly, the
509 .I user
510 parameter is of type
511 .I pcap_dumper_t
512 as returned by
513 .BR pcap_dump_open() .
514 .PP
515 .B pcap_compile()
516 is used to compile the string
517 .I str
518 into a filter program.
519 .I program
520 is a pointer to a
521 .I bpf_program
522 struct and is filled in by
523 .BR pcap_compile() .
524 .I optimize
525 controls whether optimization on the resulting code is performed.
526 .I netmask
527 specifies the IPv4 netmask of the network on which packets are being
528 captured; it is used only when checking for IPv4 broadcast addresses in
529 the filter program. If the netmask of the network on which packets are
530 being captured isn't known to the program, or if packets are being
531 captured on the Linux "any" pseudo-interface that can capture on more
532 than one network, a value of 0 can be supplied; tests for IPv4 broadcast
533 addreses won't be done correctly, but all other tests in the filter
534 program will be OK. A return of \-1 indicates an error in which case
535 .BR pcap_geterr()
536 may be used to display the error text.
537 .PP
538 .B pcap_compile_nopcap()
539 is similar to
540 .B pcap_compile()
541 except that instead of passing a pcap structure, one passes the
542 snaplen and linktype explicitly. It is intended to be used for
543 compiling filters for direct BPF usage, without necessarily having
544 called
545 .BR pcap_open() .
546 A return of \-1 indicates an error; the error text is unavailable.
547 .RB ( pcap_compile_nopcap()
548 is a wrapper around
549 .BR pcap_open_dead() ,
550 .BR pcap_compile() ,
551 and
552 .BR pcap_close() ;
553 the latter three routines can be used directly in order to get the error
554 text for a compilation error.)
555 .B
556 .PP
557 .B pcap_setfilter()
558 is used to specify a filter program.
559 .I fp
560 is a pointer to a
561 .I bpf_program
562 struct, usually the result of a call to
563 .BR pcap_compile() .
564 .B \-1
565 is returned on failure, in which case
566 .BR pcap_geterr()
567 may be used to display the error text;
568 .B 0
569 is returned on success.
570 .PP
571 .B pcap_freecode()
572 is used to free up allocated memory pointed to by a
573 .I bpf_program
574 struct generated by
575 .B pcap_compile()
576 when that BPF program is no longer needed, for example after it
577 has been made the filter program for a pcap structure by a call to
578 .BR pcap_setfilter() .
579 .PP
580 .B pcap_datalink()
581 returns the link layer type; link layer types it can return include:
582 .PP
583 .RS 5
584 .TP 5
585 .B DLT_NULL
586 BSD loopback encapsulation; the link layer header is a 4-byte field, in
587 .I host
588 byte order, containing a PF_ value from
589 .B socket.h
590 for the network-layer protocol of the packet
591 .IP
592 Note that ``host byte order'' is the byte order of the machine on which
593 the packets are captured, and the PF_ values are for the OS of the
594 machine on which the packets are captured; if a live capture is being
595 done, ``host byte order'' is the byte order of the machine capturing the
596 packets, and the PF_ values are those of the OS of the machine capturing
597 the packets, but if a ``savefile'' is being read, the byte order and PF_
598 values are
599 .I not
600 necessarily those of the machine reading the capture file.
601 .TP 5
602 .B DLT_EN10MB
603 Ethernet (10Mb, 100Mb, 1000Mb, and up)
604 .TP 5
605 .B DLT_IEEE802
606 IEEE 802.5 Token Ring
607 .TP 5
608 .B DLT_ARCNET
609 ARCNET
610 .TP 5
611 .B DLT_SLIP
612 SLIP; the link layer header contains, in order:
613 .RS 10
614 .LP
615 a 1-byte flag, which is 0 for packets received by the machine and 1 for
616 packets sent by the machine;
617 .LP
618 a 1-byte field, the upper 4 bits of which indicate the type of packet,
619 as per RFC 1144:
620 .RS 5
621 .TP 5
622 0x40
623 an unmodified IP datagram (TYPE_IP);
624 .TP 5
625 0x70
626 an uncompressed-TCP IP datagram (UNCOMPRESSED_TCP), with that byte being
627 the first byte of the raw IP header on the wire, containing the
628 connection number in the protocol field;
629 .TP 5
630 0x80
631 a compressed-TCP IP datagram (COMPRESSED_TCP), with that byte being the
632 first byte of the compressed TCP/IP datagram header;
633 .RE
634 .LP
635 for UNCOMPRESSED_TCP, the rest of the modified IP header, and for
636 COMPRESSED_TCP, the compressed TCP/IP datagram header;
637 .RE
638 .RS 5
639 .LP
640 for a total of 16 bytes; the uncompressed IP datagram follows the header
641 .RE
642 .TP 5
643 .B DLT_PPP
644 PPP; if the first 2 bytes are 0xff and 0x03, it's PPP in HDLC-like
645 framing, with the PPP header following those two bytes, otherwise it's
646 PPP without framing, and the packet begins with the PPP header
647 .TP 5
648 .B DLT_FDDI
649 FDDI
650 .TP 5
651 .B DLT_ATM_RFC1483
652 RFC 1483 LLC/SNAP-encapsulated ATM; the packet begins with an IEEE 802.2
653 LLC header
654 .TP 5
655 .B DLT_RAW
656 raw IP; the packet begins with an IP header
657 .TP 5
658 .B DLT_PPP_SERIAL
659 PPP in HDLC-like framing, as per RFC 1662, or Cisco PPP with HDLC
660 framing, as per section 4.3.1 of RFC 1547; the first byte will be 0xFF
661 for PPP in HDLC-like framing, and will be 0x0F or 0x8F for Cisco PPP
662 with HDLC framing
663 .TP 5
664 .B DLT_PPP_ETHER
665 PPPoE; the packet begins with a PPPoE header, as per RFC 2516
666 .TP 5
667 .B DLT_C_HDLC
668 Cisco PPP with HDLC framing, as per section 4.3.1 of RFC 1547
669 .TP 5
670 .B DLT_IEEE802_11
671 IEEE 802.11 wireless LAN
672 .TP 5
673 .B DLT_FRELAY
674 Frame Relay
675 .TP 5
676 .B DLT_LOOP
677 OpenBSD loopback encapsulation; the link layer header is a 4-byte field, in
678 .I network
679 byte order, containing a PF_ value from OpenBSD's
680 .B socket.h
681 for the network-layer protocol of the packet
682 .IP
683 Note that, if a ``savefile'' is being read, those PF_ values are
684 .I not
685 necessarily those of the machine reading the capture file.
686 .TP 5
687 .B DLT_LINUX_SLL
688 Linux "cooked" capture encapsulation; the link layer header contains, in
689 order:
690 .RS 10
691 .LP
692 a 2-byte "packet type", in network byte order, which is one of:
693 .RS 5
694 .TP 5
695 0
696 packet was sent to us by somebody else
697 .TP 5
698 1
699 packet was broadcast by somebody else
700 .TP 5
701 2
702 packet was multicast, but not broadcast, by somebody else
703 .TP 5
704 3
705 packet was sent by somebody else to somebody else
706 .TP 5
707 4
708 packet was sent by us
709 .RE
710 .LP
711 a 2-byte field, in network byte order, containing a Linux ARPHRD_ value
712 for the link layer device type;
713 .LP
714 a 2-byte field, in network byte order, containing the length of the
715 link layer address of the sender of the packet (which could be 0);
716 .LP
717 an 8-byte field containing that number of bytes of the link layer header
718 (if there are more than 8 bytes, only the first 8 are present);
719 .LP
720 a 2-byte field containing an Ethernet protocol type, in network byte
721 order, or containing 1 for Novell 802.3 frames without an 802.2 LLC
722 header or 4 for frames beginning with an 802.2 LLC header.
723 .RE
724 .TP 5
725 .B DLT_LTALK
726 Apple LocalTalk; the packet begins with an AppleTalk LLAP header
727 .TP 5
728 .B DLT_SUNATM
729 SunATM devices; the link layer header contains, in order:
730 .RS 10
731 .LP
732 a 1-byte flag field, containing a direction flag in the uppermost bit,
733 which is set for packets transmitted by the machine and clear for
734 packets received by the machine, and a 4-byte traffic type in the
735 low-order 4 bits, which is one of:
736 .RS 5
737 .TP 5
738 0
739 raw traffic
740 .TP 5
741 1
742 LANE traffic
743 .TP 5
744 2
745 LLC-encapsulated traffic
746 .TP 5
747 3
748 MARS traffic
749 .TP 5
750 4
751 IFMP traffic
752 .TP 5
753 5
754 ILMI traffic
755 .TP 5
756 6
757 Q.2931 traffic
758 .RE
759 .LP
760 a 1-byte VPI value;
761 .LP
762 a 2-byte VCI field, in network byte order.
763 .RE
764 .TP 5
765 .B DLT_IP_OVER_FC
766 RFC 2625 IP-over-Fibre Channel, with the link-layer header being the
767 Network_Header as described in that RFC.
768 .PP
769 .B pcap_snapshot()
770 returns the snapshot length specified when
771 .B pcap_open_live
772 was called.
773 .PP
774 .B pcap_is_swapped()
775 returns true if the current ``savefile'' uses a different byte order
776 than the current system.
777 .PP
778 .B pcap_major_version()
779 returns the major number of the version of the pcap used to write the
780 savefile.
781 .PP
782 .B pcap_minor_version()
783 returns the minor number of the version of the pcap used to write the
784 savefile.
785 .PP
786 .B pcap_file()
787 returns the standard I/O stream of the ``savefile,'' if a ``savefile''
788 was opened with
789 .BR pcap_open_offline() ,
790 or NULL, if a network device was opened with
791 .BR pcap_open_live() .
792 .PP
793 .B pcap_stats()
794 returns 0 and fills in a
795 .B pcap_stat
796 struct. The values represent packet statistics from the start of the
797 run to the time of the call. If there is an error or the underlying
798 packet capture doesn't support packet statistics, \-1 is returned and
799 the error text can be obtained with
800 .B pcap_perror()
801 or
802 .BR pcap_geterr() .
803 .B pcap_stats()
804 is supported only on live captures, not on ``savefiles''; no statistics
805 are stored in ``savefiles'', so no statistics are available when reading
806 from a ``savefile''.
807 .PP
808 .B pcap_fileno()
809 returns the file descriptor number from which captured packets are read,
810 if a network device was opened with
811 .BR pcap_open_live() ,
812 or \-1, if a ``savefile'' was opened with
813 .BR pcap_open_offline() .
814 .PP
815 .B pcap_perror()
816 prints the text of the last pcap library error on
817 .BR stderr ,
818 prefixed by
819 .IR prefix .
820 .PP
821 .B pcap_geterr()
822 returns the error text pertaining to the last pcap library error.
823 .BR NOTE :
824 the pointer it returns will no longer point to a valid error message
825 string after the
826 .B pcap_t
827 passed to it is closed; you must use or copy the string before closing
828 the
829 .BR pcap_t .
830 .PP
831 .B pcap_strerror()
832 is provided in case
833 .BR strerror (1)
834 isn't available.
835 .PP
836 .B pcap_close()
837 closes the files associated with
838 .I p
839 and deallocates resources.
840 .PP
841 .B pcap_dump_close()
842 closes the ``savefile.''
843 .PP
844 .SH SEE ALSO
845 tcpdump(1), tcpslice(1)
846 .SH AUTHORS
847 The original authors are:
848 .LP
849 Van Jacobson,
850 Craig Leres and
851 Steven McCanne, all of the
852 Lawrence Berkeley National Laboratory, University of California, Berkeley, CA.
853 .LP
854 The current version is available from "The Tcpdump Group"'s Web site at
855 .LP
856 .RS
857 .I http://www.tcpdump.org/
858 .RE
859 .SH BUGS
860 Please send problems, bugs, questions, desirable enhancements, etc. to:
861 .LP
862 .RS
863 tcpdump-workers@tcpdump.org
864 .RE
865 .LP
866 Please send source code contributions, etc. to:
867 .LP
868 .RS
869 patches@tcpdump.org
870 .RE