基于ndis的防火墙源码供大家赏析firewall c

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

 #include "precomp.h"
#pragma hdrstop

#pragma NDIS_INIT_FUNCTION(DriverEntry)

NDIS_PHYSICAL_ADDRESS         HighestAcceptableMax = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);

NDIS_MEDIUM                           MediumArray[3] =
                                         {
                                        NdisMedium802_3,      // Ethernet
                                            NdisMedium802_5,      // Token-ring
                                        NdisMediumFddi            // Fddi
                                         };

//
// g_GlobalLock - Protects resources
//
NDIS_SPIN_LOCK         g_GlobalLock;

//
// g_ProtocolHandle - handle returned by NDIS when registering the protocol portion of the IM
//
NDIS_HANDLE                           g_ProtocolHandle = NULL;

//
// g_MiniportHandle - handle returned by NDIS when MP portion registers as LM
//
NDIS_HANDLE                           g_MiniportHandle   = NULL;

//
// g_AdapterList - List of adapters to which the NetWall is bound
//
PADAPT               g_AdapterList     = NULL;

//
// g_DriverObject - pointer to NT driver and device objects
//
PDRIVER_OBJECT         g_DriverObject     = NULL;


/**
* Routine Description:
*
*   This is the primary initialization routine for the NetWall IM driver.
*   It is simply responsible for the intializing the wrapper and registering
*   the Miniport and Protocol driver.
*
* Arguments:
*
*       IN DriverObject - Pointer to driver object created by the system.
*   IN RegistryPath - Registry path string for driver service key
*
* Return Value:
*
*   The status of the operation.
*/
NTSTATUS
DriverEntry(
     IN      PDRIVER_OBJECT            DriverObject,
     IN      PUNICODE_STRING            RegistryPath
     )
{
     NDIS_STATUS                                    Status;
     NDIS_PROTOCOL_CHARACTERISTICS      PChars;
     NDIS_MINIPORT_CHARACTERISTICS      MChars;
     NDIS_STRING               protoName;      
  UNICODE_STRING             ntDeviceName;
  UNICODE_STRING             win32DeviceName;
     NDIS_HANDLE                                    WrapperHandle;
  UINT                   FuncIndex   = 0;

  DBGPRINT("===> NetWall - DriverEntry/n");
 
  DbgPrint("=== RegistryPath is : %ws ===/n", RegistryPath->Buffer);

  g_DriverObject = DriverObject;

  //
  // Initialize Global Lock
  //
  NdisAllocateSpinLock(&g_GlobalLock);  

  do
  {
        //
    // 1. Register the miniport with NDIS. Note that it is the miniport
        //   which was started as a driver and not the protocol. Also the miniport
        //   must be registered prior to the protocol since the protocol's BindAdapter
        //   handler can be initiated anytime and when it is, it must be ready to
        //   start driver instances.
        //
        NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);

    //
    // 2. Perform IM Driver's Miniport Initialization
    //
        NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS));

        MChars.MajorNdisVersion       = 4;
        MChars.MinorNdisVersion       = 0;

        MChars.InitializeHandler     = MPInitialize;
        MChars.QueryInformationHandler = MPQueryInformation;
        MChars.SetInformationHandler   = MPSetInformation;
        MChars.ResetHandler         = MPReset;
        MChars.TransferDataHandler     = MPTransferData;
        MChars.HaltHandler         = MPHalt;

        //
        // We will disable the check for hang timeout so we do not
        // need a check for hang handler!
        //
        MChars.CheckForHangHandler     = NULL;
        MChars.SendHandler         = MPSend;
        MChars.ReturnPacketHandler     = MPReturnPacket;

        //
        // Either the Send or the SendPackets handler should be specified.
        // If SendPackets handler is specified, SendHandler is ignored
        //
        MChars.SendPacketsHandler     = NULL;//MPSendPackets;

        Status = NdisIMRegisterLayeredMiniport(WrapperHandle,
                                                                &MChars,
                                                                sizeof(MChars),
                                                                &g_MiniportHandle);
        if (! NT_SUCCESS(Status))
    {
        DbgPrint("MPRegisterAsMiniport Failed! Status: 0x%x/n", Status);

        NdisWriteErrorLogEntry(
                    DriverObject,
                    (ULONG)IM_ERROR_IM_REGISTER_FAILED,
                    0,
                    1,
                    (ULONG )Status);
        break;
    }

    //
    // 3. Perform initialization supported by WDM
    //
    // Create a control device object for this driver.
    // Application can send an IOCTL to this device to get
    // bound adapter information.
    //
    //

    DBGPRINT("===> NetWall - NdisWDMInitialize/n");

        NdisAcquireSpinLock(&g_GlobalLock); // sync

        ++g_MiniportCount;
       
        if (1 == g_MiniportCount)
    {
              ASSERT(g_DeviceState != PS_DEVICE_STATE_CREATING); //
   
              while (g_DeviceState != PS_DEVICE_STATE_READY)
              {
                    NdisReleaseSpinLock(&g_GlobalLock);
                    NdisMSleep(1); // Waiting
                    NdisAcquireSpinLock(&g_GlobalLock);
              }
              g_DeviceState

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值