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