-
WinPcap Sniffer App Prob
Code:
#include <stdio.h>
#include <conio.h>
#include <wchar.h>
#include "packet32.h"
#include "ntddndis.h"
#define UNICODE // Helps Im told
// Prototypes
void DisplayPackets(LPPACKET lpPacket);
char AdapterList[10][1024];
int main()
{
LPADAPTER lpAdapter = 0;
LPPACKET lpPacket;
int i = 0,n = 0;int Open;
ULONG AdapterLength = 4096;
DWORD dwErrorCode;
WCHAR AdapterName[8192];
WCHAR *temp,*temp1;
char buffer[512000];
struct bpf_stat stat;
printf("Adapters installed On Your System Are As Follows:\n");
printf("\n-----------------------------------------------\n");
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE)
{
printf("Unable to retrieve the list of the adapters!\n");
return -1;
}
temp=AdapterName; // Char Pointers
temp1=AdapterName; // Char Pointers
while ((*temp!='\0')||(*(temp-1)!='\0'))
{
if (*temp=='\0')
{
memcpy(AdapterList[i],temp1,(temp-temp1)*2);
temp1=temp+1;
i++;
}
temp++;
}
// End Of Politecnico di Torino Code
//-------------------------------------------
//Outputting Strings
for (n=0; n < i;n++)
{
wprintf(L"\n%d- %s\n",n+1,AdapterList[n]);
// wprintf translates any number of numeric values and prints
// the results along with other characters,
// uses a wide-character-format string
}
printf("\n");
Code tags added by Kermi3
-
Code Tags
I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you ;)
For example:
Without code tags:
for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}
With Code Tags:
Code:
for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}
This is of course a basic example...more complicated code is even easier to read with code tags than without.
I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.
This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.
If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.
Good Luck with your program,
Kermi3
Lead Moderator
-
WinPcap Sniffer App Prob
/*
Hi..
this little app gets the network cards installed on a pc using WinpCap http://winpcap.polito.it/install/bin/WinPcap_3_0_a4.exe about 300k..
WinpCap is open source packet capture architecture
The problem is..
it works when the source file is a .c
but when name a .cpp
WCHAR AdapterName[8192];
WCHAR *temp,*temp1;
cannot be passed to the PacketGetAdapterNames function
and my loop output is all wrong..
in c it runs perfectly
i have been stuck on this problem for 3 weeks now..
and could someone kindly help me
as to a datatype to use in c++ instead of WCHAR
and the modifications to the loop that need to be
made to work with this datatype.
Code:
*/
#include <stdio.h>
#include <conio.h>
#include <wchar.h>
#include "packet32.h"
#include "ntddndis.h"
#define UNICODE // Helps Im told
// Prototypes
char AdapterList[10][1024];
int main()
{
LPADAPTER lpAdapter = 0; //pointers to winpcap stuff
LPPACKET lpPacket; //pointers to winpcap stuff
int i = 0,n = 0;int Open;
ULONG AdapterLength = 4096;
DWORD dwErrorCode;
WCHAR AdapterName[8192];
WCHAR *temp,*temp1;
char buffer[512000];
struct bpf_stat stat;
printf("Adapters installed On Your System Are As Follows:\n");
printf("\n-----------------------------------------------\n");
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE)
{
printf("Unable to retrieve the list of the adapters!\n");
return -1;
}
temp=AdapterName; // Char Pointers
temp1=AdapterName; // Char Pointers
while ((*temp!='\0')||(*(temp-1)!='\0'))
{
if (*temp=='\0')
{
memcpy(AdapterList[i],temp1,(temp-temp1)*2);
temp1=temp+1;
i++;
}
temp++;
}
for (n=0; n < i;n++)
{
wprintf(L"\n%d- %s\n",n+1,AdapterList[n]);
}
printf("\n");
return 0;
}
//end
-
Code Tags
I don't see why you posted twice but....oh you asked the Q heh cool...still...
I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you ;)
For example:
Without code tags:
for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}
With Code Tags:
Code:
for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}
This is of course a basic example...more complicated code is even easier to read with code tags than without.
I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.
This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.
If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.
Good Luck with your program,
Kermi3
Lead Moderator