Ok ,I have a problem binding the adapter to ndis driver. Please
somebody can look to my code and tell me whats wrong.Thanks !!!
It is very important to me to know how to send raw packets.
I have c++6.
///////////////////////////////////////////////////////////////////
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int
copying=0,lol=0,lol2=999,bufsize,pointerull1=0,pointerull0=0,lungimeaaa=0;
char output[1000]="",filtredoutput[1000]="",adapterid[524]="";
struct NDISPROT_QUERY_BINDING
{
unsigned long BindingIndex; // 0-based binding number
unsigned long DeviceNameOffset;
unsigned long DeviceNameLength; // in bytes
unsigned long DeviceDescrOffset;
unsigned long DeviceDescrLength; // in bytes
};
struct NDISPROT_QUERY_BINDING ndisprot;
ndisprot.BindingIndex=0; //Adaptor number
bufsize =sizeof(ndisprot);
HANDLE hDevice; // handle to the adapter to be examined
BOOL validAdapter,bindadadapter; //handle
DWORD bytesread,uiBytesReturned; // number of bytes
for output buffer
//Opening driver with create file
hDevice = CreateFile("\\\\.\\\\NdisProt"/* drive to
open*/,GENERIC_WRITE|GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
validAdapter = DeviceIoControl(hDevice/* device to be
queried*/,0x12C80C/* operation to perform "Enumerate
Adapters"*/,(void*) &ndisprot/*input buffer*/,bufsize/*input buffer
size*/,output/*output buffer*/,lol2/*output buffer
size*/,&bytesread/*number of bytes returned*/,NULL);
///////////////////////////////////////////////////////////
if (!validAdapter)
printf("Error\n");
do{
if(strncmp(output+copying,"\x00",1))
strncat(filtredoutput,output+copying,1);
copying++;
}while(copying<bytesread);//getting adapter id from iocontroldevice
data
do{
pointerull0++;
}while(strncmp(filtredoutput+pointerull0,"\\",1)!=NULL);
do{
pointerull1++;
}while(strncmp(filtredoutput+pointerull1,"}",1)!=NULL);
strncpy(adapterid,filtredoutput+pointerull0,pointerull1-pointerull0+1);
///////////////////////////////////////////////////////////
lungimeaaa=strlen(adapterid);
bindadadapter=DeviceIoControl(hDevice/* device to be
binded*/,0x12C800/*operation to perform "Open Device"*/,(void*)
&adapterid,lungimeaaa,NULL,0,&uiBytesReturned,0);
if (!bindadadapter)
printf("Error not binded %d\n",uiBytesReturned);
printf("filtredoutput=%s\nsize=%d\nbytesread=%d\n",filtredoutput,lol2,bytesread);
printf("Adapter ID =%s\n",adapterid);
CloseHandle(hDevice);
printf("Hello World!\n");
return 0;
}
/////////////////////////////////EOF///////////////////////////////