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
P

packetlos

@packetlos
About
Posts
17
Topics
9
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • tcp header
    P packetlos

    Could I not do something like this:

    typedef struct len_flags
    { USHORT unused : 6,
    	 len: 4,
    	 flags : 6;
    } len_flags;
    
    typedef struct tcp_header {
        USHORT sport;			// Source port
        USHORT dport;			// Destination port
        UINT32 seq;				// Sequence number
        UINT32 ack;				// Acknowledgement number
            #define TH_FIN  0x01
            #define TH_SYN  0x02
            #define TH_RST  0x04
            #define TH_PUSH 0x08
            #define TH_ACK  0x10
            #define TH_URG  0x20
        len_flags lenflags;		        // TCP length & flags
        USHORT win;				// window
        USHORT crc;				// checksum
        USHORT urp;				// urgent pointer
    } tcp_header;
    

    Then test the flags like this:

    // test flags
    if (tcpHeader->lenflags.flags & TH_URG)
      tempTCP.flags = "URG ";
    if (tcpHeader->lenflags.flags & TH_ACK)
      tempTCP.flags += "ACK ";
    if (tcpHeader->lenflags.flags & TH_PUSH)
      tempTCP.flags += "PSH ";
    if (tcpHeader->lenflags.flags & TH_RST)
      tempTCP.flags += "RST ";
    if (tcpHeader->lenflags.flags & TH_SYN)
      tempTCP.flags += "SYN ";
    if (tcpHeader->lenflags.flags & TH_FIN)
     tempTCP.flags += "FIN ";
    

    But it dosent seem to work :((, something to do with #pragma pack? Regards Packetlos

    C / C++ / MFC help tutorial question

  • CListView
    P packetlos

    Thank you, i knew there had to be something like this available. :)

    C / C++ / MFC question

  • CListView
    P packetlos

    Hi just a quickie, I have 2 views in my application which are split, a ListView and a TreeView, when the selection in the listview changes the treeview updates, when this happens the LitsView looses focus and the selection highlight disapears, is there any way to retain this? Cheers Packetlos

    C / C++ / MFC question

  • unsigned chars
    P packetlos

    Sorted with: MoveMemory(tempDatagram.pkt_data.GetData(), pkt_data, dataLen);

    C / C++ / MFC question

  • copy constructor
    P packetlos

    Thanks toxcct and antlers, toxcct was right that there in as far as I can see a way to provide a constructor for the struct, therefore I converted it to a class and used CByteArray's .Copy() to provide the assignment. :)

    C / C++ / MFC help question

  • copy constructor
    P packetlos

    Hi there, If I add a CArray such as CByteArray to a struct like so: typedef struct DATAGRAM { // other types here... CByteArray pkt_data; // Packet data } DATAGRAM; and then try and assign something of type DATAGRAM to type DATAGRAM i get the following compile error: C2558: struct 'DATAGRAM' : no copy constructor available or copy constructor is declared 'explicit' I know this is because because CByteArray is of dynamic type so I need to provide a copy constructor. So my question is do I need to provide one for DATAGRAM or do I really need to provide one for CByteArray and if so could somebody post a code snippet to help me out? Cheers Packetlos

    C / C++ / MFC help question

  • unsigned chars
    P packetlos

    Hi John, Thanks for taking time to reply, CByteArray seems to be exactly what I need, I can calculate the size of the data and set the CByteArray like this: tempDatagram.pkt_data.SetSize(dataLen); But then how do I copy the data into the array using the given pointer to the buffer of UCHARS?

    C / C++ / MFC question

  • unsigned chars
    P packetlos

    Hi guys, I am trying to copy into a struct the contents of a buffer returned from the winpcap library, the libray function call returns a pointer to the buffer like the following type: const UCHAR *pkt_data I am trying to declare something to hold the data where // Packet data ??? is.

    typedef struct DATAGRAM
    {
    	UINT packetID;			// Sequence Number
    	ip_header ipHeader;		// IP header
    	pcap_pkthdr wpHeader;	        // Winpcap header
    	unsigned char pkt_data[];	// Packet data ???
    } DATAGRAM;
    

    I would prefer to keep it as UCHARS because it makes it easier to parse the data later on into headers such as tcp, so my question is how should declare the type in the struct and how can i copy the data in from the buffer?? Cheers Packetlos

    C / C++ / MFC question

  • CList class
    P packetlos

    Hi, What is the best way of using MFC's List to store data of this type?

    typedef struct DATAGRAM
    {
    	UINT packetID;			// Sequence Number
    	ip_header* ipHeader;		// IP header
    	pcap_pkthdr* wpHeader;		// Winpcap header
    	const UCHAR* pkt_data;		// Packet data
    } DATAGRAM;
    

    ipHeader* etc are pointers to further structs. I tried plain CList DATAGRAM, DATAGRAM& and are having problems with code like:

    packetCapture.AddTail(filledStruct);
    

    The addtail is in a fairly fast loop and added data is going in fine and coming out of the list corrupted (due to something going out of scope before the operation is completed perhaps?) I am probably doing something extremely retarded, any ideas?

    C / C++ / MFC question c++

  • making a class thread safe
    P packetlos

    Hi, I am trying to make my class thread safe with out much luck and wonder if anybody can point me in the right direction. An object of this class is shared between 2 threads, therefore I have added some critical sections but in testing this does not seem to be enough, below is what i have so far:void CPacket::Lock() { CSingleLock singleLock(&m_CList); singleLock.Lock(); ASSERT(singleLock.IsLocked()); } void CPacket::Unlock() { CSingleLock singleLock(&m_CList); singleLock.Unlock(); ASSERT(!singleLock.IsLocked()); }
    and in my code around all use of the object:m_capturedPacket->Lock(); m_capturedPacket->Addpacket() // do something m_capturedPacket->Unlock();
    Internally the class mainatins a CList which is being corrupted, how can I make calls to this class thread safe?

    C / C++ / MFC question testing beta-testing

  • tcp header
    P packetlos

    Cheers for the reply roger, Can you give me a hint at which data types would be best suited for these fields and how to declare them at that length in c++, considering that I would rather they were kept seperate from one another so no further processing is required to split the header data into component parts. As you can tell I am a bit of a novice at c++ and the MFC's and i think i have bitten off a bit more than I can chew :((

    C / C++ / MFC help tutorial question

  • tcp header
    P packetlos

    Hi, i wonder if anybody with knowledge of the TCP header can help me with this one: I am casting some data from a buffer provided by the winpcap packet capture library into a struct I have defined to represent the TCP header, the header is at the start of the buffer and I am casting it like this: tcpHeader = (tcp_header *) (UCHAR*) tempDatagram.pkt_data; where the tcpHeader is of type: typedef struct tcp_header{ USHORT sport; // Source port USHORT dport; // Destination port UINT32 seq; // Sequence number UINT32 ack; // Acknowledgement number // assume little endian for now UINT x2:4; // Unused UINT off:4; // Header length (offset) UCHAR flags; // TCP flags USHORT win; // window USHORT crc; // checksum USHORT urp; // urgent pointer } tcp_header; the cast is working upto the offset i think and then values are being filled in a little randomly from there so I dont think i have the tcp_header defined right for the TCP header, can anybody suggest how to fix it?

    C / C++ / MFC help tutorial question

  • UCHAR to CString
    P packetlos

    Hi i wonder if anybody can answer this (simple?) question, i have a buffer returned from a library call declared as: const UCHAR* pkt_data and i want to fill a CString object from a certain postion from that buffer, say 14 charachers in, I have looked at all the CString articles here and for the life of me cannot figure out how to do it. Can anybody be so kind as to post a code snippet? Cheers Andy

    C / C++ / MFC question tutorial

  • Access violations
    P packetlos

    Cheers for the link, i have read the article and I am doing what it suggests by using a user defined message to trigger OnThreadUpdate now using PostMessage() and it is still causing access violations. Any other things I should be looking at anybody? Thanks

    C / C++ / MFC design question announcement

  • Access violations
    P packetlos

    Hi, I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:

    LRESULT CNetworkMonitoringListView::OnThreadUpdate(WPARAM wParam, LPARAM lParam)
    {
    CString sResult;
    LV_ITEM lvi;
    
    lvi.mask = LVIF_TEXT | LVIF_DI_SETITEM;	// instance mask
    lvi.iItem = (INT)lParam;		// position in control
    lvi.iSubItem = 0;			// column
    lvi.pszText = (LPTSTR)(LPCTSTR)lParam;	// 
    GetListCtrl().InsertItem(&lvi);		// insert the item
    
    for (int i = 0; i < 5; i++)
    {
    	lvi.iSubItem = i;
    	GetDocument()->m_cs.Lock();
    	// get the text for the relevant row subitem
    	sResult = GetDocument()->m_capturedPacket.GetDescription((UINT)lParam, i);
    	GetDocument()->m_cs.Unlock();
    	lvi.pszText = (LPTSTR)(LPCTSTR)(sResult);
    	GetListCtrl().SetItem(&lvi);
    		
    	}
    
    return 0;
    }
    

    The second time the message from the worker thread is processed

    GetListCtrl().InsertItem(&lvi)
    

    causes an access violation and fails to add another entry into the CListview, is there anything I can do? :(( Cheers Packetlos

    C / C++ / MFC design question announcement

  • Sharing object between thread
    P packetlos

    I solved this problem by placing a critical section around the usage of the instance of my class :)

    C / C++ / MFC help data-structures question

  • Sharing object between thread
    P packetlos

    I am having a problem with threads and wonder if anybody can help, I am spawning a worker thread that updates a linked list that I need access to from the other thread, basically i am passing the instance of the class with the linked list using a struct: UINT CNetworkMonitoringDoc::CaptureThread(LPVOID pParam) { THREADPARMS* ptp = (THREADPARMS*) pParam; CPacket* m_capturedPacket = ptp->pPacketInst; delete ptp; ... } The worker thread adds data to the linked list ok but when the orginal thread needs to do something with the m_capturedPacket instance the contained linked list is empty, im guessing the thread is creating its own private copy and working on that; is there anyway to share m_capturedPacket between them? Cheers Andy

    C / C++ / MFC help data-structures question
  • Login

  • Don't have an account? Register

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