I'm looking for a network interface simulator, that offers both ends of a network on a single machine (particularly for UDP).

The way com0com works for serial ports, but simulating a network card instead of a serial port.

Is this behavior possible by using the existing network stack in a creative way? (Port forwarding or some such?) Or some creative configuration of OpenVPN, L2TP/IPSec, SoftEther, PPTP, etc.?

I have software I can't change, that binds to certain UDP ports and sends outgoing messages on those same ports. I'd like to intercept and route those messages, but I can't bind to those same ports myself since that software is already binding to them.

New contributor
JimB is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
up vote 1 down vote accepted

First off, you actually already have one on pretty much every platform that has a network interface. It's called the loopback interface, and it's actually one of the fastest ways you can do this type of thing. By default, this provides one address for the whole system, but on many platforms, but if you're using IPv4 you can add multiple addresses out of the 127.0.0.0/8 block, and it will generally work correctly (you unfortunately can't do this with IPv6, as there is only one address reserved there for loopback usage).

There are multiple alternative options out there though, depending on what system you're running on:

  • Software bridge interfaces. On many UNIX systems, you can create ethernet bridges in software to provide transparent bridging between multiple physical interfaces. On most such systems, you don't actually have to bind any physical interfaces to them, and can just use the bridges as private internal network interfaces.
  • Linux provides a special driver that can be used to do literally exactly what you're asking for. The virtual devices it provides are known as 'virtual ethernet pair devices'. Using this driver, you get two network interfaces which simulate an (near-zero latency) Ethernet link.
  • Many operating systems that have a modern networking stack provide a special type of network interface allows an application to provide basic network emulation. On most systems, these are known as tun and tap interfaces (the difference is what layer they are emulating), and they're used for a wide variety of things, from VPN interfaces to network emulation for virtual machines.
  • A bit unconventional, but you already mentioned serial emulation software so I'll mention it here: You could run PPP or SLIP over the emulated serial link. This might actually be one of the best options, as it should prevent any optimizations by the OS that might interfere with the routing you want to do.
  • As Lucio Crusca mentioned, you could use a virtual machine for this, although I'd argue that that's probably overkill on most systems (except Windows, because doing complicated networking things there is a pain in the arse).
  • VDE, also known as Virtual Distributed Ethernet, might work for what you need. It's mostly designed for providing an emulated ethernet network to virtual machines that are located physically far from each other, but it can operate locally too.
  • Open vSwitch, another virtualization oriented technology, may similarly be of use to you.
  • Thanks for the batch of great ideas! A network stack native solution like 127.0.0.0/8 would be awesome: know of a how-to for it? I'm a little familiar with tun and tap from OpenVPN: can we get at that in some native way? (My most immediate concern is Windows, I'll update my Q's tag.) – JimB Nov 10 at 15:10
  • Here's something on using OpenVPN's tun driver by itself, which seems not to work for what they're trying, but it's not clear if it would work for UDP. – JimB 2 days ago
  • I think that you can do the same things as the tun and tap drivers on Windows using natively built drivers (this is what most VM offerings on Windows do), but it's a lot more effort. – Austin Hemmelgarn 2 days ago

You didn't tell what OS you are using, anyway it's always possible to install a virtual machine (VirtualBox on Windows, qemu/KVM on Linux for example) and install your software into that.

From there you have a whole virtual network where you can add all kinds of virtual routers you need.

  • Thanks! I considered a VM, but it's pretty heavyweight for just the ethernet driver, and having it fire up on machine start, then start our software, seems like kind of a lot. – JimB Nov 10 at 13:51
  • If you compare it to the hassle of setting up virtual interfaces under Windows, you probably are better off with virtualization. BTW, starting a VM upon boot is quite straightfoward with VirtualBox or any other virtualization system, the same is true for your software into the VM... – Lucio Crusca Nov 10 at 21:51

Your Answer

JimB is a new contributor. Be nice, and check out our Code of Conduct.
 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.