4

Currently I need to develop some program that will communicate with cisco devices over serial line. I want to build testing environment on my development linux machine. So, I found dynamips cisco emulator. This emulator can provide interface via serial line with '-U /dev/ttyS0' option. Well, this causes dynamips to open hardware serial port and communicate via it. I'm able to connect to this hardware serial port from another linux machine with serial client like minicom.

However, since i'm using virtualbox for both linux machines, I link serial ports via virtualbox ability to forward serial port to named pipe. This scheme seems to be working, but very redunant. I'm looking for a method to run dynamips and minicom on a single linux machine.

I found that pseudo-terminals could be useful in my case. But I've tried to run dynamips with '-U /dev/ptmx' and then connect with minicom to created /dev/pts/... port and vice versa. In both cases I've got input/output error on both sides.

reddot
  • 764
  • 7
  • 15

1 Answers1

6

Unfortunately, modern pseudo-terminals aren't that easy. After opening the master with posix_openpt() or open("/dev/ptmx"), you must call grantpt() and unlockpt() on the master FD before it and its corresponding slave device are usable. (The openpty() etc. utility functions simplify this.)

As a workaround, the ever handy socat may be of use.

# terminal 1
socat pty:link=$PWD/pts unix-l:$PWD/ptm-pipe &
dynamips -U $PWD/pts

# terminal 2
socat unix:$PWD/ptm-pipe -
ephemient
  • 198,619
  • 38
  • 280
  • 391
  • Or you could use `socat` to open two ptys, and join the master ends together (then connect to one pty from `dynamips`, and the other from `minicom`). – caf Feb 04 '10 at 00:05
  • I don't have `minicom` installed, so I didn't know if it could do that. I'm reading its man page now, and it claims to work on UNIX sockets too! That would obviate the second `socat` altogether. – ephemient Feb 04 '10 at 02:14
  • @caf "and join the maste ends together". what do you mean and how would I do that? Shouldn't one terminal be master and the other slave? – nass Jul 18 '13 at 13:20
  • @ephemient: do you know what additional code one needs to add to make a loopback for the opened slaves with two openpty calls? – László Papp Nov 17 '13 at 06:05