2 * pcap-dag.c: Packet capture interface for Endace DAG card.
4 * The functionality of this code attempts to mimic that of pcap-linux as much
5 * as possible. This code is compiled in several different ways depending on
6 * whether DAG_ONLY and HAVE_DAG_API are defined. If HAVE_DAG_API is not
7 * defined it should not get compiled in, otherwise if DAG_ONLY is defined then
8 * the 'dag_' function calls are renamed to 'pcap_' equivalents. If DAG_ONLY
9 * is not defined then nothing is altered - the dag_ functions will be
10 * called as required from their pcap-linux/bpf equivalents.
12 * Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
13 * Modifications: Jesper Peterson <support@endace.com>
14 * Koryn Grant <support@endace.com>
15 * Stephen Donnelly <support@endace.com>
19 static const char rcsid
[] _U_
=
20 "@(#) $Header: /pub/NetBSD/misc/repositories/cvsroot/src/dist/libpcap/pcap-dag.c,v 1.1.1.1 2006/02/27 15:45:47 drochner Exp $ (LBL)";
27 #include <sys/param.h> /* optionally get BSD define */
36 #include <netinet/in.h>
38 #include <sys/socket.h>
39 #include <sys/types.h>
42 struct mbuf
; /* Squelch compiler warnings on some platforms for */
43 struct rtentry
; /* declarations in <net/if.h> */
49 #define MIN_DAG_SNAPLEN 12
50 #define MAX_DAG_SNAPLEN 2040
51 #define ATM_CELL_SIZE 52
52 #define ATM_HDR_SIZE 4
54 /* SunATM pseudo header */
56 unsigned char flags
; /* destination and traffic type */
57 unsigned char vpi
; /* VPI */
58 unsigned short vci
; /* VCI */
61 typedef struct pcap_dag_node
{
62 struct pcap_dag_node
*next
;
67 static pcap_dag_node_t
*pcap_dags
= NULL
;
68 static int atexit_handler_installed
= 0;
69 static const unsigned short endian_test_word
= 0x0100;
71 #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word))
74 * Swap byte ordering of unsigned long long timestamp on a big endian
77 #define SWAP_TS(ull) ((ull & 0xff00000000000000LL) >> 56) | \
78 ((ull & 0x00ff000000000000LL) >> 40) | \
79 ((ull & 0x0000ff0000000000LL) >> 24) | \
80 ((ull & 0x000000ff00000000LL) >> 8) | \
81 ((ull & 0x00000000ff000000LL) << 8) | \
82 ((ull & 0x0000000000ff0000LL) << 24) | \
83 ((ull & 0x000000000000ff00LL) << 40) | \
84 ((ull & 0x00000000000000ffLL) << 56)
88 /* This code is required when compiling for a DAG device only. */
91 /* Replace dag function names with pcap equivalent. */
92 #define dag_open_live pcap_open_live
93 #define dag_platform_finddevs pcap_platform_finddevs
96 static int dag_setfilter(pcap_t
*p
, struct bpf_program
*fp
);
97 static int dag_stats(pcap_t
*p
, struct pcap_stat
*ps
);
98 static int dag_set_datalink(pcap_t
*p
, int dlt
);
99 static int dag_get_datalink(pcap_t
*p
);
100 static int dag_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
);
103 delete_pcap_dag(pcap_t
*p
)
105 pcap_dag_node_t
*curr
= NULL
, *prev
= NULL
;
107 for (prev
= NULL
, curr
= pcap_dags
; curr
!= NULL
&& curr
->p
!= p
; prev
= curr
, curr
= curr
->next
) {
111 if (curr
!= NULL
&& curr
->p
== p
) {
113 prev
->next
= curr
->next
;
115 pcap_dags
= curr
->next
;
121 * Performs a graceful shutdown of the DAG card, frees dynamic memory held
122 * in the pcap_t structure, and closes the file descriptor for the DAG card.
126 dag_platform_close(pcap_t
*p
)
130 #ifdef HAVE_DAG_STREAMS_API
131 if(dag_stop_stream(p
->fd
, p
->md
.dag_stream
) < 0)
132 fprintf(stderr
,"dag_stop_stream: %s\n", strerror(errno
));
134 if(dag_detach_stream(p
->fd
, p
->md
.dag_stream
) < 0)
135 fprintf(stderr
,"dag_detach_stream: %s\n", strerror(errno
));
137 if(dag_stop(p
->fd
) < 0)
138 fprintf(stderr
,"dag_stop: %s\n", strerror(errno
));
139 #endif /* HAVE_DAG_STREAMS_API */
140 if(dag_close(p
->fd
) < 0)
141 fprintf(stderr
,"dag_close: %s\n", strerror(errno
));
147 /* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
153 while (pcap_dags
!= NULL
) {
154 if (pcap_dags
->pid
== getpid()) {
155 dag_platform_close(pcap_dags
->p
);
157 delete_pcap_dag(pcap_dags
->p
);
163 new_pcap_dag(pcap_t
*p
)
165 pcap_dag_node_t
*node
= NULL
;
167 if ((node
= malloc(sizeof(pcap_dag_node_t
))) == NULL
) {
171 if (!atexit_handler_installed
) {
172 atexit(atexit_handler
);
173 atexit_handler_installed
= 1;
176 node
->next
= pcap_dags
;
178 node
->pid
= getpid();
186 * Read at most max_packets from the capture stream and call the callback
187 * for each of them. Returns the number of packets handled, -1 if an
188 * error occured, or -2 if we were told to break out of the loop.
191 dag_read(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
193 unsigned int processed
= 0;
194 int flags
= p
->md
.dag_offset_flags
;
195 unsigned int nonblocking
= flags
& DAGF_NONBLOCK
;
197 /* Get the next bufferful of packets (if necessary). */
198 while (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
) {
201 * Has "pcap_breakloop()" been called?
205 * Yes - clear the flag that indicates that
206 * it has, and return -2 to indicate that
207 * we were told to break out of the loop.
213 #ifdef HAVE_DAG_STREAMS_API
214 /* dag_advance_stream() will block (unless nonblock is called)
215 * until 64kB of data has accumulated.
216 * If to_ms is set, it will timeout before 64kB has accumulated.
217 * We wait for 64kB because processing a few packets at a time
218 * can cause problems at high packet rates (>200kpps) due
220 * This does mean if to_ms is not specified the capture may 'hang'
221 * for long periods if the data rate is extremely slow (<64kB/sec)
222 * If non-block is specified it will return immediately. The user
223 * is then responsible for efficiency.
225 p
->md
.dag_mem_top
= dag_advance_stream(p
->fd
, p
->md
.dag_stream
, (void**)&(p
->md
.dag_mem_bottom
));
227 /* dag_offset does not support timeouts */
228 p
->md
.dag_mem_top
= dag_offset(p
->fd
, &(p
->md
.dag_mem_bottom
), flags
);
229 #endif /* HAVE_DAG_STREAMS_API */
231 if (nonblocking
&& (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
))
233 /* Pcap is configured to process only available packets, and there aren't any, return immediately. */
239 (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
))
241 /* Blocking mode, but timeout set and no data has arrived, return anyway.*/
247 /* Process the packets. */
248 while (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
>= dag_record_size
) {
250 unsigned short packet_len
= 0;
252 struct pcap_pkthdr pcap_header
;
254 #ifdef HAVE_DAG_STREAMS_API
255 dag_record_t
*header
= (dag_record_t
*)(p
->md
.dag_mem_bottom
);
257 dag_record_t
*header
= (dag_record_t
*)(p
->md
.dag_mem_base
+ p
->md
.dag_mem_bottom
);
258 #endif /* HAVE_DAG_STREAMS_API */
260 u_char
*dp
= ((u_char
*)header
) + dag_record_size
;
264 * Has "pcap_breakloop()" been called?
268 * Yes - clear the flag that indicates that
269 * it has, and return -2 to indicate that
270 * we were told to break out of the loop.
276 rlen
= ntohs(header
->rlen
);
277 if (rlen
< dag_record_size
)
279 strncpy(p
->errbuf
, "dag_read: record too small", PCAP_ERRBUF_SIZE
);
282 p
->md
.dag_mem_bottom
+= rlen
;
284 switch(header
->type
) {
289 if (header
->type
== TYPE_MC_ATM
) {
290 caplen
= packet_len
= ATM_CELL_SIZE
;
296 if (header
->type
== TYPE_MC_AAL5
) {
297 packet_len
= ntohs(header
->wlen
);
298 caplen
= rlen
- dag_record_size
- 4;
302 if (header
->type
== TYPE_AAL5
) {
303 packet_len
= ntohs(header
->wlen
);
304 caplen
= rlen
- dag_record_size
;
305 } else if(header
->type
== TYPE_ATM
) {
306 caplen
= packet_len
= ATM_CELL_SIZE
;
308 if (p
->linktype
== DLT_SUNATM
) {
309 struct sunatm_hdr
*sunatm
= (struct sunatm_hdr
*)dp
;
310 unsigned long rawatm
;
312 rawatm
= ntohl(*((unsigned long *)dp
));
313 sunatm
->vci
= htons((rawatm
>> 4) & 0xffff);
314 sunatm
->vpi
= (rawatm
>> 20) & 0x00ff;
315 sunatm
->flags
= ((header
->flags
.iface
& 1) ? 0x80 : 0x00) |
316 ((sunatm
->vpi
== 0 && sunatm
->vci
== htons(5)) ? 6 :
317 ((sunatm
->vpi
== 0 && sunatm
->vci
== htons(16)) ? 5 :
318 ((dp
[ATM_HDR_SIZE
] == 0xaa &&
319 dp
[ATM_HDR_SIZE
+1] == 0xaa &&
320 dp
[ATM_HDR_SIZE
+2] == 0x03) ? 2 : 1)));
323 packet_len
-= ATM_HDR_SIZE
;
324 caplen
-= ATM_HDR_SIZE
;
329 #ifdef TYPE_COLOR_ETH
333 packet_len
= ntohs(header
->wlen
);
334 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
335 caplen
= rlen
- dag_record_size
- 2;
336 if (caplen
> packet_len
) {
341 #ifdef TYPE_COLOR_HDLC_POS
342 case TYPE_COLOR_HDLC_POS
:
345 packet_len
= ntohs(header
->wlen
);
346 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
347 caplen
= rlen
- dag_record_size
;
348 if (caplen
> packet_len
) {
354 packet_len
= ntohs(header
->wlen
);
355 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
356 caplen
= rlen
- dag_record_size
- 4;
357 if (caplen
> packet_len
) {
365 if (caplen
> p
->snapshot
)
366 caplen
= p
->snapshot
;
368 /* Count lost packets. */
369 switch(header
->type
) {
370 #ifdef TYPE_COLOR_HDLC_POS
371 /* in this type the color value overwrites the lctr */
372 case TYPE_COLOR_HDLC_POS
:
375 #ifdef TYPE_COLOR_ETH
376 /* in this type the color value overwrites the lctr */
382 if (p
->md
.stat
.ps_drop
> (UINT_MAX
- ntohs(header
->lctr
))) {
383 p
->md
.stat
.ps_drop
= UINT_MAX
;
385 p
->md
.stat
.ps_drop
+= ntohs(header
->lctr
);
390 /* Run the packet filter if there is one. */
391 if ((p
->fcode
.bf_insns
== NULL
) || bpf_filter(p
->fcode
.bf_insns
, dp
, packet_len
, caplen
)) {
393 /* convert between timestamp formats */
394 register unsigned long long ts
;
396 if (IS_BIGENDIAN()) {
397 ts
= SWAP_TS(header
->ts
);
402 pcap_header
.ts
.tv_sec
= ts
>> 32;
403 ts
= (ts
& 0xffffffffULL
) * 1000000;
404 ts
+= 0x80000000; /* rounding */
405 pcap_header
.ts
.tv_usec
= ts
>> 32;
406 if (pcap_header
.ts
.tv_usec
>= 1000000) {
407 pcap_header
.ts
.tv_usec
-= 1000000;
408 pcap_header
.ts
.tv_sec
++;
411 /* Fill in our own header data */
412 pcap_header
.caplen
= caplen
;
413 pcap_header
.len
= packet_len
;
415 /* Count the packet. */
416 p
->md
.stat
.ps_recv
++;
418 /* Call the user supplied callback function */
419 callback(user
, &pcap_header
, dp
);
421 /* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
423 if (processed
== cnt
)
425 /* Reached the user-specified limit. */
435 dag_inject(pcap_t
*p
, const void *buf _U_
, size_t size _U_
)
437 strlcpy(p
->errbuf
, "Sending packets isn't supported on DAG cards",
443 * Get a handle for a live capture from the given DAG device. Passing a NULL
444 * device will result in a failure. The promisc flag is ignored because DAG
445 * cards are always promiscuous. The to_ms parameter is also ignored as it is
446 * not supported in hardware.
451 dag_open_live(const char *device
, int snaplen
, int promisc
, int to_ms
, char *ebuf
)
453 char conf
[30]; /* dag configure string */
459 #ifdef HAVE_DAG_STREAMS_API
461 struct timeval maxwait
;
465 if (device
== NULL
) {
466 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "device is NULL: %s", pcap_strerror(errno
));
469 /* Allocate a handle for this session. */
471 handle
= malloc(sizeof(*handle
));
472 if (handle
== NULL
) {
473 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "malloc %s: %s", device
, pcap_strerror(errno
));
477 /* Initialize some components of the pcap structure. */
479 memset(handle
, 0, sizeof(*handle
));
481 newDev
= (char *)malloc(strlen(device
) + 16);
483 #ifdef HAVE_DAG_STREAMS_API
485 /* Parse input name to get dag device and stream number if provided */
486 if (dag_parse_name(device
, newDev
, strlen(device
) + 16, &handle
->md
.dag_stream
) < 0) {
487 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_parse_name: %s\n", pcap_strerror(errno
));
492 if (handle
->md
.dag_stream
%2) {
493 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_parse_name: tx (even numbered) streams not supported for capture\n");
497 if (strstr(device
, "/dev") == NULL
) {
499 strcat(newDev
, "/dev/");
500 strcat(newDev
,device
);
503 device
= strdup(device
);
506 if (device
== NULL
) {
507 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "str_dup: %s\n", pcap_strerror(errno
));
510 #endif /* HAVE_DAG_STREAMS_API */
512 /* setup device parameters */
513 if((handle
->fd
= dag_open((char *)device
)) < 0) {
514 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_open %s: %s", device
, pcap_strerror(errno
));
518 #ifdef HAVE_DAG_STREAMS_API
519 /* Open requested stream. Can fail if already locked or on error */
520 if (dag_attach_stream(handle
->fd
, handle
->md
.dag_stream
, 0, 0) < 0) {
521 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_attach_stream: %s\n", pcap_strerror(errno
));
525 /* Set up default poll parameters for stream
526 * Can be overridden by pcap_set_nonblock()
528 if (dag_get_stream_poll(handle
->fd
, handle
->md
.dag_stream
,
529 &mindata
, &maxwait
, &poll
) < 0) {
530 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_get_stream_poll: %s\n", pcap_strerror(errno
));
534 /* Amount of data to collect in Bytes before calling callbacks.
535 * Important for efficiency, but can introduce latency
536 * at low packet rates if to_ms not set!
540 /* Obey to_ms if supplied. This is a good idea!
541 * Recommend 10-100ms. Calls will time out even if no data arrived.
543 maxwait
.tv_sec
= to_ms
/1000;
544 maxwait
.tv_usec
= (to_ms
%1000) * 1000;
546 if (dag_set_stream_poll(handle
->fd
, handle
->md
.dag_stream
,
547 mindata
, &maxwait
, &poll
) < 0) {
548 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_set_stream_poll: %s\n", pcap_strerror(errno
));
553 if((handle
->md
.dag_mem_base
= dag_mmap(handle
->fd
)) == MAP_FAILED
) {
554 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,"dag_mmap %s: %s\n", device
, pcap_strerror(errno
));
558 #endif /* HAVE_DAG_STREAMS_API */
560 /* set the card snap length to the specified snaplen parameter */
561 if (snaplen
== 0 || snaplen
> MAX_DAG_SNAPLEN
) {
562 snaplen
= MAX_DAG_SNAPLEN
;
563 } else if (snaplen
< MIN_DAG_SNAPLEN
) {
564 snaplen
= MIN_DAG_SNAPLEN
;
566 /* snap len has to be a multiple of 4 */
567 snprintf(conf
, 30, "varlen slen=%d", (snaplen
+ 3) & ~3);
569 if(dag_configure(handle
->fd
, conf
) < 0) {
570 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,"dag_configure %s: %s\n", device
, pcap_strerror(errno
));
574 #ifdef HAVE_DAG_STREAMS_API
575 if(dag_start_stream(handle
->fd
, handle
->md
.dag_stream
) < 0) {
576 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_start_stream %s: %s\n", device
, pcap_strerror(errno
));
580 if(dag_start(handle
->fd
) < 0) {
581 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_start %s: %s\n", device
, pcap_strerror(errno
));
584 #endif /* HAVE_DAG_STREAMS_API */
587 * Important! You have to ensure bottom is properly
588 * initialized to zero on startup, it won't give you
589 * a compiler warning if you make this mistake!
591 handle
->md
.dag_mem_bottom
= 0;
592 handle
->md
.dag_mem_top
= 0;
593 handle
->md
.dag_fcs_bits
= 32;
595 /* Query the card first for special cases. */
596 daginf
= dag_info(handle
->fd
);
597 if ((0x4200 == daginf
->device_code
) || (0x4230 == daginf
->device_code
))
599 /* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
600 handle
->md
.dag_fcs_bits
= 0;
603 /* Then allow an environment variable to override. */
604 if ((s
= getenv("ERF_FCS_BITS")) != NULL
) {
605 if ((n
= atoi(s
)) == 0 || n
== 16|| n
== 32) {
606 handle
->md
.dag_fcs_bits
= n
;
608 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
609 "pcap_open_live %s: bad ERF_FCS_BITS value (%d) in environment\n", device
, n
);
614 handle
->snapshot
= snaplen
;
615 handle
->md
.dag_timeout
= to_ms
;
617 handle
->linktype
= -1;
618 if (dag_get_datalink(handle
) < 0) {
619 strcpy(ebuf
, handle
->errbuf
);
625 if (new_pcap_dag(handle
) < 0) {
626 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "new_pcap_dag %s: %s\n", device
, pcap_strerror(errno
));
631 * "select()" and "poll()" don't work on DAG device descriptors.
633 handle
->selectable_fd
= -1;
636 handle
->md
.device
= (char *)device
;
637 handle
->md
.timeout
= to_ms
;
639 free((char *)device
);
643 handle
->read_op
= dag_read
;
644 handle
->inject_op
= dag_inject
;
645 handle
->setfilter_op
= dag_setfilter
;
646 handle
->setdirection_op
= NULL
; /* Not implemented.*/
647 handle
->set_datalink_op
= dag_set_datalink
;
648 handle
->getnonblock_op
= pcap_getnonblock_fd
;
649 handle
->setnonblock_op
= dag_setnonblock
;
650 handle
->stats_op
= dag_stats
;
651 handle
->close_op
= dag_platform_close
;
656 if (newDev
!= NULL
) {
657 free((char *)newDev
);
659 if (handle
!= NULL
) {
661 * Get rid of any link-layer type list we allocated.
663 if (handle
->dlt_list
!= NULL
) {
664 free(handle
->dlt_list
);
673 dag_stats(pcap_t
*p
, struct pcap_stat
*ps
) {
674 /* This needs to be filled out correctly. Hopefully a dagapi call will
675 provide all necessary information.
677 /*p->md.stat.ps_recv = 0;*/
678 /*p->md.stat.ps_drop = 0;*/
686 * Simply submit all possible dag names as candidates.
687 * pcap_add_if() internally tests each candidate with pcap_open_live(),
688 * so any non-existent devices are dropped.
689 * For 2.5 try all rx stream names as well.
692 dag_platform_finddevs(pcap_if_t
**devlistp
, char *errbuf
)
694 char name
[12]; /* XXX - pick a size */
698 /* Try all the DAGs 0-9 */
699 for (c
= 0; c
< 9; c
++) {
700 snprintf(name
, 12, "dag%d", c
);
701 if (pcap_add_if(devlistp
, name
, 0, NULL
, errbuf
) == -1) {
707 #ifdef HAVE_DAG_STREAMS_API
710 for(stream
=0;stream
<16;stream
+=2) {
711 snprintf(name
, 10, "dag%d:%d", c
, stream
);
712 if (pcap_add_if(devlistp
, name
, 0, NULL
, errbuf
) == -1) {
720 #endif /* HAVE_DAG_STREAMS_API */
726 * Installs the given bpf filter program in the given pcap structure. There is
727 * no attempt to store the filter in kernel memory as that is not supported
731 dag_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
736 strncpy(p
->errbuf
, "setfilter: No filter specified",
741 /* Make our private copy of the filter */
743 if (install_bpf_program(p
, fp
) < 0)
752 dag_set_datalink(pcap_t
*p
, int dlt
)
760 dag_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
)
763 * Set non-blocking mode on the FD.
764 * XXX - is that necessary? If not, don't bother calling it,
765 * and have a "dag_getnonblock()" function that looks at
766 * "p->md.dag_offset_flags".
768 if (pcap_setnonblock_fd(p
, nonblock
, errbuf
) < 0)
770 #ifdef HAVE_DAG_STREAMS_API
773 struct timeval maxwait
;
776 if (dag_get_stream_poll(p
->fd
, p
->md
.dag_stream
,
777 &mindata
, &maxwait
, &poll
) < 0) {
778 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "dag_get_stream_poll: %s\n", pcap_strerror(errno
));
782 /* Amount of data to collect in Bytes before calling callbacks.
783 * Important for efficiency, but can introduce latency
784 * at low packet rates if to_ms not set!
791 if (dag_set_stream_poll(p
->fd
, p
->md
.dag_stream
,
792 mindata
, &maxwait
, &poll
) < 0) {
793 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "dag_set_stream_poll: %s\n", pcap_strerror(errno
));
797 #endif /* HAVE_DAG_STREAMS_API */
799 p
->md
.dag_offset_flags
|= DAGF_NONBLOCK
;
801 p
->md
.dag_offset_flags
&= ~DAGF_NONBLOCK
;
807 dag_get_datalink(pcap_t
*p
)
811 if (p
->dlt_list
== NULL
&& (p
->dlt_list
= malloc(2*sizeof(*(p
->dlt_list
)))) == NULL
) {
812 (void)snprintf(p
->errbuf
, sizeof(p
->errbuf
), "malloc: %s", pcap_strerror(errno
));
816 /* Check the type through a dagapi call. */
817 daglinktype
= dag_linktype(p
->fd
);
819 switch(daglinktype
) {
822 case TYPE_COLOR_HDLC_POS
:
823 if (p
->dlt_list
!= NULL
) {
825 p
->dlt_list
[0] = DLT_CHDLC
;
826 p
->dlt_list
[1] = DLT_PPP_SERIAL
;
827 p
->dlt_list
[2] = DLT_FRELAY
;
829 p
->linktype
= DLT_CHDLC
;
835 * This is (presumably) a real Ethernet capture; give it a
836 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
837 * that an application can let you choose it, in case you're
838 * capturing DOCSIS traffic that a Cisco Cable Modem
839 * Termination System is putting out onto an Ethernet (it
840 * doesn't put an Ethernet header onto the wire, it puts raw
841 * DOCSIS frames out on the wire inside the low-level
844 if (p
->dlt_list
!= NULL
) {
846 p
->dlt_list
[0] = DLT_EN10MB
;
847 p
->dlt_list
[1] = DLT_DOCSIS
;
849 p
->linktype
= DLT_EN10MB
;
856 if (p
->dlt_list
!= NULL
) {
858 p
->dlt_list
[0] = DLT_ATM_RFC1483
;
859 p
->dlt_list
[1] = DLT_SUNATM
;
861 p
->linktype
= DLT_ATM_RFC1483
;
865 if (p
->dlt_list
!= NULL
) {
867 p
->dlt_list
[0] = DLT_CHDLC
;
868 p
->dlt_list
[1] = DLT_PPP_SERIAL
;
869 p
->dlt_list
[2] = DLT_FRELAY
;
870 p
->dlt_list
[3] = DLT_MTP2
;
872 p
->linktype
= DLT_CHDLC
;
876 p
->linktype
= DLT_NULL
;
880 snprintf(p
->errbuf
, sizeof(p
->errbuf
), "unknown DAG linktype %d\n", daglinktype
);