Reputation: 93
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
Upvotes: 0
Views: 878
Reputation: 1146
From my understanding of your requirement, you can use the subinterfaces. You can split the eth0 to multiple interfaces like eth0:1 eth0:2 etc. Then you can assign IP for each of these interfaces and use them as regular interfaces. You can run run tcpdump/wireshark on these subinterfaces and capture the packets as you wish.
Upvotes: 0