]>
The Tcpdump Group git mirrors - libpcap/blob - pcap-dag.c
ae9c7abd7027acf6dc28b2c618b97d614f84bbe3
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: /tcpdump/master/libpcap/pcap-dag.c,v 1.27 2007-01-29 20:08:06 guy 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 ATM_CELL_SIZE 52
50 #define ATM_HDR_SIZE 4
52 /* SunATM pseudo header */
54 unsigned char flags
; /* destination and traffic type */
55 unsigned char vpi
; /* VPI */
56 unsigned short vci
; /* VCI */
59 typedef struct pcap_dag_node
{
60 struct pcap_dag_node
*next
;
65 static pcap_dag_node_t
*pcap_dags
= NULL
;
66 static int atexit_handler_installed
= 0;
67 static const unsigned short endian_test_word
= 0x0100;
69 #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word))
73 /* This code is required when compiling for a DAG device only. */
76 /* Replace dag function names with pcap equivalent. */
77 #define dag_open_live pcap_open_live
78 #define dag_platform_finddevs pcap_platform_finddevs
81 static int dag_setfilter(pcap_t
*p
, struct bpf_program
*fp
);
82 static int dag_stats(pcap_t
*p
, struct pcap_stat
*ps
);
83 static int dag_set_datalink(pcap_t
*p
, int dlt
);
84 static int dag_get_datalink(pcap_t
*p
);
85 static int dag_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
);
88 delete_pcap_dag(pcap_t
*p
)
90 pcap_dag_node_t
*curr
= NULL
, *prev
= NULL
;
92 for (prev
= NULL
, curr
= pcap_dags
; curr
!= NULL
&& curr
->p
!= p
; prev
= curr
, curr
= curr
->next
) {
96 if (curr
!= NULL
&& curr
->p
== p
) {
98 prev
->next
= curr
->next
;
100 pcap_dags
= curr
->next
;
106 * Performs a graceful shutdown of the DAG card, frees dynamic memory held
107 * in the pcap_t structure, and closes the file descriptor for the DAG card.
111 dag_platform_close(pcap_t
*p
)
115 #ifdef HAVE_DAG_STREAMS_API
116 if(dag_stop_stream(p
->fd
, p
->md
.dag_stream
) < 0)
117 fprintf(stderr
,"dag_stop_stream: %s\n", strerror(errno
));
119 if(dag_detach_stream(p
->fd
, p
->md
.dag_stream
) < 0)
120 fprintf(stderr
,"dag_detach_stream: %s\n", strerror(errno
));
122 if(dag_stop(p
->fd
) < 0)
123 fprintf(stderr
,"dag_stop: %s\n", strerror(errno
));
124 #endif /* HAVE_DAG_STREAMS_API */
125 if(dag_close(p
->fd
) < 0)
126 fprintf(stderr
,"dag_close: %s\n", strerror(errno
));
132 /* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
138 while (pcap_dags
!= NULL
) {
139 if (pcap_dags
->pid
== getpid()) {
140 dag_platform_close(pcap_dags
->p
);
142 delete_pcap_dag(pcap_dags
->p
);
148 new_pcap_dag(pcap_t
*p
)
150 pcap_dag_node_t
*node
= NULL
;
152 if ((node
= malloc(sizeof(pcap_dag_node_t
))) == NULL
) {
156 if (!atexit_handler_installed
) {
157 atexit(atexit_handler
);
158 atexit_handler_installed
= 1;
161 node
->next
= pcap_dags
;
163 node
->pid
= getpid();
171 * Read at most max_packets from the capture stream and call the callback
172 * for each of them. Returns the number of packets handled, -1 if an
173 * error occured, or -2 if we were told to break out of the loop.
176 dag_read(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
178 unsigned int processed
= 0;
179 int flags
= p
->md
.dag_offset_flags
;
180 unsigned int nonblocking
= flags
& DAGF_NONBLOCK
;
182 /* Get the next bufferful of packets (if necessary). */
183 while (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
) {
186 * Has "pcap_breakloop()" been called?
190 * Yes - clear the flag that indicates that
191 * it has, and return -2 to indicate that
192 * we were told to break out of the loop.
198 #ifdef HAVE_DAG_STREAMS_API
199 /* dag_advance_stream() will block (unless nonblock is called)
200 * until 64kB of data has accumulated.
201 * If to_ms is set, it will timeout before 64kB has accumulated.
202 * We wait for 64kB because processing a few packets at a time
203 * can cause problems at high packet rates (>200kpps) due
205 * This does mean if to_ms is not specified the capture may 'hang'
206 * for long periods if the data rate is extremely slow (<64kB/sec)
207 * If non-block is specified it will return immediately. The user
208 * is then responsible for efficiency.
210 p
->md
.dag_mem_top
= dag_advance_stream(p
->fd
, p
->md
.dag_stream
, &(p
->md
.dag_mem_bottom
));
212 /* dag_offset does not support timeouts */
213 p
->md
.dag_mem_top
= dag_offset(p
->fd
, &(p
->md
.dag_mem_bottom
), flags
);
214 #endif /* HAVE_DAG_STREAMS_API */
216 if (nonblocking
&& (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
))
218 /* Pcap is configured to process only available packets, and there aren't any, return immediately. */
224 (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
< dag_record_size
))
226 /* Blocking mode, but timeout set and no data has arrived, return anyway.*/
232 /* Process the packets. */
233 while (p
->md
.dag_mem_top
- p
->md
.dag_mem_bottom
>= dag_record_size
) {
235 unsigned short packet_len
= 0;
237 struct pcap_pkthdr pcap_header
;
239 #ifdef HAVE_DAG_STREAMS_API
240 dag_record_t
*header
= (dag_record_t
*)(p
->md
.dag_mem_bottom
);
242 dag_record_t
*header
= (dag_record_t
*)(p
->md
.dag_mem_base
+ p
->md
.dag_mem_bottom
);
243 #endif /* HAVE_DAG_STREAMS_API */
245 u_char
*dp
= ((u_char
*)header
) + dag_record_size
;
249 * Has "pcap_breakloop()" been called?
253 * Yes - clear the flag that indicates that
254 * it has, and return -2 to indicate that
255 * we were told to break out of the loop.
261 rlen
= ntohs(header
->rlen
);
262 if (rlen
< dag_record_size
)
264 strncpy(p
->errbuf
, "dag_read: record too small", PCAP_ERRBUF_SIZE
);
267 p
->md
.dag_mem_bottom
+= rlen
;
269 switch(header
->type
) {
273 if (header
->type
== TYPE_AAL5
) {
274 packet_len
= ntohs(header
->wlen
);
275 caplen
= rlen
- dag_record_size
;
280 if (header
->type
== TYPE_MC_ATM
) {
281 caplen
= packet_len
= ATM_CELL_SIZE
;
287 if (header
->type
== TYPE_MC_AAL5
) {
288 packet_len
= ntohs(header
->wlen
);
289 caplen
= rlen
- dag_record_size
- 4;
293 if (header
->type
== TYPE_ATM
) {
294 caplen
= packet_len
= ATM_CELL_SIZE
;
296 if (p
->linktype
== DLT_SUNATM
) {
297 struct sunatm_hdr
*sunatm
= (struct sunatm_hdr
*)dp
;
298 unsigned long rawatm
;
300 rawatm
= ntohl(*((unsigned long *)dp
));
301 sunatm
->vci
= htons((rawatm
>> 4) & 0xffff);
302 sunatm
->vpi
= (rawatm
>> 20) & 0x00ff;
303 sunatm
->flags
= ((header
->flags
.iface
& 1) ? 0x80 : 0x00) |
304 ((sunatm
->vpi
== 0 && sunatm
->vci
== htons(5)) ? 6 :
305 ((sunatm
->vpi
== 0 && sunatm
->vci
== htons(16)) ? 5 :
306 ((dp
[ATM_HDR_SIZE
] == 0xaa &&
307 dp
[ATM_HDR_SIZE
+1] == 0xaa &&
308 dp
[ATM_HDR_SIZE
+2] == 0x03) ? 2 : 1)));
311 packet_len
-= ATM_HDR_SIZE
;
312 caplen
-= ATM_HDR_SIZE
;
317 #ifdef TYPE_DSM_COLOR_ETH
318 case TYPE_DSM_COLOR_ETH
:
320 #ifdef TYPE_COLOR_ETH
324 packet_len
= ntohs(header
->wlen
);
325 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
326 caplen
= rlen
- dag_record_size
- 2;
327 if (caplen
> packet_len
) {
332 #ifdef TYPE_DSM_COLOR_HDLC_POS
333 case TYPE_DSM_COLOR_HDLC_POS
:
335 #ifdef TYPE_COLOR_HDLC_POS
336 case TYPE_COLOR_HDLC_POS
:
339 packet_len
= ntohs(header
->wlen
);
340 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
341 caplen
= rlen
- dag_record_size
;
342 if (caplen
> packet_len
) {
348 packet_len
= ntohs(header
->wlen
);
349 packet_len
-= (p
->md
.dag_fcs_bits
>> 3);
350 caplen
= rlen
- dag_record_size
- 4;
351 if (caplen
> packet_len
) {
358 /* Unhandled ERF type.
359 * Ignore rather than generating error
364 if (caplen
> p
->snapshot
)
365 caplen
= p
->snapshot
;
367 /* Count lost packets. */
368 switch(header
->type
) {
369 #ifdef TYPE_COLOR_HDLC_POS
370 /* in this type the color value overwrites the lctr */
371 case TYPE_COLOR_HDLC_POS
:
374 #ifdef TYPE_COLOR_ETH
375 /* in this type the color value overwrites the lctr */
379 #ifdef TYPE_DSM_COLOR_HDLC_POS
380 /* in this type the color value overwrites the lctr */
381 case TYPE_DSM_COLOR_HDLC_POS
:
384 #ifdef TYPE_DSM_COLOR_ETH
385 /* in this type the color value overwrites the lctr */
386 case TYPE_DSM_COLOR_ETH
:
392 if (p
->md
.stat
.ps_drop
> (UINT_MAX
- ntohs(header
->lctr
))) {
393 p
->md
.stat
.ps_drop
= UINT_MAX
;
395 p
->md
.stat
.ps_drop
+= ntohs(header
->lctr
);
400 /* Run the packet filter if there is one. */
401 if ((p
->fcode
.bf_insns
== NULL
) || bpf_filter(p
->fcode
.bf_insns
, dp
, packet_len
, caplen
)) {
403 /* convert between timestamp formats */
404 register unsigned long long ts
;
406 if (IS_BIGENDIAN()) {
407 ts
= SWAPLL(header
->ts
);
412 pcap_header
.ts
.tv_sec
= ts
>> 32;
413 ts
= (ts
& 0xffffffffULL
) * 1000000;
414 ts
+= 0x80000000; /* rounding */
415 pcap_header
.ts
.tv_usec
= ts
>> 32;
416 if (pcap_header
.ts
.tv_usec
>= 1000000) {
417 pcap_header
.ts
.tv_usec
-= 1000000;
418 pcap_header
.ts
.tv_sec
++;
421 /* Fill in our own header data */
422 pcap_header
.caplen
= caplen
;
423 pcap_header
.len
= packet_len
;
425 /* Count the packet. */
426 p
->md
.stat
.ps_recv
++;
428 /* Call the user supplied callback function */
429 callback(user
, &pcap_header
, dp
);
431 /* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
433 if (processed
== cnt
)
435 /* Reached the user-specified limit. */
445 dag_inject(pcap_t
*p
, const void *buf _U_
, size_t size _U_
)
447 strlcpy(p
->errbuf
, "Sending packets isn't supported on DAG cards",
453 * Get a handle for a live capture from the given DAG device. Passing a NULL
454 * device will result in a failure. The promisc flag is ignored because DAG
455 * cards are always promiscuous. The to_ms parameter is also ignored as it is
456 * not supported in hardware.
458 * snaplen is now also ignored, until we get per-stream slen support. Set
459 * slen with approprite DAG tool BEFORE pcap_open_live().
464 dag_open_live(const char *device
, int snaplen
, int promisc
, int to_ms
, char *ebuf
)
466 char conf
[30]; /* dag configure string */
472 #ifdef HAVE_DAG_STREAMS_API
474 struct timeval maxwait
;
478 if (device
== NULL
) {
479 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "device is NULL: %s", pcap_strerror(errno
));
482 /* Allocate a handle for this session. */
484 handle
= malloc(sizeof(*handle
));
485 if (handle
== NULL
) {
486 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "malloc %s: %s", device
, pcap_strerror(errno
));
490 /* Initialize some components of the pcap structure. */
492 memset(handle
, 0, sizeof(*handle
));
494 newDev
= (char *)malloc(strlen(device
) + 16);
496 #ifdef HAVE_DAG_STREAMS_API
498 /* Parse input name to get dag device and stream number if provided */
499 if (dag_parse_name(device
, newDev
, strlen(device
) + 16, &handle
->md
.dag_stream
) < 0) {
500 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_parse_name: %s\n", pcap_strerror(errno
));
505 if (handle
->md
.dag_stream
%2) {
506 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_parse_name: tx (even numbered) streams not supported for capture\n");
510 if (strstr(device
, "/dev") == NULL
) {
512 strcat(newDev
, "/dev/");
513 strcat(newDev
,device
);
516 device
= strdup(device
);
519 if (device
== NULL
) {
520 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "str_dup: %s\n", pcap_strerror(errno
));
523 #endif /* HAVE_DAG_STREAMS_API */
525 /* setup device parameters */
526 if((handle
->fd
= dag_open((char *)device
)) < 0) {
527 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_open %s: %s", device
, pcap_strerror(errno
));
531 #ifdef HAVE_DAG_STREAMS_API
532 /* Open requested stream. Can fail if already locked or on error */
533 if (dag_attach_stream(handle
->fd
, handle
->md
.dag_stream
, 0, 0) < 0) {
534 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_attach_stream: %s\n", pcap_strerror(errno
));
538 /* Set up default poll parameters for stream
539 * Can be overridden by pcap_set_nonblock()
541 if (dag_get_stream_poll(handle
->fd
, handle
->md
.dag_stream
,
542 &mindata
, &maxwait
, &poll
) < 0) {
543 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_get_stream_poll: %s\n", pcap_strerror(errno
));
547 /* Amount of data to collect in Bytes before calling callbacks.
548 * Important for efficiency, but can introduce latency
549 * at low packet rates if to_ms not set!
553 /* Obey to_ms if supplied. This is a good idea!
554 * Recommend 10-100ms. Calls will time out even if no data arrived.
556 maxwait
.tv_sec
= to_ms
/1000;
557 maxwait
.tv_usec
= (to_ms
%1000) * 1000;
559 if (dag_set_stream_poll(handle
->fd
, handle
->md
.dag_stream
,
560 mindata
, &maxwait
, &poll
) < 0) {
561 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_set_stream_poll: %s\n", pcap_strerror(errno
));
566 if((handle
->md
.dag_mem_base
= dag_mmap(handle
->fd
)) == MAP_FAILED
) {
567 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,"dag_mmap %s: %s\n", device
, pcap_strerror(errno
));
571 #endif /* HAVE_DAG_STREAMS_API */
573 /* XXX Not calling dag_configure() to set slen; this is unsafe in
574 * multi-stream environments as the gpp config is global.
575 * Once the firmware provides 'per-stream slen' this can be supported
576 * again via the Config API without side-effects */
578 /* set the card snap length to the specified snaplen parameter */
579 /* This is a really bad idea, as different cards have different
580 * valid slen ranges. Should fix in Config API. */
581 if (snaplen
== 0 || snaplen
> MAX_DAG_SNAPLEN
) {
582 snaplen
= MAX_DAG_SNAPLEN
;
583 } else if (snaplen
< MIN_DAG_SNAPLEN
) {
584 snaplen
= MIN_DAG_SNAPLEN
;
586 /* snap len has to be a multiple of 4 */
587 snprintf(conf
, 30, "varlen slen=%d", (snaplen
+ 3) & ~3);
589 if(dag_configure(handle
->fd
, conf
) < 0) {
590 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,"dag_configure %s: %s\n", device
, pcap_strerror(errno
));
595 #ifdef HAVE_DAG_STREAMS_API
596 if(dag_start_stream(handle
->fd
, handle
->md
.dag_stream
) < 0) {
597 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_start_stream %s: %s\n", device
, pcap_strerror(errno
));
601 if(dag_start(handle
->fd
) < 0) {
602 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "dag_start %s: %s\n", device
, pcap_strerror(errno
));
605 #endif /* HAVE_DAG_STREAMS_API */
608 * Important! You have to ensure bottom is properly
609 * initialized to zero on startup, it won't give you
610 * a compiler warning if you make this mistake!
612 handle
->md
.dag_mem_bottom
= 0;
613 handle
->md
.dag_mem_top
= 0;
614 handle
->md
.dag_fcs_bits
= 32;
616 /* Query the card first for special cases. */
617 daginf
= dag_info(handle
->fd
);
618 if ((0x4200 == daginf
->device_code
) || (0x4230 == daginf
->device_code
))
620 /* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
621 handle
->md
.dag_fcs_bits
= 0;
624 /* Then allow an environment variable to override. */
625 if ((s
= getenv("ERF_FCS_BITS")) != NULL
) {
626 if ((n
= atoi(s
)) == 0 || n
== 16|| n
== 32) {
627 handle
->md
.dag_fcs_bits
= n
;
629 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
630 "pcap_open_live %s: bad ERF_FCS_BITS value (%d) in environment\n", device
, n
);
635 handle
->snapshot
= snaplen
;
636 handle
->md
.dag_timeout
= to_ms
;
638 handle
->linktype
= -1;
639 if (dag_get_datalink(handle
) < 0) {
640 strcpy(ebuf
, handle
->errbuf
);
646 if (new_pcap_dag(handle
) < 0) {
647 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "new_pcap_dag %s: %s\n", device
, pcap_strerror(errno
));
652 * "select()" and "poll()" don't work on DAG device descriptors.
654 handle
->selectable_fd
= -1;
657 handle
->md
.device
= (char *)device
;
658 handle
->md
.timeout
= to_ms
;
660 free((char *)device
);
664 handle
->read_op
= dag_read
;
665 handle
->inject_op
= dag_inject
;
666 handle
->setfilter_op
= dag_setfilter
;
667 handle
->setdirection_op
= NULL
; /* Not implemented.*/
668 handle
->set_datalink_op
= dag_set_datalink
;
669 handle
->getnonblock_op
= pcap_getnonblock_fd
;
670 handle
->setnonblock_op
= dag_setnonblock
;
671 handle
->stats_op
= dag_stats
;
672 handle
->close_op
= dag_platform_close
;
673 handle
->md
.stat
.ps_drop
= 0;
674 handle
->md
.stat
.ps_recv
= 0;
678 if (newDev
!= NULL
) {
679 free((char *)newDev
);
681 if (handle
!= NULL
) {
683 * Get rid of any link-layer type list we allocated.
685 if (handle
->dlt_list
!= NULL
) {
686 free(handle
->dlt_list
);
695 dag_stats(pcap_t
*p
, struct pcap_stat
*ps
) {
696 /* This needs to be filled out correctly. Hopefully a dagapi call will
697 provide all necessary information.
699 /*p->md.stat.ps_recv = 0;*/
700 /*p->md.stat.ps_drop = 0;*/
708 * Simply submit all possible dag names as candidates.
709 * pcap_add_if() internally tests each candidate with pcap_open_live(),
710 * so any non-existent devices are dropped.
711 * For 2.5 try all rx stream names as well.
714 dag_platform_finddevs(pcap_if_t
**devlistp
, char *errbuf
)
716 char name
[12]; /* XXX - pick a size */
720 /* Try all the DAGs 0-9 */
721 for (c
= 0; c
< 9; c
++) {
722 snprintf(name
, 12, "dag%d", c
);
723 if (pcap_add_if(devlistp
, name
, 0, NULL
, errbuf
) == -1) {
729 #ifdef HAVE_DAG_STREAMS_API
732 for(stream
=0;stream
<16;stream
+=2) {
733 snprintf(name
, 10, "dag%d:%d", c
, stream
);
734 if (pcap_add_if(devlistp
, name
, 0, NULL
, errbuf
) == -1) {
742 #endif /* HAVE_DAG_STREAMS_API */
748 * Installs the given bpf filter program in the given pcap structure. There is
749 * no attempt to store the filter in kernel memory as that is not supported
753 dag_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
758 strncpy(p
->errbuf
, "setfilter: No filter specified",
763 /* Make our private copy of the filter */
765 if (install_bpf_program(p
, fp
) < 0)
774 dag_set_datalink(pcap_t
*p
, int dlt
)
782 dag_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
)
785 * Set non-blocking mode on the FD.
786 * XXX - is that necessary? If not, don't bother calling it,
787 * and have a "dag_getnonblock()" function that looks at
788 * "p->md.dag_offset_flags".
790 if (pcap_setnonblock_fd(p
, nonblock
, errbuf
) < 0)
792 #ifdef HAVE_DAG_STREAMS_API
795 struct timeval maxwait
;
798 if (dag_get_stream_poll(p
->fd
, p
->md
.dag_stream
,
799 &mindata
, &maxwait
, &poll
) < 0) {
800 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "dag_get_stream_poll: %s\n", pcap_strerror(errno
));
804 /* Amount of data to collect in Bytes before calling callbacks.
805 * Important for efficiency, but can introduce latency
806 * at low packet rates if to_ms not set!
813 if (dag_set_stream_poll(p
->fd
, p
->md
.dag_stream
,
814 mindata
, &maxwait
, &poll
) < 0) {
815 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "dag_set_stream_poll: %s\n", pcap_strerror(errno
));
819 #endif /* HAVE_DAG_STREAMS_API */
821 p
->md
.dag_offset_flags
|= DAGF_NONBLOCK
;
823 p
->md
.dag_offset_flags
&= ~DAGF_NONBLOCK
;
829 dag_get_datalink(pcap_t
*p
)
834 memset(types
, 0, 255);
836 if (p
->dlt_list
== NULL
&& (p
->dlt_list
= malloc(255*sizeof(*(p
->dlt_list
)))) == NULL
) {
837 (void)snprintf(p
->errbuf
, sizeof(p
->errbuf
), "malloc: %s", pcap_strerror(errno
));
843 #ifdef HAVE_DAG_GET_ERF_TYPES
844 /* Get list of possible ERF types for this card */
845 if (dag_get_erf_types(p
->fd
, types
, 255) < 0) {
846 snprintf(p
->errbuf
, sizeof(p
->errbuf
), "dag_get_erf_types: %s", pcap_strerror(errno
));
850 while (types
[index
]) {
852 /* Check the type through a dagapi call. */
853 types
[index
] = dag_linktype(p
->fd
);
857 switch(types
[index
]) {
860 #ifdef TYPE_COLOR_HDLC_POS
861 case TYPE_COLOR_HDLC_POS
:
863 #ifdef TYPE_DSM_COLOR_HDLC_POS
864 case TYPE_DSM_COLOR_HDLC_POS
:
866 if (p
->dlt_list
!= NULL
) {
867 p
->dlt_list
[index
++] = DLT_CHDLC
;
868 p
->dlt_list
[index
++] = DLT_PPP_SERIAL
;
869 p
->dlt_list
[index
++] = DLT_FRELAY
;
872 p
->linktype
= DLT_CHDLC
;
876 #ifdef TYPE_COLOR_ETH
879 #ifdef TYPE_DSM_COLOR_ETH
880 case TYPE_DSM_COLOR_ETH
:
883 * This is (presumably) a real Ethernet capture; give it a
884 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
885 * that an application can let you choose it, in case you're
886 * capturing DOCSIS traffic that a Cisco Cable Modem
887 * Termination System is putting out onto an Ethernet (it
888 * doesn't put an Ethernet header onto the wire, it puts raw
889 * DOCSIS frames out on the wire inside the low-level
892 if (p
->dlt_list
!= NULL
) {
893 p
->dlt_list
[index
++] = DLT_EN10MB
;
894 p
->dlt_list
[index
++] = DLT_DOCSIS
;
897 p
->linktype
= DLT_EN10MB
;
910 if (p
->dlt_list
!= NULL
) {
911 p
->dlt_list
[index
++] = DLT_ATM_RFC1483
;
912 p
->dlt_list
[index
++] = DLT_SUNATM
;
915 p
->linktype
= DLT_ATM_RFC1483
;
920 if (p
->dlt_list
!= NULL
) {
921 p
->dlt_list
[index
++] = DLT_CHDLC
;
922 p
->dlt_list
[index
++] = DLT_PPP_SERIAL
;
923 p
->dlt_list
[index
++] = DLT_FRELAY
;
924 p
->dlt_list
[index
++] = DLT_MTP2
;
927 p
->linktype
= DLT_CHDLC
;
933 p
->linktype
= DLT_NULL
;
937 snprintf(p
->errbuf
, sizeof(p
->errbuf
), "unknown DAG linktype %d", types
[index
]);
943 p
->dlt_count
= index
;