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