e42.uk Circle Device

 

Quick Reference

Terminal Codes and socat

Terminal Codes and socat

For this I used a Gentoo host machine and an Alpine guest.

To look at the codes being sent use pfwd to relay the messages:

Start a VM and use a serial terminal:

qemu-system-x86_64 -enable-kvm \
   ... \
   -serial pty \
   -boot c

When you start the VM notice that it should tell you the char device being used:

qemu-system-x86_64: -serial pty: char device redirected to /dev/pts/8 (label serial0)

If you are running a good OS you should be able to put getty on a serial port see /etc/inittab:

ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100

This line may be commented out or might not exist. If you do not have an inittab file, you might be out of luck, maybe try Alpine Linux? You can use this with screen like this:

screen /dev/pts/8 115200,rtscts

The 115200,rtscts does not actually matter in this case! Press enter a few times and you should see a login prompt... login!

Type a few commands and make sure everything is OK... if you cannot run some curses programmes well you might need to call resize or stty.

To get out of screen you can call Ctrl-a : then type kill and press enter. There may be other ways...

Now we want to see the traffic, to do this we are going to use socat to put the "serial port" onto a TCP port:

socat tcp-l:5432,reuseaddr,fork file:/dev/pts/8,nonblock

Then forward that port (and log the traffic) using pfwd:

./pfwd 0.0.0.0 5000 127.0.0.1 5432

Now connect to port 5000 and use the terminal...

socat $(tty),raw,icanon=0,echo=0,min=0,isig,icrnl=0 tcp:127.0.0.1:5000

Yay! you can also connect like this:

socat -,icanon=0,echo=0,min=0,isig,icrnl=0 tcp:127.0.0.1:5000

(difference is left up to the user to find out).

What about being able to send Ctrl-C through the socket? You can send some stuff like this:

echo -en "resize\n" > /dev/pts/8

But I am sure we can find a way to make this better...

Connecting screen to a socket:

more coming soon.

References

Quick Links: Techie Stuff | General | Personal | Quick Reference