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

📄 main.c

📁 NDIS 实现pppoe例子
💻 C
字号:
/*
    MikroTik PPPoE - MikroTik PPP over Ethernet client for Windows
    Copyright (C),  2001  MikroTikls

    The contents of this program are subject to the Mozilla Public License 
    Version 1.1; you may not use this program except in compliance with the 
    License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ 

    
    http://www.mikrotik.com
    mt@mt.lv
*/


#include "main.h"
#include "debug.h"

NDIS_HANDLE mainWraperHandle = NULL;
NDIS_HANDLE mainDriverHandle = NULL;
NDIS_HANDLE mainProtocolHandle = NULL;

PDRIVER_OBJECT mainDriverObject = NULL;

UCHAR mainEthBcast[6] = {
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};

WCHAR driverRegPathBuf[256];
UNICODE_STRING driverRegPath;

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

VOID UnloadHandler (void) {
	FENTER("UnloadHandler");
	if(mainWraperHandle)
		NdisTerminateWrapper(mainWraperHandle, NULL);
	else
		DbgPrint("No ndis wrapper...\n");
	mainWraperHandle = NULL;
	FLEAVE("UnloadHandler");
}

NTSTATUS DriverEntry(IN PDRIVER_OBJECT  DriverObject, 
                     IN PUNICODE_STRING  RegistryPath) {
	NDIS_STATUS err;
	NDIS_MINIPORT_CHARACTERISTICS miniport_cfg;
	NDIS_PROTOCOL_CHARACTERISTICS protocol_cfg;
	NDIS_STRING Name;
	
	FENTER("DriverEntry");


	NdisMInitializeWrapper(&mainWraperHandle,(PVOID) DriverObject, 
				(PVOID) RegistryPath, (PVOID) NULL);


	NdisZeroMemory(&miniport_cfg, sizeof(miniport_cfg));
	NdisZeroMemory(&protocol_cfg, sizeof(protocol_cfg));

	NdisZeroMemory(driverRegPathBuf, 256 * sizeof(WCHAR));
	NdisMoveMemory(driverRegPathBuf, RegistryPath->Buffer, RegistryPath->Length * sizeof(WCHAR));
	NdisZeroMemory(&driverRegPath, sizeof(UNICODE_STRING));
	driverRegPath.Length = RegistryPath->Length;
	driverRegPath.MaximumLength = 256 * sizeof(WCHAR);
	driverRegPath.Buffer = driverRegPathBuf;
	DbgPrint("%ls\n", driverRegPathBuf);

	NdisInitUnicodeString(&Name, L"MTPPPOE");
	protocol_cfg.Name = Name;
	

	SetupMiniportCfg(&miniport_cfg);
	SetupProtocolCfg(&protocol_cfg);

	// Added for win98 compability.
	protocol_cfg.UnloadHandler = UnloadHandler;

	err = NdisIMRegisterLayeredMiniport(mainWraperHandle, &miniport_cfg, 
					    sizeof(miniport_cfg), &mainDriverHandle);

	if(err != NDIS_STATUS_SUCCESS) {
		NdisTerminateWrapper(mainWraperHandle, NULL);
		mainWraperHandle = NULL;
		DbgPrint("Error in registering miniport: %x\n", err);
		
		FLEAVE("DriverEntry");
		return err;
	}
 
	NdisRegisterProtocol(&err, &mainProtocolHandle, &protocol_cfg, 
			     sizeof(protocol_cfg));

	if(err != NDIS_STATUS_SUCCESS) {
		NdisTerminateWrapper(mainWraperHandle, NULL);
		mainWraperHandle = NULL;
		DbgPrint("Error in registering protocol: %x\n", err);
		
		FLEAVE("DriverEntry");
		return err;
	}
//  Must use protocolCharacteristics for Win98 compability. 
//	NdisMRegisterUnloadHandler(mainWraperHandle, UnloadHandler);


//  Must not be used, because of fucking Windows 98.
	
//	NdisIMAssociateMiniport(mainDriverHandle, mainProtocolHandle);

	FLEAVE("DriverEntry");
	return NDIS_STATUS_SUCCESS;
}

⌨️ 快捷键说明

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