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