Sniff LPT Traffic in windows - c++

I need to programmatically sniff data that is being passed through the parallel port (LPT) to printer in Windows XP.
This is what I have tried in the past 3-4 days:
Firstly, I tried to read data using windows CreateFile(), WaitCommEvent() and ReadFile() functions. But they seem to block the port, so that the port access is denied to other applications.
Secondly, I have used com0com to create virtual COM port to get the printer data and then send it to LPT. This requires me to make the source user space application send the data to COM port first and then I write my code to tunnel that data to printer through LPT port. So, I basically redirect the print stream through COM port rather than sniffing it over the LPT port. So, it requires changing the settings in the application whose print data I need to capture. Hence, this is more of a hack but not something I need.
Finally, I have used PortMon and PrintFil as mentioned in this question. They work fine but I need to include PortMon's sniff functionality in my application.
So, is there any open source library or code sample which could be used to sniff the parallel port data similar to what portmon or printfil do ?

Related

How to supply data via COM3?

I have been tasked with testing a serial comms application.
This application listens on COM3.
How can I supply data via COM3 to test the code.
I have tried to have another application that supplies the data but as I have discovered I can only have one application accessing COM3
What is the recommended way of doing this?
The most typical way is to connect some hardware to COM3 to communicate with.
If you are lacking such hardware or want to test what the application does when it gets garbage instead of what it is expecting there are applications which provide a "virtual serial port pair" which emulate both sides and you can connect your application to one port while using a second application to communicate via it's pair. The paired ports should behave as if they were physically connected by a wire.
Also if you need a specific port number because of how the application is written you can change port numbers by choosing the device in Device Manager going to Properties and than Advanced and changing COM Port Number. If it's already used by another device you have to change that first to have a different number.

Sending NS-3 packets through user-defined socket to another terminal

I wanted to know if anyone has any idea of how I can handle this scenario:
I want to have two terminals open. In one of them I want to run an NS-3 script file which generates packets and sends it through a socket to the other terminal.
The other terminal (which is only running a simple C socket program) receives the packet through the socket (and ideally displays the payload or even simpler increases a packet counter).
Any ideas appreciated...
Yes, you can make ns-3 interact with the real world.
Please read this tutorial :
http://www.nsnam.org/wiki/HOWTO_make_ns-3_interact_with_the_real_world
Especially Tap bridge. The Tap Bridge is designed to integrate “real” internet hosts (or more precisely, hosts that support Tun/Tap devices) into ns-3 simulations
http://www.nsnam.org/docs/release/3.18/models/html/tap.html

Virtual COM port to Socket communication

I have a virtual COM port and socket in my app , i want to transfer data from this Virtual COM port to a socket and vice versa.
How can i do this?
Is there some sample code or good library out there to do so? Eventually this should work on Windows CE, but initially it should work on regular Windows.
It depends what you need the service to do.
Is it bi-directional, does opening the port have to automatically setup a new network link, do you need to set serial port parameters over the network?
If you only really need to remote a serial port and don't need any command and control data then most introductions to network programming start with some sort of chat server where everything typed at the client end goes to the server as text - it should be trivial to modify this so that the source text comes from a serial port

best method to find the COM port to which my embeded device got connected in my vc++ program

I want to find the COM port my device got connected in my vc++ program.
upto now i used to scan all the ports from 0 to 15 and send some command if the reply is suitable to me i can confirm that it is the port i am finding.
But this is Taking a lot of time.
anyother solution???
The serial API does not provide for any of the sort of identification that you seem to desire so the only choice that you have is to poll he various ports. If the device is a USB device, you may be able to garnish clues from the friendly name associated with that device (see How do I get the friendly name of a COM port in Windows?).

C++ redirect outgoing connections

Is there any way in C++ on windows to monitor a program and redirect any outgoing requests it makes on a specific port? I have a simple C++ http proxy and want it to be able to automatically redirect all browser requests on port 80 through itself.
The simple way to do it is to create a Windows kernel hook to trap socket requests and reroute them to your proxy.
Some useful documentation on this is:
http://www.internals.com/articles/apispy/apispy.htm
If you're using Windows Vista or better, consider Windows Filtering Platform (WFP):
http://www.microsoft.com/whdc/device/network/wfp.mspx
Also consider looking at Detours (commercial) and EasyHook (free). They significantly simplify the process of writing hooks and redirecting API calls (both Win32 and Application).
The program would have to be run with administrative privileges in kernel mode of the host OS.
While I don't have extensive experience with windows kernel hooks, in BSD and linux its trivial to install a kernel module that over-writes the system calls for creating sockets and could easily redirect all sockets to a proxy socket of choice.
If you mean [any destination port] to [one port] then you will have to rely on special drivers. The problem with windows is the inability to natively block [drop] packets. For example a common solution is winpcap. However, while you can monitor traffic, you cannot stop the traffic or modify it in a useful way.
On windows the only solution I've seen would be to use some open TUN/TAP adapter. With that, you would be able to modify every packet that leaves your system.
If you know beforehand the destination port you will be using then it gets rather simple. Simply write a passthrough c++ socket program that will only change the destination port.
If you want to redirect browser requests then you can simply edit the settings in your browser.