dumpcap: Include CPU info as hardware description in SHB
authorStig Bjørlykke <stig@bjorlykke.org>
Thu, 22 Sep 2016 11:23:37 +0000 (13:23 +0200)
committerStig Bjørlykke <stig@bjorlykke.org>
Fri, 23 Sep 2016 08:13:43 +0000 (08:13 +0000)
Add CPU info as hardware description in session header block when
using pcapng.

Use capture_comment from the capture_options structure when using
ring buffer.

Change-Id: I5e688fc2d6ab61de1f64ad9a8a96e6e39e8cf708
Reviewed-on: https://code.wireshark.org/review/17862
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
debian/libwsutil0.symbols
dumpcap.c
ws_version_info.c
wsutil/CMakeLists.txt
wsutil/Makefile.am
wsutil/cpu_info.c [new file with mode: 0644]
wsutil/cpu_info.h [new file with mode: 0644]

index 0bc96889f84b64609d90f6dab67ab43a4bd47f6c..5224d04f7af8caa056fb27c2da6c660f5b0bf640 100644 (file)
@@ -58,6 +58,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
  get_copyright_info@Base 1.99.0
  get_cur_groupname@Base 1.10.0
  get_cur_username@Base 1.10.0
+ get_cpu_info@Base 2.3.0
  get_datafile_dir@Base 1.12.0~rc1
  get_datafile_path@Base 1.12.0~rc1
  get_dirname@Base 1.12.0~rc1
index 07aa89bf785d1886f65a2477c404165638467b39..be1910fd24d561d2521642dc1c3e4872199d3329 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
 #include "wsutil/tempfile.h"
 #include "log.h"
 #include "wsutil/file_util.h"
+#include "wsutil/cpu_info.h"
 #include "wsutil/os_version_info.h"
 #include "wsutil/str_util.h"
 #include "wsutil/inet_addr.h"
