Home:ALL Converter>How to implement virtual network interface

How to implement virtual network interface

Ask Time:2013-10-07T10:42:33         Author:user2616158

Json Formatter

I am trying to write a program to simulate some virtual network interfaces. My program runs on a Linux PC, denoted A, connected to a router, denoted R, and A has one physical network interface eth0 with an IPv4 address, say, 192.168.1.2. My program can obtain multiple different IPv4 addresses from the router via DHCP, say, 192.168.1.3, 192.168.1.4, ... (I have done this part by making up some virtual MAC address). What I need to do next is that, when another physical PC, denoted B, which is also connected to the router R, tries to communicate with one of the IPv4 addresses obtained by my program (not the one assigned to the physical interface, eth0, of A), say, 192.168.1.3 it should appear to B that 192.168.1.3 is a "real" network interface. For example, if B ping 192.168.1.3, it should be able to receive response from 192.168.1.3 (even thought the packet actually pass through A's physical network interface eht0). In addition, my program should be able to extract the IP packet on the virtual interface where the whole packet is received.

In other words, what my program wants to accomplish is like the "Bridged Network" in virtual machines like VirutalBox or VMWare Player.

Can someone please tell me what I should start with? Should I use TAP? Are there any existing libraries which I could use? Or should I just create a link layer socket for my purpose? (I read "Datalink Access" in Richard Stevens's Unix Network Programming, but the info is not quite detailed.) Thanks, Tom

Author:user2616158,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19216328/how-to-implement-virtual-network-interface
yy