Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Someone Please Help (WinPCap/TCP Capture)

Someone Please Help (WinPCap/TCP Capture)

Scheduled Pinned Locked Moved C / C++ / MFC
helpalgorithms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe_Scialabba
    wrote on last edited by
    #1

    Hey guys, I can't seem to figure out my problem trying to print out the data to the tcp packet. Please, someone help me out.. I've been searching the internet, trying to find something in the Wireshark source, I'm lost and confused... If you want the full source, please say something. Thanks!

    typedef struct IP_Address
    {
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;

    } ip_addr;
    typedef struct IPv4_Header
    {
    u_char ver_ihl;
    u_char tos;

    u\_short tlen;
    u\_short id;
    u\_short flags\_off;
    
    u\_char ttl;
    u\_char proto;
    u\_short crc;
    
    ip\_addr srcaddr;
    ip\_addr dstaddr;
    
    u\_int opt\_pad;
    

    } ipv4_hdr;
    typedef struct TCP_Header
    {
    u_short srcport;
    u_short dstport;

    u\_int seq;
    u\_int ack;
    
    u\_char offset;
    u\_char reserved;
    
    u\_short window;
    u\_short crc;
    
    u\_int opt\_pad;
    
    u\_char data\[65535\];
    

    } tcp_hdr;

        for (;;)
    {
    	CErr = pcap\_next\_ex(edev\_open, &pkt\_header, &pkt\_data);
    	
    	if (CErr == -1)
    	{
    		cout<< "Encountered an error while reading!\\n";
    
    		pcap\_close(edev\_open);
    		return 0;
    	}
    
    	switch (CErr)
    	{
    		case 0: /\* Timeout \*/
    		{
    			break;
    		}
    		case 1:
    		{
    			ih = (ipv4\_hdr\*) (pkt\_data + 14);
    			th = (tcp\_hdr\*) ( (u\_char\*)ih + ((ih->ver\_ihl & 0xF0) \* 4) );
    
    			break;
    		}
    		case -2: /\* EOF reached reading from offline capture \*/
    		{
    			cout<< "End of Dump File!\\n";
    			break;
    		}
    	}
    }
    
    M 1 Reply Last reply
    0
    • J Joe_Scialabba

      Hey guys, I can't seem to figure out my problem trying to print out the data to the tcp packet. Please, someone help me out.. I've been searching the internet, trying to find something in the Wireshark source, I'm lost and confused... If you want the full source, please say something. Thanks!

      typedef struct IP_Address
      {
      u_char byte1;
      u_char byte2;
      u_char byte3;
      u_char byte4;

      } ip_addr;
      typedef struct IPv4_Header
      {
      u_char ver_ihl;
      u_char tos;

      u\_short tlen;
      u\_short id;
      u\_short flags\_off;
      
      u\_char ttl;
      u\_char proto;
      u\_short crc;
      
      ip\_addr srcaddr;
      ip\_addr dstaddr;
      
      u\_int opt\_pad;
      

      } ipv4_hdr;
      typedef struct TCP_Header
      {
      u_short srcport;
      u_short dstport;

      u\_int seq;
      u\_int ack;
      
      u\_char offset;
      u\_char reserved;
      
      u\_short window;
      u\_short crc;
      
      u\_int opt\_pad;
      
      u\_char data\[65535\];
      

      } tcp_hdr;

          for (;;)
      {
      	CErr = pcap\_next\_ex(edev\_open, &pkt\_header, &pkt\_data);
      	
      	if (CErr == -1)
      	{
      		cout<< "Encountered an error while reading!\\n";
      
      		pcap\_close(edev\_open);
      		return 0;
      	}
      
      	switch (CErr)
      	{
      		case 0: /\* Timeout \*/
      		{
      			break;
      		}
      		case 1:
      		{
      			ih = (ipv4\_hdr\*) (pkt\_data + 14);
      			th = (tcp\_hdr\*) ( (u\_char\*)ih + ((ih->ver\_ihl & 0xF0) \* 4) );
      
      			break;
      		}
      		case -2: /\* EOF reached reading from offline capture \*/
      		{
      			cout<< "End of Dump File!\\n";
      			break;
      		}
      	}
      }
      
      M Offline
      M Offline
      malaugh
      wrote on last edited by
      #2

      Did you look at this? It worked for me. http://www.tcpdump.org/pcap.htm[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups