How to write from an input port to a file in racket without storing string/bytestring in memory? - port

I'm looking for a way to stream the content of an input port to a file in racket without holding the string/bytestring in memory but instead stream the content from port to port and I can't seem to find the way to do it, any help is appreciated.

Related

Upload data to the TelosB in Contiki

I am a newbie of the Contiki System. I am trying to upload binary data (in
txt. format, it is some recorded interference) to the TelosB node to regenerate
interference (the data file is in large size, 5M for example), in other words, I am trying to use Contiki to read binary files and send to the node. I googled
this problem, but did not found much useful information.
Could anyone give me some idea?
Thank you in advance.
The easiest way to send data from/to your TelosB is to just send it to the tty associated with the USB port it's connected to (e.g., /dev/ttyUSB0). Your TelosB will be able to simply read the data from stdin (and vice versa).

How do I find what program initiated a download using wireshark?

I have a packet capture and I'm trying to find out which program a download was made with, where would I go in the packet to find this information?
Thanks all!
Instead of looking for answers within the packet, you may want to look at which port the download was done through. That could give you more information, and faster
I assume you know the destination ip address from where the file is downloaded. If it's something that you can catch while it's happening or you can trigger it then you could use netstat to determine the PID of the program that is handling that socket after filtering the netstat output based on the destination ip address.
Then you could use ps on Linux or TaskManager on Windows to know which program has that PID.
On windows: How to determine which program uses or blocks specific transmission control protocol ports in Windows
Alternative if the packet capture it's all you got and it's not a recurring event then if the download was done via HTTP you could check the headers of the HTTP request for info about the client in the User-Agent header.
Hope it helps.

Erlang Port Data Transfer Length

I am trying to evaluate php code through erlang using erlang ports. The problem is when Data to be evaluated is bigger then I am getting parse error from php. But if data is smaller then I am getting the correct output. I think when the Data length is bigger erlang is truncating the data before it is being sent to php for evaluation. Is there any limit on data length which can be sent or received on erlang port. Or is this error due to some other reason ?
I am using open_port(PortName, PortSettings) to open a new port and in PortSettings I am setting [{packet,4},exit_status] as my port options.
The {packet, 4} tuple says the program launched to handle the other end of the port expects data in a 4-byte length-prefixed form. I don't see anything in the docs for the php(1) program that says it knows how to deal with such data. Probably the only reason it works for short inputs is that the length prefix looks kinda like ASCII if you squint, as long as the data you're sending is under 127 bytes. As soon as you go over that, PHP is probably running into a UTF-8 decoding error.
I'm pretty sure you want to say spawn here instead. This gets you standard Unix-like pipe interaction: data sent down the port goes to stdin on the launched process, and anything it sends to stdout comes back to your Erlang process.
The only problem doing it this way is that it re-launches php(1) on each transaction. This may seem expensive, but it's not too bad on any Unix type system, due to the relative efficiency of the fork(2) system call. If you're on Windows or you've benchmarked this and found that you really do need to build a FastCGI like system, you may be out of luck. There seems to be no libphp to embed PHP into a program you write to deal with packetized input, and no way to run php(1) in a way that lets it stay active on the other end of a port. You might be better off switching to a native Erlang templating system.
Also, note that the exit_status atom passed to open_port() does nothing unless you use spawn.

convert printer port bytes inpout32

I'm running out of ideas.
I'm using C by the way via inpout32.dll.
I have these "bytes"(e.g. 0000,00CC) being read from the printer data ports D0-7 or D1-8.
I need to filter out human readable characters when a print job is being done.
This is still very primitive, but I've got a listener function catching these data using inp32.
Basically if I do a print in notepad like 'Hello World', this will be pulled out from the byte being read by inp32 function.
the printer port listener is on a separate app.
the idea is that the app can listen in on any printer.
It's basically a PoC at the moment.
but what I'm using right now to test is a Canon BJC-1000SP, it's pretty old but it's the only parallel port printer we've got at the office. the others are USB types.
I'm using this on Windows at the moment.
Thermal Printers are actually the ones we'll be listening on.
So now I'm trying to use a generic driver that allows raw text file to print.
How can I extract text from it via the port?
If anybody can give me an idea, a function/converter or where to search, that would be great.
If all you read is already human-readable text, just store it all.
If not, you need to think about the character encoding in use. If it's plain old ASCII, you can probably just call isprint() to determine if a byte is a printable character.
The above of course assumes that your printer is talking plain-text, which probably means it has to be a rather old and simplistic printer (like a dot-matrix from ~20 years ago, or so).
If it's a modern "Win-Printer" laser or inkjet, with all the intelligence of page layout being done by the host computer in the driver, you're probably out of luck. In these cases, what is transmitted is the instructions to layout the page, typically in a printer-specific format.
I think you should edit your question and specify exactly what printer you're using, and in which operating system environment you're running your program.
Update: The Canon BJC-1000 printer you're currently using is an inkjet. It very probably relies on the host computer to send it line-by-line (as in ink lines, not text lines) of data to control the various ink nozzles. I don't think it ever sends plain text to the printer. You could investigate by reading through the code of an open source driver. For Linux, the recommended driver is called gutenprint.

Help for driver programming

I want to write a driver (in c) that can "catch" the events for reading and writing on hard disk. My problem is that I do not know how can I listen the system bus to treat these events. I use Microsoft DDK.
Thank you!
I think what your looking for is IoAttachDevice(), you can find more information on the routine here.
It is much easier to monitor reads and writes of your applications than those actually happens to the physical media. In other words, it is much easier to write a upper filter driver that sits above the file system driver than playing with the actual driver that handles physical access to the hard disk.
I suggest you browse the examples that come with your version of DDK (or WDK, etc) to see if there's anything similar to what you need. If there is, it's much easier to modify from those instead of starting from scratch.
This is more complicated than you think. This can be done with a SCSI Port Driver. What are you trying to do? Get logical IO or IO on a physical disk?

Resources