From 0703c7b4145f1ec23172b261356ca65bb17d12dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Thu, 22 Sep 2016 13:23:37 +0200 Subject: dumpcap: Include CPU info as hardware description in SHB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- wsutil/CMakeLists.txt | 1 + wsutil/Makefile.am | 2 ++ wsutil/cpu_info.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ wsutil/cpu_info.h | 40 ++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 wsutil/cpu_info.c create mode 100644 wsutil/cpu_info.h (limited to 'wsutil') diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index c992a8be0e..2f71d0fc72 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -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 diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am index 1fb0cc9854..6f104b51f2 100644 --- a/wsutil/Makefile.am +++ b/wsutil/Makefile.am @@ -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 index 0000000000..9a3416d9ab --- /dev/null +++ b/wsutil/cpu_info.c @@ -0,0 +1,80 @@ +/* cpu_info.c + * Routines to report CPU information + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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 +#include + +#include +#include + +/* + * 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 index 0000000000..74fca1f783 --- /dev/null +++ b/wsutil/cpu_info.h @@ -0,0 +1,40 @@ +/* cpu_info.h + * Declarations of routines to report CPU information + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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__ */ -- cgit v1.2.1