]> The Tcpdump Group git mirrors - libpcap/blob - pcap-dag.c
Clean up the ether_hostton() stuff.
[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* p)
740 {
741 struct pcap_dag *pd = p->priv;
742 char *s;
743 int n;
744 daginf_t* daginf;
745 char * newDev = NULL;
746 char * device = p->opt.device;
747 dag_size_t mindata;
748 struct timeval maxwait;
749 struct timeval poll;
750
751 if (device == NULL) {
752 pcap_snprintf(p->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(p->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, &pd->dag_stream) < 0) {
765 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s", pcap_strerror(errno));
766 goto fail;
767 }
768 device = newDev;
769
770 if (pd->dag_stream%2) {
771 pcap_snprintf(p->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((p->fd = dag_open((char *)device)) < 0) {
777 pcap_snprintf(p->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(p->fd, pd->dag_stream, 0, 0) < 0) {
783 pcap_snprintf(p->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(p->fd, pd->dag_stream,
791 &mindata, &maxwait, &poll) < 0) {
792 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
793 goto faildetach;
794 }
795
796 /*
797 * Turn a negative snapshot value (invalid), a snapshot value of
798 * 0 (unspecified), or a value bigger than the normal maximum
799 * value, into the maximum allowed value.
800 *
801 * If some application really *needs* a bigger snapshot
802 * length, we should just increase MAXIMUM_SNAPLEN.
803 */
804 if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
805 p->snapshot = MAXIMUM_SNAPLEN;
806
807 if (p->opt.immediate) {
808 /* Call callback immediately.
809 * XXX - is this the right way to p this?
810 */
811 mindata = 0;
812 } else {
813 /* Amount of data to collect in Bytes before calling callbacks.
814 * Important for efficiency, but can introduce latency
815 * at low packet rates if to_ms not set!
816 */
817 mindata = 65536;
818 }
819
820 /* Obey opt.timeout (was to_ms) if supplied. This is a good idea!
821 * Recommend 10-100ms. Calls will time out even if no data arrived.
822 */
823 maxwait.tv_sec = p->opt.timeout/1000;
824 maxwait.tv_usec = (p->opt.timeout%1000) * 1000;
825
826 if (dag_set_stream_poll64(p->fd, pd->dag_stream,
827 mindata, &maxwait, &poll) < 0) {
828 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
829 goto faildetach;
830 }
831
832 /* XXX Not calling dag_configure() to set slen; this is unsafe in
833 * multi-stream environments as the gpp config is global.
834 * Once the firmware provides 'per-stream slen' this can be supported
835 * again via the Config API without side-effects */
836 #if 0
837 /* set the card snap length to the specified snaplen parameter */
838 /* This is a really bad idea, as different cards have different
839 * valid slen ranges. Should fix in Config API. */
840 if (p->snapshot == 0 || p->snapshot > MAX_DAG_SNAPLEN) {
841 p->snapshot = MAX_DAG_SNAPLEN;
842 } else if (snaplen < MIN_DAG_SNAPLEN) {
843 p->snapshot = MIN_DAG_SNAPLEN;
844 }
845 /* snap len has to be a multiple of 4 */
846 #endif
847
848 if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
849 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s", device, pcap_strerror(errno));
850 goto faildetach;
851 }
852
853 /*
854 * Important! You have to ensure bottom is properly
855 * initialized to zero on startup, it won't give you
856 * a compiler warning if you make this mistake!
857 */
858 pd->dag_mem_bottom = 0;
859 pd->dag_mem_top = 0;
860
861 /*
862 * Find out how many FCS bits we should strip.
863 * First, query the card to see if it strips the FCS.
864 */
865 daginf = dag_info(p->fd);
866 if ((0x4200 == daginf->device_code) || (0x4230 == daginf->device_code)) {
867 /* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
868 pd->dag_fcs_bits = 0;
869
870 /* Note that no FCS will be supplied. */
871 p->linktype_ext = LT_FCS_DATALINK_EXT(0);
872 } else {
873 /*
874 * Start out assuming it's 32 bits.
875 */
876 pd->dag_fcs_bits = 32;
877
878 /* Allow an environment variable to override. */
879 if ((s = getenv("ERF_FCS_BITS")) != NULL) {
880 if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
881 pd->dag_fcs_bits = n;
882 } else {
883 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
884 "pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
885 goto failstop;
886 }
887 }
888
889 /*
890 * Did the user request that they not be stripped?
891 */
892 if ((s = getenv("ERF_DONT_STRIP_FCS")) != NULL) {
893 /* Yes. Note the number of bytes that will be
894 supplied. */
895 p->linktype_ext = LT_FCS_DATALINK_EXT(pd->dag_fcs_bits/16);
896
897 /* And don't strip them. */
898 pd->dag_fcs_bits = 0;
899 }
900 }
901
902 pd->dag_timeout = p->opt.timeout;
903
904 p->linktype = -1;
905 if (dag_get_datalink(p) < 0)
906 goto failstop;
907
908 p->bufsize = 0;
909
910 if (new_pcap_dag(p) < 0) {
911 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "new_pcap_dag %s: %s", device, pcap_strerror(errno));
912 goto failstop;
913 }
914
915 /*
916 * "select()" and "poll()" don't work on DAG device descriptors.
917 */
918 p->selectable_fd = -1;
919
920 if (newDev != NULL) {
921 free((char *)newDev);
922 }
923
924 p->read_op = dag_read;
925 p->inject_op = dag_inject;
926 p->setfilter_op = dag_setfilter;
927 p->setdirection_op = NULL; /* Not implemented.*/
928 p->set_datalink_op = dag_set_datalink;
929 p->getnonblock_op = pcap_getnonblock_fd;
930 p->setnonblock_op = dag_setnonblock;
931 p->stats_op = dag_stats;
932 p->cleanup_op = dag_platform_cleanup;
933 pd->stat.ps_drop = 0;
934 pd->stat.ps_recv = 0;
935 pd->stat.ps_ifdrop = 0;
936 return 0;
937
938 failstop:
939 if (dag_stop_stream(p->fd, pd->dag_stream) < 0) {
940 fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
941 }
942
943 faildetach:
944 if (dag_detach_stream(p->fd, pd->dag_stream) < 0)
945 fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
946
947 failclose:
948 if (dag_close(p->fd) < 0)
949 fprintf(stderr,"dag_close: %s\n", strerror(errno));
950 delete_pcap_dag(p);
951
952 fail:
953 pcap_cleanup_live_common(p);
954 if (newDev != NULL) {
955 free((char *)newDev);
956 }
957
958 return PCAP_ERROR;
959 }
960
961 pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
962 {
963 const char *cp;
964 char *cpend;
965 long devnum;
966 pcap_t *p;
967 long stream = 0;
968
969 /* Does this look like a DAG device? */
970 cp = strrchr(device, '/');
971 if (cp == NULL)
972 cp = device;
973 /* Does it begin with "dag"? */
974 if (strncmp(cp, "dag", 3) != 0) {
975 /* Nope, doesn't begin with "dag" */
976 *is_ours = 0;
977 return NULL;
978 }
979 /* Yes - is "dag" followed by a number from 0 to DAG_MAX_BOARDS-1 */
980 cp += 3;
981 devnum = strtol(cp, &cpend, 10);
982 if (*cpend == ':') {
983 /* Followed by a stream number. */
984 stream = strtol(++cpend, &cpend, 10);
985 }
986
987 if (cpend == cp || *cpend != '\0') {
988 /* Not followed by a number. */
989 *is_ours = 0;
990 return NULL;
991 }
992
993 if (devnum < 0 || devnum >= DAG_MAX_BOARDS) {
994 /* Followed by a non-valid number. */
995 *is_ours = 0;
996 return NULL;
997 }
998
999 if (stream <0 || stream >= DAG_STREAM_MAX) {
1000 /* Followed by a non-valid stream number. */
1001 *is_ours = 0;
1002 return NULL;
1003 }
1004
1005 /* OK, it's probably ours. */
1006 *is_ours = 1;
1007
1008 p = pcap_create_common(ebuf, sizeof (struct pcap_dag));
1009 if (p == NULL)
1010 return NULL;
1011
1012 p->activate_op = dag_activate;
1013
1014 /*
1015 * We claim that we support microsecond and nanosecond time
1016 * stamps.
1017 *
1018 * XXX Our native precision is 2^-32s, but libpcap doesn't support
1019 * power of two precisions yet. We can convert to either MICRO or NANO.
1020 */
1021 p->tstamp_precision_count = 2;
1022 p->tstamp_precision_list = malloc(2 * sizeof(u_int));
1023 if (p->tstamp_precision_list == NULL) {
1024 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
1025 pcap_strerror(errno));
1026 pcap_close(p);
1027 return NULL;
1028 }
1029 p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
1030 p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
1031 return p;
1032 }
1033
1034 static int
1035 dag_stats(pcap_t *p, struct pcap_stat *ps) {
1036 struct pcap_dag *pd = p->priv;
1037
1038 /* This needs to be filled out correctly. Hopefully a dagapi call will
1039 provide all necessary information.
1040 */
1041 /*pd->stat.ps_recv = 0;*/
1042 /*pd->stat.ps_drop = 0;*/
1043
1044 *ps = pd->stat;
1045
1046 return 0;
1047 }
1048
1049 /*
1050 * Add all DAG devices.
1051 */
1052 int
1053 dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
1054 {
1055 char name[12]; /* XXX - pick a size */
1056 int ret = 0;
1057 int c;
1058 char dagname[DAGNAME_BUFSIZE];
1059 int dagstream;
1060 int dagfd;
1061 dag_card_inf_t *inf;
1062 char *description;
1063 int stream, rxstreams;
1064
1065 /* Try all the DAGs 0-DAG_MAX_BOARDS */
1066 for (c = 0; c < DAG_MAX_BOARDS; c++) {
1067 pcap_snprintf(name, 12, "dag%d", c);
1068 if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream))
1069 {
1070 (void) pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1071 "dag: device name %s can't be parsed", name);
1072 return -1;
1073 }
1074 if ( (dagfd = dag_open(dagname)) >= 0 ) {
1075 description = NULL;
1076 if ((inf = dag_pciinfo(dagfd)))
1077 description = dag_device_name(inf->device_code, 1);
1078 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1079 /*
1080 * Failure.
1081 */
1082 ret = -1;
1083 }
1084 rxstreams = dag_rx_get_stream_count(dagfd);
1085 for(stream=0;stream<DAG_STREAM_MAX;stream+=2) {
1086 if (0 == dag_attach_stream(dagfd, stream, 0, 0)) {
1087 dag_detach_stream(dagfd, stream);
1088
1089 pcap_snprintf(name, 10, "dag%d:%d", c, stream);
1090 if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
1091 /*
1092 * Failure.
1093 */
1094 ret = -1;
1095 }
1096
1097 rxstreams--;
1098 if(rxstreams <= 0) {
1099 break;
1100 }
1101 }
1102 }
1103 dag_close(dagfd);
1104 }
1105
1106 }
1107 return (ret);
1108 }
1109
1110 /*
1111 * Installs the given bpf filter program in the given pcap structure. There is
1112 * no attempt to store the filter in kernel memory as that is not supported
1113 * with DAG cards.
1114 */
1115 static int
1116 dag_setfilter(pcap_t *p, struct bpf_program *fp)
1117 {
1118 if (!p)
1119 return -1;
1120 if (!fp) {
1121 strncpy(p->errbuf, "setfilter: No filter specified",
1122 sizeof(p->errbuf));
1123 return -1;
1124 }
1125
1126 /* Make our private copy of the filter */
1127
1128 if (install_bpf_program(p, fp) < 0)
1129 return -1;
1130
1131 return (0);
1132 }
1133
1134 static int
1135 dag_set_datalink(pcap_t *p, int dlt)
1136 {
1137 p->linktype = dlt;
1138
1139 return (0);
1140 }
1141
1142 static int
1143 dag_setnonblock(pcap_t *p, int nonblock)
1144 {
1145 struct pcap_dag *pd = p->priv;
1146 dag_size_t mindata;
1147 struct timeval maxwait;
1148 struct timeval poll;
1149
1150 /*
1151 * Set non-blocking mode on the FD.
1152 * XXX - is that necessary? If not, don't bother calling it,
1153 * and have a "dag_getnonblock()" function that looks at
1154 * "pd->dag_flags".
1155 */
1156 if (pcap_setnonblock_fd(p, nonblock) < 0)
1157 return (-1);
1158
1159 if (dag_get_stream_poll64(p->fd, pd->dag_stream,
1160 &mindata, &maxwait, &poll) < 0) {
1161 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
1162 return -1;
1163 }
1164
1165 /* Amount of data to collect in Bytes before calling callbacks.
1166 * Important for efficiency, but can introduce latency
1167 * at low packet rates if to_ms not set!
1168 */
1169 if(nonblock)
1170 mindata = 0;
1171 else
1172 mindata = 65536;
1173
1174 if (dag_set_stream_poll64(p->fd, pd->dag_stream,
1175 mindata, &maxwait, &poll) < 0) {
1176 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
1177 return -1;
1178 }
1179
1180 if (nonblock) {
1181 pd->dag_flags |= DAGF_NONBLOCK;
1182 } else {
1183 pd->dag_flags &= ~DAGF_NONBLOCK;
1184 }
1185 return (0);
1186 }
1187
1188 static int
1189 dag_get_datalink(pcap_t *p)
1190 {
1191 struct pcap_dag *pd = p->priv;
1192 int index=0, dlt_index=0;
1193 uint8_t types[255];
1194
1195 memset(types, 0, 255);
1196
1197 if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
1198 (void)pcap_snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s", pcap_strerror(errno));
1199 return (-1);
1200 }
1201
1202 p->linktype = 0;
1203
1204 #ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
1205 /* Get list of possible ERF types for this card */
1206 if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
1207 pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
1208 return (-1);
1209 }
1210
1211 while (types[index]) {
1212
1213 #elif defined HAVE_DAG_GET_ERF_TYPES
1214 /* Get list of possible ERF types for this card */
1215 if (dag_get_erf_types(p->fd, types, 255) < 0) {
1216 pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
1217 return (-1);
1218 }
1219
1220 while (types[index]) {
1221 #else
1222 /* Check the type through a dagapi call. */
1223 types[index] = dag_linktype(p->fd);
1224
1225 {
1226 #endif
1227 switch((types[index] & 0x7f)) {
1228
1229 case ERF_TYPE_HDLC_POS:
1230 case ERF_TYPE_COLOR_HDLC_POS:
1231 case ERF_TYPE_DSM_COLOR_HDLC_POS:
1232 case ERF_TYPE_COLOR_HASH_POS:
1233
1234 if (p->dlt_list != NULL) {
1235 p->dlt_list[dlt_index++] = DLT_CHDLC;
1236 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1237 p->dlt_list[dlt_index++] = DLT_FRELAY;
1238 }
1239 if(!p->linktype)
1240 p->linktype = DLT_CHDLC;
1241 break;
1242
1243 case ERF_TYPE_ETH:
1244 case ERF_TYPE_COLOR_ETH:
1245 case ERF_TYPE_DSM_COLOR_ETH:
1246 case ERF_TYPE_COLOR_HASH_ETH:
1247 /*
1248 * This is (presumably) a real Ethernet capture; give it a
1249 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
1250 * that an application can let you choose it, in case you're
1251 * capturing DOCSIS traffic that a Cisco Cable Modem
1252 * Termination System is putting out onto an Ethernet (it
1253 * doesn't put an Ethernet header onto the wire, it puts raw
1254 * DOCSIS frames out on the wire inside the low-level
1255 * Ethernet framing).
1256 */
1257 if (p->dlt_list != NULL) {
1258 p->dlt_list[dlt_index++] = DLT_EN10MB;
1259 p->dlt_list[dlt_index++] = DLT_DOCSIS;
1260 }
1261 if(!p->linktype)
1262 p->linktype = DLT_EN10MB;
1263 break;
1264
1265 case ERF_TYPE_ATM:
1266 case ERF_TYPE_AAL5:
1267 case ERF_TYPE_MC_ATM:
1268 case ERF_TYPE_MC_AAL5:
1269 if (p->dlt_list != NULL) {
1270 p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
1271 p->dlt_list[dlt_index++] = DLT_SUNATM;
1272 }
1273 if(!p->linktype)
1274 p->linktype = DLT_ATM_RFC1483;
1275 break;
1276
1277 case ERF_TYPE_COLOR_MC_HDLC_POS:
1278 case ERF_TYPE_MC_HDLC:
1279 if (p->dlt_list != NULL) {
1280 p->dlt_list[dlt_index++] = DLT_CHDLC;
1281 p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
1282 p->dlt_list[dlt_index++] = DLT_FRELAY;
1283 p->dlt_list[dlt_index++] = DLT_MTP2;
1284 p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
1285 p->dlt_list[dlt_index++] = DLT_LAPD;
1286 }
1287 if(!p->linktype)
1288 p->linktype = DLT_CHDLC;
1289 break;
1290
1291 case ERF_TYPE_IPV4:
1292 if (p->dlt_list != NULL) {
1293 p->dlt_list[dlt_index++] = DLT_RAW;
1294 p->dlt_list[dlt_index++] = DLT_IPV4;
1295 }
1296 if(!p->linktype)
1297 p->linktype = DLT_RAW;
1298 break;
1299
1300 case ERF_TYPE_IPV6:
1301 if (p->dlt_list != NULL) {
1302 p->dlt_list[dlt_index++] = DLT_RAW;
1303 p->dlt_list[dlt_index++] = DLT_IPV6;
1304 }
1305 if(!p->linktype)
1306 p->linktype = DLT_RAW;
1307 break;
1308
1309 case ERF_TYPE_LEGACY:
1310 case ERF_TYPE_MC_RAW:
1311 case ERF_TYPE_MC_RAW_CHANNEL:
1312 case ERF_TYPE_IP_COUNTER:
1313 case ERF_TYPE_TCP_FLOW_COUNTER:
1314 case ERF_TYPE_INFINIBAND:
1315 case ERF_TYPE_RAW_LINK:
1316 case ERF_TYPE_INFINIBAND_LINK:
1317 case ERF_TYPE_META:
1318 default:
1319 /* Libpcap cannot deal with these types yet */
1320 /* Add no 'native' DLTs, but still covered by DLT_ERF */
1321 break;
1322
1323 } /* switch */
1324 index++;
1325 }
1326
1327 p->dlt_list[dlt_index++] = DLT_ERF;
1328
1329 p->dlt_count = dlt_index;
1330
1331 if(!p->linktype)
1332 p->linktype = DLT_ERF;
1333
1334 return p->linktype;
1335 }
1336
1337 #ifdef DAG_ONLY
1338 /*
1339 * This libpcap build supports only DAG cards, not regular network
1340 * interfaces.
1341 */
1342
1343 /*
1344 * There are no regular interfaces, just DAG interfaces.
1345 */
1346 int
1347 pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
1348 {
1349 return (0);
1350 }
1351
1352 /*
1353 * Attempts to open a regular interface fail.
1354 */
1355 pcap_t *
1356 pcap_create_interface(const char *device, char *errbuf)
1357 {
1358 pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
1359 "This version of libpcap only supports DAG cards");
1360 return NULL;
1361 }
1362
1363 #include "pcap_version.h"
1364
1365 /*
1366 * Libpcap version string.
1367 */
1368 const char *
1369 pcap_lib_version(void)
1370 {
1371 return (PCAP_VERSION_STRING " (DAG-only)");
1372 }
1373 #endif