socat (SOcket CAT) – multipurpose relay – is a command line based utility that establishes two bidirectional byte streams and transfers data between them. socat is #4 on the Top 100 Network Security Tools list, available in most distro repositories (on Debian/Ubuntu sudo apt-get install socat does the trick), really light on resources, and very efficient. Sounds simple, does wonders!
Connection through COM port between host and guest in VirtualBox. Ask Question 3. In VirtualBox, I enabled the serial port and chose a host pipe in port mode, as shown in. First of all, VirtualBox won't create a serial port for your host. So you have to create two virtual COM ports on the host using some other software and bridge.
Sidenote: socat is actually #71 on the mentioned list, but since socat is a much enhanced version of netcat, which is #4, it seems to me logical to count socat as #4 also.
One of the wonders you can do is creating pairs of “virtual” ports/interfaces/sockets etc., even hybrid pairs like port-socket, etc., where one (or both) ends of the pair can also be real objects. See socat man page for more details.
Creating pairs of virtual serial ports (VSP), is quite often wanted feature, yet it’s hard to find a solution online (try Googling it)… Pair of VSP’s is very useful to have esp. if you’re into embedded device programming, where many embedded development kits support debugging via serial link – PharLap in my case. Yes, it does have Ethernet debugging since ETS 14, but it’s a very unstable option. Even if you’re using Ethernet debugging, it’s often much easier to have your embedded system in a virtual machine (VirtualBox, VMWare etc.), and do the debugging via virtual NIC.
To cut the talk short, many thanks to Gerhard Rieger, author of socat, for the following tips!
To create a pair of VSP’s
and that’s it! As long as the socat is running, you have a pair of VSP’s open (their names are printed by socat on initialization). See socat man page for more details on what the above command does.
Connecting executable and VSP
where the executable myprog will be connected with the VSP through stdio.
Virtual network interfaces
In a similar fashion, you can create pairs of virtual network interfaces – tun/tap devices (again, this pair exists as long as the master process – socat – is alive):
Yes, that’s it, you’ve got a pair of virtual network interfaces!
While installing Solaris on VirtualBox on Linux host, I was slightly annoyed by the graphical interface. I had to go out of my screen session, use mouse, click the virtual machine window, let it steal the input and then press right ctrl key to go out, and use mouse again to go back to my screen session.
Solaris x86 supports installation over a serial port. Why not use it?
VirtualBox supports attaching a serial device to a guest machine. By default, serial ports are disabled. If you go to the details tab, and see ‘Serial Ports’, you can click it and get a dialog box. Enable serial port COM1 (IRQ 4 I/O port 0x3F8). There are two port modes. One of them is ‘Host Device’. It would be very nice to use it, but VirtualBox run as a normal user lacks permissions to create devices. The other option is ‘Host Pipe’. Normal user permssions are sufficient to create a pipe, but when you run VirtualBox and examine the file type, you’ll find out that what has been actually created is a unix domain socket rather than a pipe.
How do you access serial port exposed as a socket? Use socat!
I’ve worked out two ways of accessing the serial port: by converting to TCP and by converting to a pty (pseudo teletype device). First, TCP solution. Let’s say, that the path to the socket is “/tmp/foo-socket”. We’ll use socat to convert it to a TCP server.
This command shouldn’t return to prompt. If it does, your serial port device on the guest virtual machine isn’t ready yet. If it doesn’t return, go to a different terminal window and type:
If socat returns immediately, it means your guest system doesn’t use the serial port at the moment. If you’re installing Solaris 10, you’ll have to select a serial port (ttya) installation mode first, in the bootloader.