@@ -2412,16 +2413,19 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
     if (ld->pdh) {
         if (capture_opts->use_pcapng) {
             char    *appname;
+            GString *cpu_info_str;
             GString *os_info_str;
 
+            cpu_info_str = g_string_new("");
             os_info_str = g_string_new("");
+            get_cpu_info(cpu_info_str);
             get_os_version_info(os_info_str);
 
             appname = g_strdup_printf("Dumpcap (Wireshark) %s", get_ws_vcs_version_info());
             successful = pcapng_write_session_header_block(ld->pdh,
-                                (const char *)capture_opts->capture_comment,   /* Comment*/
-                                NULL,                        /* HW*/
-                                os_info_str->str,            /* OS*/
+                                (const char *)capture_opts->capture_comment,   /* Comment */
+                                cpu_info_str->str,           /* HW */
+                                os_info_str->str,            /* OS */
                                 appname,
                                 -1,                          /* section_length */
                                 &ld->bytes_written,
@@ -2911,18 +2915,21 @@ do_file_switch_or_stop(capture_options *capture_opts,
             global_ld.bytes_written = 0;
             if (capture_opts->use_pcapng) {
                 char    *appname;
+                GString *cpu_info_str;
                 GString *os_info_str;
 
+                cpu_info_str = g_string_new("");
                 os_info_str = g_string_new("");
+                get_cpu_info(cpu_info_str);
                 get_os_version_info(os_info_str);
 
                 appname = g_strdup_printf("Dumpcap (Wireshark) %s", get_ws_vcs_version_info());
                 successful = pcapng_write_session_header_block(global_ld.pdh,
-                                NULL,                        /* Comment */
-                                NULL,                        /* HW */
+                                (const char *)capture_opts->capture_comment,   /* Comment */
+                                cpu_info_str->str,           /* HW */
                                 os_info_str->str,            /* OS */
                                 appname,
-                                                                -1,                          /* section_length */
+                                -1,                          /* section_length */
                                 &(global_ld.bytes_written),
                                 &global_ld.err);
                 g_free(appname);
index 036956aa7b01fe0554ce7b1434b1ca10550164af..436d33248ab4721976402be9f06a22d0b3d81927 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "ws_version_info.h"
 
-#include <wsutil/ws_cpuid.h>
+#include <wsutil/cpu_info.h>
 #include <wsutil/copyright_info.h>
 #include <wsutil/os_version_info.h>
 #include <wsutil/ws_printf.h> /* ws_debug_printf */
@@ -143,42 +143,6 @@ get_compiled_version_info(void (*prepend_info)(GString *),
        return str;
 }
 
-/*
- * Get the CPU info, and append it to the GString
- */
-static void
-get_cpu_info(GString *str)
-{
-       guint32 CPUInfo[4];
-       char CPUBrandString[0x40];
-       unsigned nExIds;
-
-       /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */
-
-       /* Calling __cpuid with 0x80000000 as the InfoType argument*/
-       /* gets the number of valid extended IDs.*/
-       if (!ws_cpuid(CPUInfo, 0x80000000))
-               return;
-       nExIds = CPUInfo[0];
-
-       if( nExIds<0x80000005)
-               return;
-       memset(CPUBrandString, 0, sizeof(CPUBrandString));
-
-       /* Interpret CPU brand string.*/
-       ws_cpuid(CPUInfo, 0x80000002);
-       memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
-       ws_cpuid(CPUInfo, 0x80000003);
-       memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
-       ws_cpuid(CPUInfo, 0x80000004);
-       memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
-
-       g_string_append_printf(str, "\n%s", CPUBrandString);
-
-       if (ws_cpuid_sse42())
-               g_string_append(str, " (with SSE4.2)");
-}
-
 static void
 get_mem_info(GString *str _U_)
 {
@@ -356,7 +320,7 @@ get_runtime_version_info(void (*additional_info)(GString *))
        g_string_append_printf(str, ", with zlib %s", zlibVersion());
 #endif
 
-       g_string_append(str, ".");
+       g_string_append(str, ".\n");
 
        /* CPU Info */
        get_cpu_info(str);
index c992a8be0e0992036766a558b2a3c19b23dfbcb6..2f71d0fc727376d37eb633392250f6a8f70e9ab0 100644 (file)
@@ -52,6 +52,7 @@ set(WSUTIL_COMMON_FILES
        md5.c
        mpeg-audio.c
        nstime.c
+       cpu_info.c
        os_version_info.c
        plugins.c
        privileges.c
index 1fb0cc9854a52ad0cd2e767b7b4c64cd49584a6a..6f104b51f21d3158cf073b13512e2804e98a8344 100644 (file)
@@ -47,6 +47,7 @@ libwsutil_nonrepl_INCLUDES = \
        clopts_common.h         \
        cmdarg_err.h            \
        copyright_info.h        \
+       cpu_info.h              \
        crash_info.h            \
        crc6.h                  \
        crc7.h                  \
@@ -121,6 +122,7 @@ libwsutil_la_SOURCES = \
        clopts_common.c         \
        cmdarg_err.c            \
        copyright_info.c        \
+       cpu_info.c              \
        crash_info.c            \
        crc6.c                  \
        crc7.c                  \
diff --git a/wsutil/cpu_info.c b/wsutil/cpu_info.c
new file mode 100644 (file)
index 0000000..9a3416d
--- /dev/null
@@ -0,0 +1,80 @@
+/* cpu_info.c
+ * Routines to report CPU information
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <glib.h>
+
+#include <wsutil/ws_cpuid.h>
+#include <wsutil/cpu_info.h>
+
+/*
+ * Get the CPU info, and append it to the GString
+ */
+void
+get_cpu_info(GString *str)
+{
+    guint32 CPUInfo[4];
+    char CPUBrandString[0x40];
+    unsigned nExIds;
+
+    /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */
+
+    /* Calling __cpuid with 0x80000000 as the InfoType argument */
+    /* gets the number of valid extended IDs. */
+    if (!ws_cpuid(CPUInfo, 0x80000000))
+        return;
+
+    nExIds = CPUInfo[0];
+
+    if (nExIds<0x80000005)
+        return;
+
+    memset(CPUBrandString, 0, sizeof(CPUBrandString));
+
+    /* Interpret CPU brand string */
+    ws_cpuid(CPUInfo, 0x80000002);
+    memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
+    ws_cpuid(CPUInfo, 0x80000003);
+    memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
+    ws_cpuid(CPUInfo, 0x80000004);
+    memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
+
+    g_string_append_printf(str, "%s", CPUBrandString);
+
+    if (ws_cpuid_sse42())
+        g_string_append(str, " (with SSE4.2)");
+}
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/wsutil/cpu_info.h b/wsutil/cpu_info.h
new file mode 100644 (file)
index 0000000..74fca1f
--- /dev/null
@@ -0,0 +1,40 @@
+/* cpu_info.h
+ * Declarations of routines to report CPU information
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __WSUTIL_CPU_INFO_H__
+#define __WSUTIL_CPU_INFO_H__
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "ws_symbol_export.h"
+
+WS_DLL_PUBLIC void get_cpu_info(GString *str);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __WSUTIL_CPU_INFO_H__ */