]> The Tcpdump Group git mirrors - libpcap/commitdiff
From Stephen Donnelly:
authorguy <guy>
Thu, 4 Oct 2007 23:06:25 +0000 (23:06 +0000)
committerguy <guy>
Thu, 4 Oct 2007 23:06:25 +0000 (23:06 +0000)
     * Improved error checking in dag_read().
     * More efficient dag_platform_finddevs().
     * Support for new DAG API function dag_get_stream_erf_types().

config.h.in
configure
configure.in
pcap-dag.c

index 2557748691d2c3e996330707943217b1d0a0e837..7a397587ded6a073f0c6ff51ad8544ad0a14bf14 100644 (file)
@@ -19,6 +19,9 @@
 /* define if you have dag_get_erf_types() */
 #undef HAVE_DAG_GET_ERF_TYPES
 
+/* define if you have dag_get_stream_erf_types() */
+#undef HAVE_DAG_GET_STREAM_ERF_TYPES
+
 /* define if you have streams capable DAG API */
 #undef HAVE_DAG_STREAMS_API
 
index 37736cf0213077126bfb24aa799942e509e488c2..f2a0f93a28873d40a990a0e5357d23e68043d2c6 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.137 .
+# From configure.in Revision: 1.138 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61.
 #
@@ -6730,6 +6730,75 @@ cat >>confdefs.h <<\_ACEOF
 #define HAVE_DAG_GET_ERF_TYPES 1
 _ACEOF
 
+fi
+
+       { echo "$as_me:$LINENO: checking for dag_get_stream_erf_types in -ldag" >&5
+echo $ECHO_N "checking for dag_get_stream_erf_types in -ldag... $ECHO_C" >&6; }
+if test "${ac_cv_lib_dag_dag_get_stream_erf_types+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldag  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dag_get_stream_erf_types ();
+int
+main ()
+{
+return dag_get_stream_erf_types ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_dag_dag_get_stream_erf_types=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_cv_lib_dag_dag_get_stream_erf_types=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_dag_dag_get_stream_erf_types" >&5
+echo "${ECHO_T}$ac_cv_lib_dag_dag_get_stream_erf_types" >&6; }
+if test $ac_cv_lib_dag_dag_get_stream_erf_types = yes; then
+
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_DAG_GET_STREAM_ERF_TYPES 1
+_ACEOF
 
 fi
 
index dc6db127cdfff48a0f2ced317b68688b93c3c018..2e1eb8a1533bdbc2f1bca94a039bf5df215868e1 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.137 2007-09-12 19:09:50 guy Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.138 2007-10-04 23:06:25 guy Exp $ (LBL)
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
@@ -6,7 +6,7 @@ dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl
 
-AC_REVISION($Revision: 1.137 $)
+AC_REVISION($Revision: 1.138 $)
 AC_PREREQ(2.50)
 AC_INIT(pcap.c)
 
@@ -592,8 +592,9 @@ if test $ac_cv_lbl_dag_api = yes; then
        LDFLAGS="-L$dag_lib_dir"
        AC_CHECK_LIB([dag], [dag_attach_stream], [dag_version="2.5.x"], [dag_version="2.4.x"])
        AC_CHECK_LIB([dag],[dag_get_erf_types], [
-               AC_DEFINE(HAVE_DAG_GET_ERF_TYPES, 1, [define if you have dag_get_erf_types()])]
-       )
+               AC_DEFINE(HAVE_DAG_GET_ERF_TYPES, 1, [define if you have dag_get_erf_types()])])
+       AC_CHECK_LIB([dag],[dag_get_stream_erf_types], [
+               AC_DEFINE(HAVE_DAG_GET_STREAM_ERF_TYPES, 1, [define if you have dag_get_stream_erf_types()])])
        LDFLAGS=$saved_ldflags
 
        if test "$dag_version" = 2.5.x; then
index 86df4f68aaa698cce65530bd021fbe91a4eb4aa6..900faa9447a8419764e0ccd5a60a236a5bbc6312 100644 (file)
@@ -17,7 +17,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-       "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.30 2007-09-29 19:33:29 guy Exp $ (LBL)";
+       "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.31 2007-10-04 23:06:25 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -220,7 +220,9 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                 * If non-block is specified it will return immediately. The user
                 * is then responsible for efficiency.
                 */
-               p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, &(p->md.dag_mem_bottom));
+               if ( NULL == (p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, &(p->md.dag_mem_bottom))) ) {
+                    return -1;
+               }
 #else
                /* dag_offset does not support timeouts */
                p->md.dag_mem_top = dag_offset(p->fd, &(p->md.dag_mem_bottom), flags);
@@ -783,10 +785,13 @@ dag_stats(pcap_t *p, struct pcap_stat *ps) {
 }
 
 /*
- * Simply submit all possible dag names as candidates.
- * pcap_add_if() internally tests each candidate with pcap_open_live(),
- * so any non-existent devices are dropped.
- * For 2.5 try all rx stream names as well.
+ * Previously we just generated a list of all possible names and let
+ * pcap_add_if() attempt to open each one, but with streams this adds up
+ * to 81 possibilities which is inefficient.
+ *
+ * Since we know more about the devices we can prune the tree here.
+ * pcap_add_if() will still retest each device but the total number of
+ * open attempts will still be much less than the naive approach.
  */
 int
 dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
@@ -794,30 +799,46 @@ dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
        char name[12];  /* XXX - pick a size */
        int ret = 0;
        int c;
