1. 目的:获得当前网卡的MAC地址
2.方法:使用OID: OID_DOT11_CURRENT_ADDRESS
3.信息准备:
DOT11_MAC_ADDRESS MacAddress; pFilter = CONTAINING_RECORD(Link, MS_FILTER, FilterModuleLink); Status = filterDoInternalRequest(pFilter, NdisRequestQueryInformation, Oid, &MacAddress, sizeof(DOT11_MAC_ADDRESS), sizeof(DOT11_MAC_ADDRESS), MethodId, &BytesProcessed); if(Status == NDIS_STATUS_SUCCESS) { DEBUGP(DL_TEST,("Get Curremt address Successfully!\n")); DEBUGP(DL_TEST,("Mac Address is %x-%x-%x-%x-%x-%x\n",MacAddress[0],MacAddress[1],MacAddress[2],MacAddress[3],MacAddress[4],MacAddress[5])); filterSendOriginatedBufferList(pFilter,NDIS_DEFAULT_PORT_NUMBER,&MacAddress);//You can modify this method to do what you want! }else{ DEBUGP(DL_TEST,("Delete a mac fail\n")); break; }
4.是执行filterDoInterNalRequest函数(来自LWF驱动源码)
NDIS_STATUS filterDoInternalRequest( IN PMS_FILTER FilterModuleContext, IN NDIS_REQUEST_TYPE RequestType, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, IN ULONG OutputBufferLength, OPTIONAL IN ULONG MethodId, OPTIONAL OUT PULONG pBytesProcessed ) /*++ Routine Description: Utility routine that forms and sends an NDIS_OID_REQUEST to the miniport, waits for it to complete, and returns status to the caller. NOTE: this assumes that the calling routine ensures validity of the filter handle until this returns. Arguments: FilterModuleContext - pointer to our filter module context RequestType - NdisRequest[Set|Query|method]Information Oid - the object being set/queried InformationBuffer - data for the request InformationBufferLength - length of the above OutputBufferLength - valid only for method request MethodId - valid only for method request pBytesProcessed - place to return bytes read/written Return Value: Status of the set/query request --*/ { FILTER_REQUEST FilterRequest; PNDIS_OID_REQUEST NdisRequest = &FilterRequest.Request; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DEBUGP(DL_TEST,("==>filterDoInternalRequest\n")); NdisZeroMemory(NdisRequest, sizeof(NDIS_OID_REQUEST)); NdisInitializeEvent(&FilterRequest.ReqEvent); NdisRequest->Header.Type = NDIS_OBJECT_TYPE_OID_REQUEST; NdisRequest->Header.Revision = NDIS_OID_REQUEST_REVISION_1; NdisRequest->Header.Size = sizeof(NDIS_OID_REQUEST); NdisRequest->RequestType = RequestType; switch (RequestType) { case NdisRequestQueryInformation: NdisRequest->DATA.QUERY_INFORMATION.Oid = Oid; NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer = InformationBuffer; NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength = InformationBufferLength; break; case NdisRequestSetInformation: NdisRequest->DATA.SET_INFORMATION.Oid = Oid; NdisRequest->DATA.SET_INFORMATION.InformationBuffer = InformationBuffer; NdisRequest->DATA.SET_INFORMATION.InformationBufferLength = InformationBufferLength; break; case NdisRequestMethod: NdisRequest->DATA.METHOD_INFORMATION.Oid = Oid; NdisRequest->DATA.METHOD_INFORMATION.MethodId = MethodId; NdisRequest->DATA.METHOD_INFORMATION.InformationBuffer = InformationBuffer; NdisRequest->DATA.METHOD_INFORMATION.InputBufferLength = InformationBufferLength; NdisRequest->DATA.METHOD_INFORMATION.OutputBufferLength = OutputBufferLength; break; default: FILTER_ASSERT(FALSE); break; } NdisRequest->RequestId = (PVOID)FILTER_REQUEST_ID; Status = NdisFOidRequest(FilterModuleContext->FilterHandle, NdisRequest); if (Status == NDIS_STATUS_PENDING) { NdisWaitEvent(&FilterRequest.ReqEvent, 0); Status = FilterRequest.Status; } if (Status == NDIS_STATUS_SUCCESS) { if (RequestType == NdisRequestSetInformation) { *pBytesProcessed = NdisRequest->DATA.SET_INFORMATION.BytesRead; } if (RequestType == NdisRequestQueryInformation) { *pBytesProcessed = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten; InformationBuffer = NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer; } if (RequestType == NdisRequestMethod) { *pBytesProcessed = NdisRequest->DATA.METHOD_INFORMATION.BytesWritten; InformationBuffer = NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer; } // The driver below should set the correct value to BytesWritten // or BytesRead. But now, we just truncate the value to InformationBufferLength if (RequestType == NdisRequestMethod) { if (*pBytesProcessed > OutputBufferLength) { *pBytesProcessed = OutputBufferLength; } } else { if (*pBytesProcessed > InformationBufferLength) { *pBytesProcessed = InformationBufferLength; } } } //add by leyond if(Status == NDIS_STATUS_INVALID_LENGTH || Status == NDIS_STATUS_BUFFER_TOO_SHORT) { DEBUGP(DL_TEST,("Still need more bytes = %u",NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded)); } if(Status == NDIS_STATUS_INVALID_OID) { DEBUGP(DL_TEST,(" NDIS_STATUS_INVALID_OID--||--")); } return (Status); }
这样就完成了~
Mac Address is 0-14-78-7a-88-b6