Posts

Showing posts from 2010

Use of const in C++

Interesting read http://duramecho.com/ComputerInformation/WhyHowCppConst.html

Windows programming: Event states

Just some basics about the Windows Event object. Event objects can be used for inter process synchronization. They have only 2 states: signalled and non-signalled. When the Event object is in the non signalled state, it means that it is being used by a thread. All other threads which want to use it will have to go to sleep while this state is maintained. When the current thread which owns the object releases it, the object goes into the signalled state and wakes up a thread which was waiting for it. SetEvent() sets the state of the object to the signalled state while ResetEvent() sets it to the non-signalled state.When creating an event object, we can specify which state it is created in.

Debugging DLL's

Certain pointers on debugging DLL's in Visual Studio Assuming you have the source code for both the calling application and the DLL. Build both the application and the DLL projects in Debug mode. On building the DLL you should get 2 files: a .dll and a .pdb. Place these 2 files in the folder containing the exe for the calling application. Or you could place it in another folder and specify its location. Please note that the pdb and dll should be created in one build. If  a mismatch occurs between the two, it might not be possible to debug your application. Open the DLL's source code files in the same Visual Studio session as the calling application and put break points in them. On stepping into the code from the calling application, you will now be able to debug the code for the DLL.  Another way to debug DLL's is to start from the DLL project and mention the executable that calls the DLL.

Converting int to char* in C/C++

A very common issue we face is to convert an integer into a char pointer or array. This can be achieved using sprintf. int count = 600; unsigned char size[3]; sprintf(size, "%03d", count); Thats it! Here '%03' means that a minimum of 3 characters will be printed and if the number is smaller than that it will be left-padded with 0's.

Loading kernel modules

Use 'lsmod' to display all the loaded modules. If the module you are looking for is not visible, you need to load it. For this use 'insmod module_name.ko'. If this still throws errors, you might consider recompiling the .ko files.

Filtering packets in Wireshark

When you open Wireshark, there is a Option for Filter on top. However, that doesn't seem to work. Instead, go to Capture->Options. Next, in the field adjacent to 'Capture Filter', type in the filter. This could be 'host 192.168.123.233' for example. The host command filters packets to/from the give ip .