"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/src/agent/tools/nxhwid/nxhwid.cpp" (23 Feb 2021, 2160 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nxhwid.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.6.300_vs_3.7.95.

    1 /* 
    2 ** nxhwid - diplay local system hardware ID
    3 ** Copyright (C) 2006-2020 Raden Solutions
    4 **
    5 ** This program is free software; you can redistribute it and/or modify
    6 ** it under the terms of the GNU General Public License as published by
    7 ** the Free Software Foundation; either version 2 of the License, or
    8 ** (at your option) any later version.
    9 **
   10 ** This program is distributed in the hope that it will be useful,
   11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 ** GNU General Public License for more details.
   14 **
   15 ** You should have received a copy of the GNU General Public License
   16 ** along with this program; if not, write to the Free Software
   17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18 **
   19 **/
   20 
   21 #include <nms_common.h>
   22 #include <nms_agent.h>
   23 #include <nms_util.h>
   24 #include <netxms_getopt.h>
   25 #include <netxms-version.h>
   26 
   27 NETXMS_EXECUTABLE_HEADER(nxhwid)
   28 
   29 #if defined(__FreeBSD__)
   30 #include "../../smbios/freebsd.cpp"
   31 #elif defined(__linux__)
   32 #include "../../smbios/linux.cpp"
   33 #elif defined(__sun)
   34 #include "../../smbios/solaris.cpp"
   35 #elif defined(_WIN32)
   36 #include "../../smbios/windows.cpp"
   37 #else
   38 static BYTE *SMBIOS_Reader(size_t *size)
   39 {
   40    return nullptr;
   41 }
   42 #endif
   43 
   44 /**
   45  * Debug writer
   46  */
   47 static void DebugWriter(const TCHAR *tag, const TCHAR *format, va_list args)
   48 {
   49    if (tag != nullptr)
   50       _tprintf(_T("%s: "), tag);
   51    _vtprintf(format, args);
   52    _tprintf(_T("\n"));
   53 }
   54 
   55 /**
   56  * Entry point
   57  */
   58 int main(int argc, char *argv[])
   59 {
   60    InitNetXMSProcess(true);
   61 
   62    int ch;
   63    while((ch = getopt(argc, argv, "Dh")) != -1)
   64    {
   65       if (ch == 'D')
   66       {
   67          nxlog_set_debug_level(9);
   68          nxlog_set_debug_writer(DebugWriter);
   69       }
   70       else
   71       {
   72          _tprintf(_T("Usage: nxhwid [-D]\n"));
   73          return 1;
   74       }
   75    }
   76 
   77    SMBIOS_Parse(SMBIOS_Reader);
   78 
   79    int rc;
   80    BYTE hwid[HARDWARE_ID_LENGTH];
   81    if (GetSystemHardwareId(hwid))
   82    {
   83       TCHAR buffer[128];
   84       _tprintf(_T("%s\n"), BinToStr(hwid, sizeof(hwid), buffer));
   85       rc = 0;
   86    }
   87    else
   88    {
   89       _tprintf(_T("ERROR\n"));
   90       rc = 1;
   91    }
   92     
   93    return rc;
   94 }