+       char dagname[DAGNAME_BUFSIZE];
+       int dagstream;
+       int dagfd;
 
        /* Try all the DAGs 0-9 */
        for (c = 0; c < 9; c++) {
                snprintf(name, 12, "dag%d", c);
-               if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
-                       /*
-                        * Failure.
-                        */
-                       ret = -1;
-               }
-#ifdef HAVE_DAG_STREAMS_API
+               if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream))
                {
-                       int stream;
-                       for(stream=0;stream<16;stream+=2) {
-                               snprintf(name,  10, "dag%d:%d", c, stream);
-                               if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
-                                       /*
-                                        * Failure.
-                                        */
-                                       ret = -1;
-                               }
-                       }                               
+                       return -1;
                }
+               if ( (dagfd = dag_open(dagname)) >= 0 ) {
+                       if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
+                               /*
+                                * Failure.
+                                */
+                               ret = -1;
+                       }
+#ifdef HAVE_DAG_STREAMS_API
+                       {
+                               int stream, rxstreams, found=0;
+                               rxstreams = dag_rx_get_stream_count(dagfd);
+                               for(stream=0;stream<16;stream+=2) {
+                                       if (0 == dag_attach_stream(dagfd, stream, 0, 0)) {
+                                               dag_detach_stream(dagfd, stream);
+
+                                               snprintf(name,  10, "dag%d:%d", c, stream);
+                                               if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
+                                                       /*
+                                                        * Failure.
+                                                        */
+                                                       ret = -1;
+                                               }
+                                       }
+                               }                               
+                       }
 #endif  /* HAVE_DAG_STREAMS_API */
+                       dag_close(dagfd);
+               }
+
        }
        return (ret);
 }
@@ -906,7 +927,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
 static int
 dag_get_datalink(pcap_t *p)
 {
-       int index=0;
+       int index=0, dlt_index=0;
        uint8_t types[255];
 
        memset(types, 0, 255);
@@ -918,7 +939,16 @@ dag_get_datalink(pcap_t *p)
 
        p->linktype = 0;
 
-#ifdef HAVE_DAG_GET_ERF_TYPES
+#ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
+       /* Get list of possible ERF types for this card */
+       if (dag_get_stream_erf_types(p->fd, p->md.dag_stream, types, 255) < 0) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
+               return (-1);            
+       }
+       
+       while (types[index]) {
+
+#elif defined HAVE_DAG_GET_ERF_TYPES
        /* Get list of possible ERF types for this card */
        if (dag_get_erf_types(p->fd, types, 255) < 0) {
                snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
@@ -942,9 +972,9 @@ dag_get_datalink(pcap_t *p)
                case TYPE_DSM_COLOR_HDLC_POS:
 #endif
                        if (p->dlt_list != NULL) {
-                               p->dlt_list[index++] = DLT_CHDLC;
-                               p->dlt_list[index++] = DLT_PPP_SERIAL;
-                               p->dlt_list[index++] = DLT_FRELAY;
+                               p->dlt_list[dlt_index++] = DLT_CHDLC;
+                               p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
+                               p->dlt_list[dlt_index++] = DLT_FRELAY;
                        }
                        if(!p->linktype)
                                p->linktype = DLT_CHDLC;
@@ -968,8 +998,8 @@ dag_get_datalink(pcap_t *p)
                         * Ethernet framing).
                         */
                        if (p->dlt_list != NULL) {
-                               p->dlt_list[index++] = DLT_EN10MB;
-                               p->dlt_list[index++] = DLT_DOCSIS;
+                               p->dlt_list[dlt_index++] = DLT_EN10MB;
+                               p->dlt_list[dlt_index++] = DLT_DOCSIS;
                        }
                        if(!p->linktype)
                                p->linktype = DLT_EN10MB;
@@ -986,8 +1016,8 @@ dag_get_datalink(pcap_t *p)
                case TYPE_MC_AAL5:
 #endif
                        if (p->dlt_list != NULL) {
-                               p->dlt_list[index++] = DLT_ATM_RFC1483;
-                               p->dlt_list[index++] = DLT_SUNATM;
+                               p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
+                               p->dlt_list[dlt_index++] = DLT_SUNATM;
                        }
                        if(!p->linktype)
                                p->linktype = DLT_ATM_RFC1483;
@@ -999,11 +1029,11 @@ dag_get_datalink(pcap_t *p)
 #ifdef TYPE_MC_HDLC
                case TYPE_MC_HDLC:
                        if (p->dlt_list != NULL) {
-                               p->dlt_list[index++] = DLT_CHDLC;
-                               p->dlt_list[index++] = DLT_PPP_SERIAL;
-                               p->dlt_list[index++] = DLT_FRELAY;
-                               p->dlt_list[index++] = DLT_MTP2;
-                               p->dlt_list[index++] = DLT_MTP2_WITH_PHDR;
+                               p->dlt_list[dlt_index++] = DLT_CHDLC;
+                               p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
+                               p->dlt_list[dlt_index++] = DLT_FRELAY;
+                               p->dlt_list[dlt_index++] = DLT_MTP2;
+                               p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
                        }
                        if(!p->linktype)
                                p->linktype = DLT_CHDLC;
@@ -1020,9 +1050,10 @@ dag_get_datalink(pcap_t *p)
                        return (-1);
 
                } /* switch */
+               index++;
        }
 
-       p->dlt_count = index;
+       p->dlt_count = dlt_index;
 
        return p->linktype;
 }