⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioctlnqgs.c

📁 macaddrsdk的驱动程序 macaddrsdk的驱动程序
💻 C
字号:
/////////////////////////////////////////////////////////////////////////////
//// INCLUDE FILES

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winioctl.h>
#include "ntddndis.h"        // This defines the IOCTL constants.

#include "IoctlNQGS.h"

// Copyright And Configuration Management ----------------------------------
//
//       IOCTL NDIS Query Global Statistics (NQGS) Module - IoctlNQGS.c
//                                    For
//                         Windows NT And Windows 2000
//
//        Copyright (c) 2000 Printing Communications Associates, Inc.
//                                - PCAUSA -
//                         <http://www.pcausa.com>
//
//                             Thomas F. Divine
//                           4201 Brunswick Court
//                        Smyrna, Georgia 30080 USA
//                              (770) 432-4580
//
//                       <mailto:tdivine@pcausa.com>
// 
// End ---------------------------------------------------------------------

#define DEVICE_PREFIX   "\\\\.\\"

/////////////////////////////////////////////////////////////////////////////
//// MAII_IoctlNdisQueryGlobalStats
//
// Purpose
//
// Parameters
//   lpAdapterName
//      This is the "MS-DOS Device Name" of the adapter. The name is
//      different on Windows NT and Windows 2000. Here are examples:
//
//         Windows NT   -> "El90x1"
//         Windows 2000 -> "{A5961EBF-F7D6-4F26-A9F3-4E817A884CD1}"
//
// Return Value
//
// Remarks
//

DWORD
MAII_IoctlNdisQueryGlobalStats(
   LPCTSTR  lpAdapterName,
   ULONG    OidCode,
   PVOID    InformationBuffer,
   UINT     InformationBufferLength,
   PUINT    pBytesWritten
   )
{
   UCHAR       LinkName[512];
   UCHAR       szMACFileName[512];
   BOOLEAN     bCreatedDevice = FALSE;
   DWORD       ErrorNumber, nResult = ERROR_SUCCESS;
   HANDLE      hMAC;

   printf( "Query For OID 0x%8.8X On MS-DOS Device Name: \042%s\042\n",
      OidCode, lpAdapterName
      );

   *pBytesWritten = 0;

   //
   // Check to see if the DOS name for the MAC driver already exists.
   // Its not created automatically in version 3.1 but may be later.
   //
   if (QueryDosDevice(lpAdapterName, LinkName, sizeof(LinkName)) == 0)
   {
      if ((ErrorNumber = GetLastError()) == ERROR_FILE_NOT_FOUND)
      {
         printf( "DOS Device Name Does Not Exist. Creating...\n" );

         strcpy( LinkName, "\\Device\\" );
         strcat( LinkName, lpAdapterName );

         //
         // It doesn't exist so create it.
         //
         if (!DefineDosDevice(
               DDD_RAW_TARGET_PATH,
               lpAdapterName,
               LinkName
               )
            )
         {
            ErrorNumber = GetLastError();

            printf(
               "DefineDosDevice returned an error creating the device = %d\n",
               ErrorNumber
               );

            nResult = ErrorNumber;
         }
         else
         {
            bCreatedDevice = TRUE;
         }
      }
      else
      {
         printf("QueryDosDevice returned an error = %d\n", ErrorNumber );
         nResult = ErrorNumber;
      }
   }
   else
   {
      printf( "   DOS Device Name Existed.\n" );
   }

   if( nResult != ERROR_SUCCESS )
   {
      return( nResult );
   }

   printf( "   LinkName: \042%s\042\n", LinkName );

   //
   // Construct a device name to pass to CreateFile
   //
   strcpy(szMACFileName, DEVICE_PREFIX);
   strcat(szMACFileName, lpAdapterName);

   hMAC = CreateFile(
                szMACFileName,
                0,      // Device Query Access
                FILE_SHARE_READ,
                NULL,
                OPEN_EXISTING,
                0,
                INVALID_HANDLE_VALUE
                );

    if (hMAC != INVALID_HANDLE_VALUE)
    {
        //
        // We successfully opened the driver, format the IOCTL to pass the
        // driver.
        //
        if( !DeviceIoControl(
                hMAC,
                IOCTL_NDIS_QUERY_GLOBAL_STATS,
                &OidCode,
                sizeof(OidCode),
                InformationBuffer,
                InformationBufferLength,
                pBytesWritten,
                NULL
                )
            )
        {
            printf("   DeviceIoControl returned an error = %d\n",
               nResult = GetLastError());
        }
    }
    else
    {
      printf("   CreateFile returned an error = %d\n",
         nResult = GetLastError());
    }

   if (bCreatedDevice)
   {
      //
      // The MAC driver wasn't visible in the Win32 name space so we created
      // a link.  Now we have to delete it.
      //
      if (!DefineDosDevice(
            DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION |
            DDD_EXACT_MATCH_ON_REMOVE,
            lpAdapterName,
            LinkName
            )
         )
      {
         ErrorNumber = GetLastError();

         printf(
            "   DefineDosDevice returned an error creating the device = %d\n",
            ErrorNumber
            );

         return( ErrorNumber );
      }
    }
    
   return( nResult );
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -