]> The Tcpdump Group git mirrors - libpcap/blob - pcap-dag.c
80ed01a2714c5c544a7c8c72c991da1d250bbe80
[libpcap] / pcap-dag.c
1 /*
2 * pcap-dag.c: Packet capture interface for Emulex EndaceDAG cards.
3 *
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.
11 *
12 * Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
13 * Modifications: Jesper Peterson
14 * Koryn Grant
15 * Stephen Donnelly <stephen.donnelly@emulex.com>
16 */
17
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <sys/param.h> /* optionally get BSD define */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
28 #include "pcap-int.h"
29
30 #include <ctype.h>
31 #include <netinet/in.h>
32 #include <sys/mman.h>
33 #include <sys/socket.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36
37 struct mbuf; /* Squelch compiler warnings on some platforms for */
38 struct rtentry; /* declarations in <net/if.h> */
39 #include <net/if.h>
40
41 #include "dagnew.h"
42 #include "dagapi.h"
43 #include "dagpci.h"
44
45 #include "pcap-dag.h"
46
47 /*
48 * DAG devices have names beginning with "dag", followed by a number
49 * from 0 to DAG_MAX_BOARDS, then optionally a colon and a stream number
50 * from 0 to DAG_STREAM_MAX.
51 */
52 #ifndef DAG_MAX_BOARDS
53 #define DAG_MAX_BOARDS 32
54 #endif
55
56
57 #ifndef ERF_TYPE_AAL5
58 #define ERF_TYPE_AAL5 4
59 #endif
60
61 #ifndef ERF_TYPE_MC_HDLC
62 #define ERF_TYPE_MC_HDLC 5
63 #endif
64
65 #ifndef ERF_TYPE_MC_RAW
66 #define ERF_TYPE_MC_RAW 6
67 #endif
68
69 #ifndef ERF_TYPE_MC_ATM
70 #define ERF_TYPE_MC_ATM 7
71 #endif
72
73 #ifndef ERF_TYPE_MC_RAW_CHANNEL
74 #define ERF_TYPE_MC_RAW_CHANNEL 8
75 #endif
76
77 #ifndef ERF_TYPE_MC_AAL5
78 #define ERF_TYPE_MC_AAL5 9
79 #endif
80
81 #ifndef ERF_TYPE_COLOR_HDLC_POS
82 #define ERF_TYPE_COLOR_HDLC_POS 10
83 #endif
84
85 #ifndef ERF_TYPE_COLOR_ETH
86 #define ERF_TYPE_COLOR_ETH 11
87 #endif
88
89 #ifndef ERF_TYPE_MC_AAL2
90 #define ERF_TYPE_MC_AAL2 12
91 #endif
92
93 #ifndef ERF_TYPE_IP_COUNTER
94 #define ERF_TYPE_IP_COUNTER 13
95 #endif
96
97 #ifndef ERF_TYPE_TCP_FLOW_COUNTER
98 #define ERF_TYPE_TCP_FLOW_COUNTER 14
99 #endif
100
101 #ifndef ERF_TYPE_DSM_COLOR_HDLC_POS
102 #define ERF_TYPE_DSM_COLOR_HDLC_POS 15
103 #endif
104
105 #ifndef ERF_TYPE_DSM_COLOR_ETH
106 #define ERF_TYPE_DSM_COLOR_ETH 16
107 #endif
108
109 #ifndef ERF_TYPE_COLOR_MC_HDLC_POS
110 #define ERF_TYPE_COLOR_MC_HDLC_POS 17
111 #endif
112
113 #ifndef ERF_TYPE_AAL2
114 #define ERF_TYPE_AAL2 18
115 #endif
116
117 #ifndef ERF_TYPE_COLOR_HASH_POS
118 #define ERF_TYPE_COLOR_HASH_POS 19
119 #endif
120
121 #ifndef ERF_TYPE_COLOR_HASH_ETH
122 #define ERF_TYPE_COLOR_HASH_ETH 20
123 #endif
124
125 #ifndef ERF_TYPE_INFINIBAND
126 #define ERF_TYPE_INFINIBAND 21
127 #endif
128
129 #ifndef ERF_TYPE_IPV4
130 #define ERF_TYPE_IPV4 22
131 #endif
132
133 #ifndef ERF_TYPE_IPV6
134 #define ERF_TYPE_IPV6 23
135 #endif
136
137 #ifndef ERF_TYPE_RAW_LINK
138 #define ERF_TYPE_RAW_LINK 24
139 #endif
140
141 #ifndef ERF_TYPE_INFINIBAND_LINK
142 #define ERF_TYPE_INFINIBAND_LINK 25
143 #endif
144
145 #ifndef ERF_TYPE_META
146 #define ERF_TYPE_META 27
147 #endif
148
149 #ifndef ERF_TYPE_PAD
150 #define ERF_TYPE_PAD 48
151 #endif
152
153 #define ATM_CELL_SIZE 52
154 #define ATM_HDR_SIZE 4
155
156 /*
157 * A header containing additional MTP information.
158 */
159 #define MTP2_SENT_OFFSET 0 /* 1 byte */
160 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
161 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
162 #define MTP2_HDR_LEN 4 /* length of the header */
163
164 #define MTP2_ANNEX_A_NOT_USED 0
165 #define MTP2_ANNEX_A_USED 1
166 #define MTP2_ANNEX_A_USED_UNKNOWN 2
167
168 /* SunATM pseudo header */
169 struct sunatm_hdr {
170 unsigned char flags; /* destination and traffic type */
171 unsigned char vpi; /* VPI */
172 unsigned short vci; /* VCI */
173 };
174
175 /*
176 * Private data for capturing on DAG devices.
177 */
178 struct pcap_dag {
179 struct pcap_stat stat;
180 u_char *dag_mem_bottom; /* DAG card current memory bottom pointer */
181 u_char *dag_mem_top; /* DAG card current memory top pointer */
182 int dag_fcs_bits; /* Number of checksum bits from link layer */
183 int dag_flags; /* Flags */
184 int dag_stream; /* DAG stream number */
185 int dag_timeout; /* timeout specified to pcap_open_live.
186 * Same as in linux above, introduce
187 * generally? */
188 };
189
190 typedef struct pcap_dag_node {
191 struct pcap_dag_node *next;
192 pcap_t *p;
193 pid_t pid;
194 } pcap_dag_node_t;
195
196 static pcap_dag_node_t *pcap_dags = NULL;
197 static int atexit_handler_installed = 0;
198 static const unsigned short endian_test_word = 0x0100;
199
200 #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word))
201
202 #define MAX_DAG_PACKET 65536
203
204 static unsigned char TempPkt[MAX_DAG_PACKET];
205
206 #ifndef HAVE_DAG_LARGE_STREAMS_API
207 #define dag_attach_stream64(a, b, c, d) dag_attach_stream(a, b, c, d)
208 #define dag_get_stream_poll64(a, b, c, d, e) dag_get_stream_poll(a, b, c, d, e)
209 #define dag_set_stream_poll64(a, b, c, d, e) dag_set_stream_poll(a, b, c, d, e)
210 #define dag_size_t uint32_t
211 #endif
212
213 static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
214 static int dag_stats(pcap_t *p, struct pcap_stat *ps);
215 static int dag_set_datalink(pcap_t *p, int dlt);
216 static int dag_get_datalink(pcap_t *p);
217 static int dag_setnonblock(pcap_t *p, int nonblock);
218
219 static void
220 delete_pcap_dag(pcap_t *p)
221 {
222 pcap_dag_node_t *curr = NULL, *prev = NULL;
223
224 for (prev = NULL, curr = pcap_dags; curr != NULL && curr->p != p; prev = curr, curr = curr->next) {
225 /* empty */
226 }
227
228 if (curr != NULL && curr->p == p) {
229 if (prev != NULL) {
230 prev->next = curr->next;
231 } else {
232 pcap_dags = curr->next;
233 }
234 }
235 }
236
237 /*
238 * Performs a graceful shutdown of the DAG card, frees dynamic memory held
239 * in the pcap_t structure, and closes the file descriptor for the DAG card.
240 */
241
242 static void
243 dag_platform_cleanup(pcap_t *p)
244 {
245 struct pcap_dag *pd = p->priv;
246
247 if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
248 fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
249
250 if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
251 fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
252
253 if(p->fd != -1) {
254 if(dag_close(p->fd) < 0)
255 fprintf(stderr,"dag_close: %s\n", strerror(errno));
256 p->fd = -1;
257 }
258 delete_pcap_dag(p);
259 pcap_cleanup_live_common(p);
260 /* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
261 }
262
263 static void
264 atexit_handler(void)
265 {
266 while (pcap_dags != NULL) {
267 if (pcap_dags->pid == getpid()) {
268 if (pcap_dags->p != NULL)
269 dag_platform_cleanup(pcap_dags->p);
270 } else {
271 delete_pcap_dag(pcap_dags->p);
272 }
273 }
274 }
275
276 static int
277 new_pcap_dag(pcap_t *p)
278 {
279 pcap_dag_node_t *node = NULL;
280
281 if ((node = malloc(sizeof(pcap_dag_node_t))) == NULL) {
282 return -1;
283 }
284
285 if (!atexit_handler_installed) {
286 atexit(atexit_handler);
287 atexit_handler_installed = 1;
288 }
289
290 node->next = pcap_dags;
291 node->p = p;
292 node->pid = getpid();
293
294 pcap_dags = node;
295
296 return 0;
297 }
298
299 static unsigned int
300 dag_erf_ext_header_count(uint8_t * erf, size_t len)
301 {
302 uint32_t hdr_num = 0;
303 uint8_t hdr_type;
304
305 /* basic sanity checks */
306 if ( erf == NULL )
307 return 0;
308 if ( len < 16 )
309 return 0;
310
311 /* check if we have any extension headers */
312 if ( (erf[8] & 0x80) == 0x00 )
313 return 0;
314
315 /* loop over the extension headers */
316 do {
317
318 /* sanity check we have enough bytes */
319 if ( len < (24 + (hdr_num * 8)) )
320 return hdr_num;
321
322 /* get the header type */
323 hdr_type = erf[(16 + (hdr_num * 8))];
324 hdr_num++;
325
326 } while ( hdr_type & 0x80 );
327
328 return hdr_num;
329 }
330
331 /*
332 * Read at most max_packets from the capture stream and call the callback
333 * for each of them. Returns the number of packets handled, -1 if an
334 * error occured, or -2 if we were told to break out of the loop.
335 */
336 static int
337 dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
338 {
339 struct pcap_dag *pd = p->priv;
340 unsigned int processed = 0;
341 unsigned int nonblocking = pd->dag_flags & DAGF_NONBLOCK;
342 unsigned int num_ext_hdr = 0;
343 unsigned int ticks_per_second;
344
345 /* Get the next bufferful of packets (if necessary). */
346 while (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size) {
347
348 /*
349 * Has "pcap_breakloop()" been called?
350 */
351 if (p->break_loop) {
352 /*
353 * Yes - clear the flag that indicates that
354 * it has, and return -2 to indicate that
355 * we were told to break out of the loop.
356 */
357 p->break_loop = 0;
358 return -2;
359 }
360
361 /* dag_advance_stream() will block (unless nonblock is called)
362 * until 64kB of data has accumulated.
363 * If to_ms is set, it will timeout before 64kB has accumulated.
364 * We wait for 64kB because processing a few packets at a time
365 * can cause problems at high packet rates (>200kpps) due
366 * to inefficiencies.
367 * This does mean if to_ms is not specified the capture may 'hang'
368 * for long periods if the data rate is extremely slow (<64kB/sec)
369 * If non-block is specified it will return immediately. The user
370 * is then responsible for efficiency.
371 */
372 if ( NULL == (pd->dag_mem_top = dag_advance_stream(p->fd, pd->dag_stream, &(pd->dag_mem_bottom))) ) {
373 return -1;
374 }
375
376 if (nonblocking && (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
377 {
378 /* Pcap is configured to process only available packets, and there aren't any, return immediately. */
379 return 0;
380 }
381
382 if(!nonblocking &&
383 pd->dag_timeout &&
384 (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
385 {
386 /* Blocking mode, but timeout set and no data has arrived, return anyway.*/
387 return 0;
388 }
389
390 }
391
392 /* Process the packets. */
393 while (pd->dag_mem_top - pd->dag_mem_bottom >= dag_record_size) {
394
395 unsigned short packet_len = 0;
396 int caplen = 0;
397 struct pcap_pkthdr pcap_header;
398
399 dag_record_t *header = (dag_record_t *)(pd->dag_mem_bottom);
400
401 u_char *dp = ((u_char *)header); /* + dag_record_size; */
402 unsigned short rlen;
403
404 /*
405 * Has "pcap_breakloop()" been called?
406 */
407 if (p->break_loop) {
408 /*
409 * Yes - clear the flag that indicates that
410 * it has, and return -2 to indicate that
411 * we were told to break out of the loop.
412 */
413 p->break_loop = 0;
414 return -2;
415 }
416
417 rlen = ntohs(header->rlen);
418 if (rlen < dag_record_size)
419 {
420 strncpy(p->errbuf, "dag_read: record too small", PCAP_ERRBUF_SIZE);
421 return -1;
422 }
423 pd->dag_mem_bottom += rlen;
424
425 /* Count lost packets. */
426 switch((header->type & 0x7f)) {
427 /* in these types the color value overwrites the lctr */
428 case ERF_TYPE_COLOR_HDLC_POS:
429 case ERF_TYPE_COLOR_ETH:
430 case ERF_TYPE_DSM_COLOR_HDLC_POS:
431 case ERF_TYPE_DSM_COLOR_ETH:
432 case ERF_TYPE_COLOR_MC_HDLC_POS:
433 case ERF_TYPE_COLOR_HASH_ETH:
434 case ERF_TYPE_COLOR_HASH_POS:
435 break;
436
437 default:
438 if (header->lctr) {
439 if (pd->stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
440 pd->stat.ps_drop = UINT_MAX;
441 } else {
442 pd->stat.ps_drop += ntohs(header->lctr);
443 }
444 }
445 }
446
447 if ((header->type & 0x7f) == ERF_TYPE_PAD) {
448 continue;
449 }
450
451 num_ext_hdr = dag_erf_ext_header_count(dp, rlen);
452
453 /* ERF encapsulation */
454 /* The Extensible Record Format is not dropped for this kind of encapsulation,
455 * and will be handled as a pseudo header by the decoding application.
456 * The information carried in the ERF header and in the optional subheader (if present)
457 * could be merged with the libpcap information, to offer a better decoding.
458 * The packet length is
459 * o the length of the packet on the link (header->wlen),
460 * o plus the length of the ERF header (dag_record_size), as the length of the
461 * pseudo header will be adjusted during the decoding,
462 * o plus the length of the optional subheader (if present).
463 *
464 * The capture length is header.rlen and the byte stuffing for alignment will be dropped
465 * if the capture length is greater than the packet length.
466 */
467 if (p->linktype == DLT_ERF) {
468 packet_len = ntohs(header->wlen) + dag_record_size;
469 caplen = rlen;
470 switch ((header->type & 0x7f)) {
471 case ERF_TYPE_MC_AAL5:
472 case ERF_TYPE_MC_ATM:
473 case ERF_TYPE_MC_HDLC:
474 case ERF_TYPE_MC_RAW_CHANNEL:
475 case ERF_TYPE_MC_RAW:
476 case ERF_TYPE_MC_AAL2:
477 case ERF_TYPE_COLOR_MC_HDLC_POS:
478 packet_len += 4; /* MC header */
479 break;
480
481 case ERF_TYPE_COLOR_HASH_ETH:
482 case ERF_TYPE_DSM_COLOR_ETH:
483 case ERF_TYPE_COLOR_ETH:
484 case ERF_TYPE_ETH:
485 packet_len += 2; /* ETH header */
486 break;
487 } /* switch type */
488
489 /* Include ERF extension headers */
490 packet_len += (8 * num_ext_hdr);
491
492 if (caplen > packet_len) {
493 caplen = packet_len;
494 }
495 } else {
496 /* Other kind of encapsulation according to the header Type */
497
498 /* Skip over generic ERF header */
499 dp += dag_record_size;
500 /* Skip over extension headers */
501 dp += 8 * num_ext_hdr;
502
503 switch((header->type & 0x7f)) {
504 case ERF_TYPE_ATM:
505 case ERF_TYPE_AAL5:
506 if ((header->type & 0x7f) == ERF_TYPE_AAL5) {
507 packet_len = ntohs(header->wlen);
508 caplen = rlen - dag_record_size;
509 }
510 case ERF_TYPE_MC_ATM:
511 if ((header->type & 0x7f) == ERF_TYPE_MC_ATM) {
512 caplen = packet_len = ATM_CELL_SIZE;
513 dp+=4;
514 }
515 case ERF_TYPE_MC_AAL5:
516 if ((header->type & 0x7f) == ERF_TYPE_MC_AAL5) {
517 packet_len = ntohs(header->wlen);
518 caplen = rlen - dag_record_size - 4;
519 dp+=4;
520 }
521 /* Skip over extension headers */
522 caplen -= (8 * num_ext_hdr);
523
524 if ((header->type & 0x7f) == ERF_TYPE_ATM) {
525 caplen = packet_len = ATM_CELL_SIZE;
526 }
527 if (p->linktype == DLT_SUNATM) {
528 struct sunatm_hdr *sunatm = (struct sunatm_hdr *)dp;
529 unsigned long rawatm;
530
531 rawatm = ntohl(*((unsigned long *)dp));
532 sunatm->vci = htons((rawatm >> 4) & 0xffff);
533 sunatm->vpi = (rawatm >> 20) & 0x00ff;
534 sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) |
535 ((sunatm->vpi == 0 && sunatm->vci == htons(5)) ? 6 :
536 ((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 :
537 ((dp[ATM_HDR_SIZE] == 0xaa &&
538 dp[ATM_HDR_SIZE+1] == 0xaa &&
539 dp[ATM_HDR_SIZE+2] == 0x03) ? 2 : 1)));
540
541 } else if (p->linktype == DLT_ATM_RFC1483) {
542 packet_len -= ATM_HDR_SIZE;
543 caplen -= ATM_HDR_SIZE;
544 dp += ATM_HDR_SIZE;
545 } else
546 continue;
547 break;
548
549 case ERF_TYPE_COLOR_HASH_ETH:
550 case ERF_TYPE_DSM_COLOR_ETH:
551 case ERF_TYPE_COLOR_ETH:
552 case ERF_TYPE_ETH:
553 if ((p->linktype != DLT_EN10MB) &&
554 (p->linktype != DLT_DOCSIS))
555 continue;
556 packet_len = ntohs(header->wlen);
557 packet_len -= (pd->dag_fcs_bits >> 3);
558 caplen = rlen - dag_record_size - 2;
559 /* Skip over extension headers */
560 caplen -= (8 * num_ext_hdr);
561 if (caplen > packet_len) {
562 caplen = packet_len;
563 }
564 dp += 2;
565 break;
566
567 case ERF_TYPE_COLOR_HASH_POS:
568 case ERF_TYPE_DSM_COLOR_HDLC_POS:
569 case ERF_TYPE_COLOR_HDLC_POS:
570 case ERF_TYPE_HDLC_POS:
571 if ((p->linktype != DLT_CHDLC) &&
572 (p->linktype != DLT_PPP_SERIAL) &&
573 (p->linktype != DLT_FRELAY))
574 continue;
575 packet_len = ntohs(header->wlen);
576 packet_len -= (pd->dag_fcs_bits >> 3);
577 caplen = rlen - dag_record_size;
578 /* Skip over extension headers */
579 caplen -= (8 * num_ext_hdr);
580 if (caplen > packet_len) {
581 caplen = packet_len;
582 }
583 break;
584
585 case ERF_TYPE_COLOR_MC_HDLC_POS:
586 case ERF_TYPE_MC_HDLC:
587 if ((p->linktype != DLT_CHDLC) &&
588 (p->linktype != DLT_PPP_SERIAL) &&
589 (p->linktype != DLT_FRELAY) &&
590 (p->linktype != DLT_MTP2) &&
591 (p->linktype != DLT_MTP2_WITH_PHDR) &&
592 (p->linktype != DLT_LAPD))
593 continue;
594 packet_len = ntohs(header->wlen);
595 packet_len -= (pd->dag_fcs_bits >> 3);
596 caplen = rlen - dag_record_size - 4;
597 /* Skip over extension headers */
598 caplen -= (8 * num_ext_hdr);
599 if (caplen > packet_len) {
600 caplen = packet_len;
601 }
602 /* jump the MC_HDLC_HEADER */
603 dp += 4;
604 #ifdef DLT_MTP2_WITH_PHDR
605 if (p->linktype == DLT_MTP2_WITH_PHDR) {
606 /* Add the MTP2 Pseudo Header */
607 caplen += MTP2_HDR_LEN;
608 packet_len += MTP2_HDR_LEN;
609
610 TempPkt[MTP2_SENT_OFFSET] = 0;
611 TempPkt[MTP2_ANNEX_A_USED_OFFSET] = MTP2_ANNEX_A_USED_UNKNOWN;
612 *(TempPkt+MTP2_LINK_NUMBER_OFFSET) = ((header->rec.mc_hdlc.mc_header>>16)&0x01);
613 *(TempPkt+MTP2_LINK_NUMBER_OFFSET+1) = ((header->rec.mc_hdlc.mc_header>>24)&0xff);
614 memcpy(TempPkt+MTP2_HDR_LEN, dp, caplen);
615 dp = TempPkt;
616 }
617 #endif
618 break;
619
620 case ERF_TYPE_IPV4:
621 if ((p->linktype != DLT_RAW) &&
622 (p->linktype != DLT_IPV4))
623 continue;
624 packet_len = ntohs(header->wlen);
625 caplen = rlen - dag_record_size;
626 /* Skip over extension headers */
627 caplen -= (8 * num_ext_hdr);
628 if (caplen > packet_len) {
629 caplen = packet_len;
630 }
631 break;
632
633 case ERF_TYPE_IPV6:
634 if ((p->linktype != DLT_RAW) &&
635 (p->linktype != DLT_IPV6))
636 continue;
637 packet_len = ntohs(header->wlen);
638 caplen = rlen - dag_record_size;
639 /* Skip over extension headers */
640 caplen -= (8 * num_ext_hdr);
641 if (caplen > packet_len) {
642 caplen = packet_len;
643 }
644 break;
645
646 /* These types have no matching 'native' DLT, but can be used with DLT_ERF above */
647 case ERF_TYPE_MC_RAW:
648 case ERF_TYPE_MC_RAW_CHANNEL:
649 case ERF_TYPE_IP_COUNTER:
650 case ERF_TYPE_TCP_FLOW_COUNTER:
651 case ERF_TYPE_INFINIBAND:
652 case ERF_TYPE_RAW_LINK:
653 case ERF_TYPE_INFINIBAND_LINK:
654 default:
655 /* Unhandled ERF type.
656 * Ignore rather than generating error
657 */
658 continue;
659 } /* switch type */
660
661 } /* ERF encapsulation */
662
663 if (caplen > p->snapshot)
664 caplen = p->snapshot;
665
666 /* Run the packet filter if there is one. */
667 if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
668
669 /* convert between timestamp formats */
670 register unsigned long long ts;
671
672 if (IS_BIGENDIAN()) {
673 ts = SWAPLL(header->ts);
674 } else {
675 ts = header->ts;
676 }
677
678 switch (p->opt.tstamp_precision) {
679 case PCAP_TSTAMP_PRECISION_NANO:
680 ticks_per_second = 1000000000;
681 break;
682 case PCAP_TSTAMP_PRECISION_MICRO:
683 default:
684 ticks_per_second = 1000000;
685 break;
686
687 }
688 pcap_header.ts.tv_sec = ts >> 32;
689 ts = (ts & 0xffffffffULL) * ticks_per_second;
690 ts += 0x80000000; /* rounding */
691 pcap_header.ts.tv_usec = ts >> 32;
692 if (pcap_header.ts.tv_usec >= ticks_per_second) {
693 pcap_header.ts.tv_usec -= ticks_per_second;
694 pcap_header.ts.tv_sec++;
695 }
696
697 /* Fill in our own header data */
698 pcap_header.caplen = caplen;
699 pcap_header.len = packet_len;
700
701 /* Count the packet. */
702 pd->stat.ps_recv++;
703
704 /* Call the user supplied callback function */
705 callback(user, &pcap_header, dp);
706
707 /* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
708 processed++;
709 if (processed == cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
710 {
711 /* Reached the user-specified limit. */
712 return cnt;
713 }
714 }
715 }
716
717 return processed;
718 }
719
720 static int
721 dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
722 {
723 strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
724 PCAP_ERRBUF_SIZE);
725 return (-1);
726 }
727
728 /*
729 * Get a handle for a live capture from the given DAG device. Passing a NULL
730 * device will result in a failure. The promisc flag is ignored because DAG
731 * cards are always promiscuous. The to_ms parameter is used in setting the
732 * API polling parameters.
733 *
734 * snaplen is now also ignored, until we get per-stream slen support. Set
735 * slen with approprite DAG tool BEFORE pcap_activate().
736 *
737 * See also pcap(3).
738 */
739 static int dag_activate(pcap_t* handle)
740 {
741 struct pcap_dag *handlep = handle->priv;
742 char *s;
743 int n;
744 daginf_t* daginf;
745 char * newDev = NULL;
746 char * device = handle->opt.device;
747 dag_size_t mindata;
748 struct timeval maxwait;
749 struct timeval poll;
750
751 if (device == NULL) {
752 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "device is NULL: %s", pcap_strerror(errno));
753 return -1;
754 }
755
756 /* Initialize some components of the pcap structure. */
757 newDev = (char *)malloc(strlen(device) + 16);
758 if (newDev == NULL) {
759 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate string for device name: %s", pcap_strerror(errno));
760 goto fail;
761 }
762
763 /* Parse input name to get dag device and stream number if provided */
764 if (dag_parse_name(device, newDev, strlen(device) + 16, &handlep->dag_stream) < 0) {
765 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s", pcap_strerror(errno));
766 goto fail;
767 }
768 device = newDev;
769
770 if (handlep->dag_stream%2) {
771 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture");
772 goto fail;
773 }
774
775 /* setup device parameters */
776 if((handle->fd = dag_open((char *)device)) < 0) {
777 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_open %s: %s", device, pcap_strerror(errno));
778 goto fail;
779 }
780
781 /* Open requested stream. Can fail if already locked or on error */
782 if (dag_attach_stream64(handle->fd, handlep->dag_stream, 0, 0) < 0) {
783 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_attach_stream: %s", pcap_strerror(errno));
784 goto failclose;
785 }
786
787 /* Set up default poll parameters for stream
788 * Can be overridden by pcap_set_nonblock()
789 */
790 if (dag_get_stream_poll64(handle->fd, handlep->dag_stream,
791 &mindata, &maxwait, &poll) < 0) {
792 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
793 goto faildetach;
794 }
795
796 if (handle->opt.immediate) {
797 /* Call callback immediately.
798 * XXX - is this the right way to handle this?
799 */
800 mindata = 0;
801 } else {
802 /* Amount of data to collect in Bytes before calling callbacks.
803 * Important for efficiency, but can introduce latency
804 * at low packet rates if to_ms not set!
805 */
806 mindata = 65536;
807 }
808
809 /* Obey opt.timeout (was to_ms) if supplied. This is a good idea!
810 * Recommend 10-100ms. Calls will time out even if no data arrived.
811 */
812 maxwait.tv_sec = handle->opt.timeout/1000;
813 maxwait.tv_usec = (handle->opt.timeout%1000) * 1000;
814
815 if (dag_set_stream_poll64(handle->fd, handlep->dag_stream,
816 mindata, &maxwait, &poll) < 0) {
817 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
818 goto faildetach;
819 }
820
821 /* XXX Not calling dag_configure() to set slen; this is unsafe in
822 * multi-stream environments as the gpp config is global.
823 * Once the firmware provides 'per-stream slen' this can be supported
824 * again via the Config API without side-effects */
825 #if 0
826 /* set the card snap length to the specified snaplen parameter */
827 /* This is a really bad idea, as different cards have different
828 * valid slen ranges. Should fix in Config API. */
829 if (handle->snapshot == 0 || handle->snapshot > MAX_DAG_SNAPLEN) {
830 handle->snapshot = MAX_DAG_SNAPLEN;
831 } else if (snaplen < MIN_DAG_SNAPLEN) {
832 handle->snapshot = MIN_DAG_SNAPLEN;
833 }
834 /* snap len has to be a multiple of 4 */
835 #endif
836
837 if(dag_start_stream(handle->fd, handlep->dag_stream) < 0) {
838 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s", device, pcap_strerror(errno));
839 goto faildetach;
840 }
841
842 /*
843 * Important! You have to ensure bottom is properly
844 * initialized to zero on startup, it won't give you
845 * a compiler warning if you make this mistake!
846 */
847 handlep->dag_mem_bottom = 0;
848 handlep->dag_mem_top = 0;
849
850 /*
851 * Find out how many FCS bits we should strip.
852 * First, query the card to see if it strips the FCS.
853 */
854 daginf = dag_info(handle->fd);
855 if ((0x4200 == daginf->device_code) || (0x4230 == daginf->device_code)) {
856 /* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
857 handlep->dag_fcs_bits = 0;
858
859 /* Note that no FCS will be supplied. */
860 handle->linktype_ext = LT_FCS_DATALINK_EXT(0);
861 } else {
862 /*
863 * Start out assuming it's 32 bits.
864 */
865 handlep->dag_fcs_bits = 32;
866
867 /* Allow an environment variable to override. */
868 if ((s = getenv("ERF_FCS_BITS")) != NULL) {
869 if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
870 handlep->dag_fcs_bits = n;
871 } else {
872 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
873 "pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
874 goto failstop;
875 }
876 }
877
878 /*
879 * Did the user request that they not be stripped?
880 */
881 if ((s = getenv("ERF_DONT_STRIP_FCS")) != NULL) {
882 /* Yes. Note the number of bytes that will be
883 supplied. */
884 handle->linktype_ext = LT_FCS_DATALINK_EXT(handlep->dag_fcs_bits/16);
885
886 /* And don't strip them. */
887 handlep->dag_fcs_bits = 0;
888 }
889 }
890
891 handlep->dag_timeout = handle->opt.timeout;
892
893 handle->linktype = -1;
894 if (dag_get_datalink(handle) < 0)
895 goto failstop;
896
897 handle->bufsize = 0;
898
899 if (new_pcap_dag(handle) < 0) {
900 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "new_pcap_dag %s: %s", device, pcap_strerror(errno));
901 goto failstop;
902 }
903
904 /*
905 * "select()" and "poll()" don't work on DAG device descriptors.
906 */
907 handle->selectable_fd = -1;
908
909 if (newDev != NULL) {
910 free((char *)newDev);
911 }
912
913 handle->read_op = dag_read;
914 handle->inject_op = dag_inject;
915 handle->setfilter_op = dag_setfilter;
916 handle->setdirection_op = NULL; /* Not implemented.*/
917 handle->set_datalink_op = dag_set_datalink;
918 handle->getnonblock_op = pcap_getnonblock_fd;
919 handle->setnonblock_op = dag_setnonblock;
920 handle->stats_op = dag_stats;
921 handle->cleanup_op = dag_platform_cleanup;
922 handlep->stat.ps_drop = 0;
923 handlep->stat.ps_recv = 0;
924 handlep->stat.ps_ifdrop = 0;
925 return 0;
926
927 failstop:
928 if (dag_stop_stream(handle->fd, handlep->dag_stream) < 0) {
929 fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
930 }
931
932 faildetach:
933 if (dag_detach_stream(handle->fd, handlep->dag_stream) < 0)
934 fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
935
936 failclose:
937 if (dag_close(handle->fd) < 0)
938 fprintf(stderr,"dag_close: %s\n", strerror(errno));
939 delete_pcap_dag(handle);
940
941 fail:
942 pcap_cleanup_live_common(handle);
943 if (newDev != NULL) {
944 free((char *)newDev);
945 }
946
947 return PCAP_ERROR;
948 }
949
950 pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
951 {
952 const char *cp;
953 char *cpend;
954 long devnum;
955 pcap_t *p;
956 long stream = 0;
957
958 /* Does this look like a DAG device? */
959 cp = strrchr(device, '/');
960 if (cp == NULL)
961 cp = device;
962 /* Does it begin with "dag"? */
963 if (strncmp(cp, "dag", 3) != 0) {
964 /* Nope, doesn't begin with "dag" */
965 *is_ours = 0;
966 return NULL;
967 }
968 /* Yes - is "dag" followed by a number from 0 to DAG_MAX_BOARDS-1 */
969 cp += 3;
970 devnum = strtol(cp, &cpend, 10);
971 if (*cpend == ':') {
972 /* Followed by a stream number. */
973 stream = strtol(++cpend, &cpend, 10);
974 }
975
976 if (cpend == cp || *cpend != '\0') {
977 /* Not followed by a number. */
978 *is_ours = 0;
979 return NULL;
980 }
981
982 if (devnum < 0 || devnum >= DAG_MAX_BOARDS) {
983 /* Followed by a non-valid number. */
984 *is_ours = 0;
985 return NULL;
986 }
987
988 if (stream <0 || stream >= DAG_STREAM_MAX) {
989 /* Followed by a non-valid stream number. */
990 *is_ours = 0;
991 return NULL;
992 }
993
994 /* OK, it's probably ours. */
995 *is_ours = 1;
996
997 p = pcap_create_common(ebuf, sizeof (struct pcap_dag));
998 if (p == NULL)
999 return NULL;
1000
1001 p->activate_op = dag_activate;
1002
1003 /*
1004 * We claim that we support microsecond and nanosecond time
1005 * stamps.
1006 *
1007 * XXX Our native precision is 2^-32s, but libpcap doesn't support
1008 * power of two precisions yet. We can convert to either MICRO or NANO.
1009 */
1010 p->tstamp_precision_count = 2;
1011 p->tstamp_precision_list = malloc(2 * sizeof(u_int));
1012 if (p->tstamp_precision_list == NULL) {
1013 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
1014 pcap_strerror(errno));
1015 pcap_close(p);
1016 return NULL;
1017 }
1018 p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
1019 p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
1020 return p;
1021 }
1022
1023 static int
1024 dag_stats(pcap_t *p, struct pcap_stat *ps) {
1025 struct pcap_dag *pd = p->priv;
1026
1027 /* This needs to be filled out correctly. Hopefully a dagapi call will
1028 provide all necessary information.
1029 */
1030 /*pd->stat.ps_recv = 0;*/
1031 /*pd->stat.ps_drop = 0;*/
1032
1033 *ps = pd->stat;
1034
1035 return 0;
1036 }
1037
1038 /*
1039 * Add all DAG devices.
1040 */
1041 int
1042 dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
1043 {
1044 char name[12]; /* XXX - pick a size */
1045 int ret = 0;
1046 int c;
1047 char dagname[DAGNAME_BUFSIZE];
1048 int dagstream;
1049 int dagfd;
1050 dag_card_inf_t *inf;
1051 char *description;
1052 int stream, rxstreams;
1053
1054 /* Try all the DAGs 0-DAG_MAX_BOARDS */
1055 for (c = 0; c < DAG_MAX_BOARDS; c++) {
1056 pcap_snprintf(name, 12, "dag%d", c);
1057 if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream))
1058 {
1059 (void) pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1060 "dag: device name %s can't be parsed", name);
1061 return -1;
1062 }
1063 if ( (dagfd = dag_open(dagname)) >= 0 ) {
1064 description = NULL;
1065 if ((inf = dag_pciinfo(dagfd)))
1066 description = dag_device_name(inf->device_code, 1);
1067 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1068 /*
1069 * Failure.
1070 */
1071 ret = -1;
1072 }
1073 rxstreams = dag_rx_get_stream_count(dagfd);
1074 for(stream=0;stream<DAG_STREAM_MAX;stream+=2) {
1075 if (0 == dag_attach_stream(dagfd, stream, 0, 0)) {
1076 dag_detach_stream(dagfd, stream);
1077
1078 pcap_snprintf(name, 10, "dag%d:%d", c, stream);
1079 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1080 /*
1081 * Failure.
1082 */
1083 ret = -1;
1084 }
1085
1086 rxstreams--;
1087 if(rxstreams <= 0) {
1088 break;
1089 }
1090 }
1091 }
1092 dag_close(dagfd);
1093 }
1094
1095 }
1096 return (ret);
1097 }
1098
1099 /*
1100 * Installs the given bpf filter program in the given pcap structure. There is
1101 * no attempt to store the filter in kernel memory as that is not supported
1102 * with DAG cards.
1103 */
1104 static int
1105 dag_setfilter(pcap_t *p, struct bpf_program *fp)
1106 {
1107 if (!p)
1108 return -1;
1109 if (!fp) {
1110 strncpy(p->errbuf, "setfilter: No filter specified",
1111 sizeof(p->errbuf));
1112 return -1;
1113 }
1114
1115 /* Make our private copy of the filter */
1116
1117 if (install_bpf_program(p, fp) < 0)
1118 return -1;
1119
1120 return (0);
1121 }
1122
1123 static int
1124 dag_set_datalink(pcap_t *p, int dlt)
1125 {
1126 p->linktype = dlt;
1127
1128 return (0);
1129 }
1130
1131 static int
1132 dag_setnonblock(pcap_t *p, int nonblock)
1133 {
1134 struct pcap_dag *pd = p->priv;
1135 dag_size_t mindata;
1136 struct timeval maxwait;
1137 struct timeval poll;
1138
1139 /*
1140 * Set non-blocking mode on the FD.
1141 * XXX - is that necessary? If not, don't bother calling it,
1142 * and have a "dag_getnonblock()" function that looks at
1143 * "pd->dag_flags".
1144 */
1145 if (pcap_setnonblock_fd(p, nonblock) < 0)
1146 return (-1);
1147
1148 if (dag_get_stream_poll64(p->fd, pd->dag_stream,
1149 &mindata, &maxwait, &poll) < 0) {
1150 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
1151 return -1;
1152 }
1153
1154 /* Amount of data to collect in Bytes before calling callbacks.
1155 * Important for efficiency, but can introduce latency
1156 * at low packet rates if to_ms not set!
1157 */
1158 if(nonblock)
1159 mindata = 0;
1160 else
1161 mindata = 65536;
1162
1163 if (dag_set_stream_poll64(p->fd, pd->dag_stream,
1164 mindata, &maxwait, &poll) < 0) {
1165 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
1166 return -1;
1167 }
1168
1169 if (nonblock) {
1170 pd->dag_flags |= DAGF_NONBLOCK;
1171 } else {
1172 pd->dag_flags &= ~DAGF_NONBLOCK;
1173 }
1174 return (0);
1175 }
1176
1177 static int
1178 dag_get_datalink(pcap_t *p)
1179 {
1180 struct pcap_dag *pd = p->priv;
1181 int index=0, dlt_index=0;
1182 uint8_t types[255];
1183
1184 memset(types, 0, 255);
1185
1186 if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
1187 (void)pcap_snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s", pcap_strerror(errno));
1188 return (-1);
1189 }
1190
1191 p->linktype = 0;
1192
1193 #ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
1194 /* Get list of possible ERF types for this card */
1195 if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
1196 pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
1197 return (-1);
1198 }
1199
1200 while (types[index]) {
1201
1202 #elif defined HAVE_DAG_GET_ERF_TYPES
1203 /* Get list of possible ERF types for this card */
1204 if (dag_get_erf_types(p->fd, types, 255) < 0) {
1205 pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
1206 return (-1);
1207 }
1208
1209 while (types[index]) {
1210 #else
1211 /* Check the type through a dagapi call. */
1212 types[index] = dag_linktype(p->fd);
1213
1214 {
1215 #endif
1216 switch((types[index] & 0x7f)) {
1217
1218 case ERF_TYPE_HDLC_POS:
1219 case ERF_TYPE_COLOR_HDLC_POS:
1220 case ERF_TYPE_DSM_COLOR_HDLC_POS:
1221 case ERF_TYPE_COLOR_HASH_POS:
1222
1223 if (p->dlt_list != NULL) {
1224 p->dlt_list[dlt_index++] = DLT_CHDLC;
1225 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1226 p->dlt_list[dlt_index++] = DLT_FRELAY;
1227 }
1228 if(!p->linktype)
1229 p->linktype = DLT_CHDLC;
1230 break;
1231
1232 case ERF_TYPE_ETH:
1233 case ERF_TYPE_COLOR_ETH:
1234 case ERF_TYPE_DSM_COLOR_ETH:
1235 case ERF_TYPE_COLOR_HASH_ETH:
1236 /*
1237 * This is (presumably) a real Ethernet capture; give it a
1238 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
1239 * that an application can let you choose it, in case you're
1240 * capturing DOCSIS traffic that a Cisco Cable Modem
1241 * Termination System is putting out onto an Ethernet (it
1242 * doesn't put an Ethernet header onto the wire, it puts raw
1243 * DOCSIS frames out on the wire inside the low-level
1244 * Ethernet framing).
1245 */
1246 if (p->dlt_list != NULL) {
1247 p->dlt_list[dlt_index++] = DLT_EN10MB;
1248 p->dlt_list[dlt_index++] = DLT_DOCSIS;
1249 }
1250 if(!p->linktype)
1251 p->linktype = DLT_EN10MB;
1252 break;
1253
1254 case ERF_TYPE_ATM:
1255 case ERF_TYPE_AAL5:
1256 case ERF_TYPE_MC_ATM:
1257 case ERF_TYPE_MC_AAL5:
1258 if (p->dlt_list != NULL) {
1259 p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
1260 p->dlt_list[dlt_index++] = DLT_SUNATM;
1261 }
1262 if(!p->linktype)
1263 p->linktype = DLT_ATM_RFC1483;
1264 break;
1265
1266 case ERF_TYPE_COLOR_MC_HDLC_POS:
1267 case ERF_TYPE_MC_HDLC:
1268 if (p->dlt_list != NULL) {
1269 p->dlt_list[dlt_index++] = DLT_CHDLC;
1270 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1271 p->dlt_list[dlt_index++] = DLT_FRELAY;
1272 p->dlt_list[dlt_index++] = DLT_MTP2;
1273 p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
1274 p->dlt_list[dlt_index++] = DLT_LAPD;
1275 }
1276 if(!p->linktype)
1277 p->linktype = DLT_CHDLC;
1278 break;
1279
1280 case ERF_TYPE_IPV4:
1281 if (p->dlt_list != NULL) {
1282 p->dlt_list[dlt_index++] = DLT_RAW;
1283 p->dlt_list[dlt_index++] = DLT_IPV4;
1284 }
1285 if(!p->linktype)
1286 p->linktype = DLT_RAW;
1287 break;
1288
1289 case ERF_TYPE_IPV6:
1290 if (p->dlt_list != NULL) {
1291 p->dlt_list[dlt_index++] = DLT_RAW;
1292 p->dlt_list[dlt_index++] = DLT_IPV6;
1293 }
1294 if(!p->linktype)
1295 p->linktype = DLT_RAW;
1296 break;
1297
1298 case ERF_TYPE_LEGACY:
1299 case ERF_TYPE_MC_RAW:
1300 case ERF_TYPE_MC_RAW_CHANNEL:
1301 case ERF_TYPE_IP_COUNTER:
1302 case ERF_TYPE_TCP_FLOW_COUNTER:
1303 case ERF_TYPE_INFINIBAND:
1304 case ERF_TYPE_RAW_LINK:
1305 case ERF_TYPE_INFINIBAND_LINK:
1306 case ERF_TYPE_META:
1307 default:
1308 /* Libpcap cannot deal with these types yet */
1309 /* Add no 'native' DLTs, but still covered by DLT_ERF */
1310 break;
1311
1312 } /* switch */
1313 index++;
1314 }
1315
1316 p->dlt_list[dlt_index++] = DLT_ERF;
1317
1318 p->dlt_count = dlt_index;
1319
1320 if(!p->linktype)
1321 p->linktype = DLT_ERF;
1322
1323 return p->linktype;
1324 }
1325
1326 #ifdef DAG_ONLY
1327 /*
1328 * This libpcap build supports only DAG cards, not regular network
1329 * interfaces.
1330 */
1331
1332 /*
1333 * There are no regular interfaces, just DAG interfaces.
1334 */
1335 int
1336 pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
1337 {
1338 return (0);
1339 }
1340
1341 /*
1342 * Attempts to open a regular interface fail.
1343 */
1344 pcap_t *
1345 pcap_create_interface(const char *device, char *errbuf)
1346 {
1347 pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1348 "This version of libpcap only supports DAG cards");
1349 return NULL;
1350 }
1351
1352 /*
1353 * Platform-specific information.
1354 */
1355 const char *
1356 pcap_platform_lib_version(void)
1357 {
1358 return ("DAG-only");
1359 }
1360 #endif