+ if((p->fd = dag_config_get_card_fd(pd->dag_ref)) < 0) {
+ /*
+ * XXX - does this reliably set errno?
+ */
+ ret = PCAP_ERROR;
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_config_get_card_fd %s", device);
+ goto failclose;
+ }
+
+ /* Open requested stream. Can fail if already locked or on error */
+ if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
+ ret = PCAP_ERROR;
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_attach_stream");
+ goto failclose;
+ }
+
+ /* Try to find Stream Drop attribute */
+ pd->drop_attr = kNullAttributeUuid;
+ pd->dag_root = dag_config_get_root_component(pd->dag_ref);
+ if ( dag_component_get_subcomponent(pd->dag_root, kComponentStreamFeatures, 0) )
+ {
+ pd->drop_attr = dag_config_get_indexed_attribute_uuid(pd->dag_ref, kUint32AttributeStreamDropCount, pd->dag_stream/2);
+ }
+
+ /* Set up default poll parameters for stream
+ * Can be overridden by pcap_set_nonblock()
+ */
+ if (dag_get_stream_poll64(p->fd, pd->dag_stream,
+ &mindata, &maxwait, &poll) < 0) {
+ ret = PCAP_ERROR;
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_get_stream_poll");
+ goto faildetach;
+ }
+
+ /* Use the poll time as the required select timeout for callers
+ * who are using select()/etc. in an event loop waiting for
+ * packets to arrive.
+ */
+ pd->required_select_timeout = poll;
+ p->required_select_timeout = &pd->required_select_timeout;
+
+ /*
+ * Turn a negative snapshot value (invalid), a snapshot value of
+ * 0 (unspecified), or a value bigger than the normal maximum
+ * value, into the maximum allowed value.
+ *
+ * If some application really *needs* a bigger snapshot
+ * length, we should just increase MAXIMUM_SNAPLEN.
+ */
+ if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
+ p->snapshot = MAXIMUM_SNAPLEN;
+
+ if (p->opt.immediate) {
+ /* Call callback immediately.
+ * XXX - is this the right way to p this?
+ */
+ mindata = 0;
+ } else {
+ /* Amount of data to collect in Bytes before calling callbacks.
+ * Important for efficiency, but can introduce latency
+ * at low packet rates if to_ms not set!
+ */
+ mindata = 65536;
+ }
+
+ /* Obey opt.timeout (was to_ms) if supplied. This is a good idea!
+ * Recommend 10-100ms. Calls will time out even if no data arrived.
+ */
+ maxwait.tv_sec = p->opt.timeout/1000;
+ maxwait.tv_usec = (p->opt.timeout%1000) * 1000;
+
+ if (dag_set_stream_poll64(p->fd, pd->dag_stream,
+ mindata, &maxwait, &poll) < 0) {
+ ret = PCAP_ERROR;
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_set_stream_poll");
+ goto faildetach;
+ }
+
+ /* XXX Not calling dag_configure() to set slen; this is unsafe in
+ * multi-stream environments as the gpp config is global.
+ * Once the firmware provides 'per-stream slen' this can be supported
+ * again via the Config API without side-effects */
+#if 0