Thread: WinPcap Sniffer App Prob

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    14

    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

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    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
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    14

    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

  4. #4
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    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
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  3. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 07:05 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM
  5. How do I make my Linux app standalone?
    By Joda in forum C++ Programming
    Replies: 2
    Last Post: 11-27-2002, 04:53 AM