The universal TUN/TAP drivers have been shipping with the Linux kernel for a while now. vtun builds on this to set up point-to-point tunnels that essentially encapsulate Ethernet frames over a TCP connection. Here’s the Ruby code to setup a tap interface so we can start receiving raw Ethernet frames that are being written to this interface.
class TunTap
# Linux 2.6.17: from /usr/include/linux/if_tun.h
TUNSETIFF = 0x400454ca
IFF_TAP = 0x0002
IFF_NO_PI = 0x1000
def self.open
Kernel.open("/dev/net/tun", "w+") do |tap|
# struct ifreq
ifr = [ "", IFF_TAP|IFF_NO_PI ].pack("a16S")
tap.ioctl(TUNSETIFF, ifr)
ifname = ifr[0, 16].gsub(/\x00/, "")
yield(tap, ifname)
end
end
end
So how do you use this? You first open the TunTap interface with a block. The ifname argument will typically be “tap0″ for the first interface opened, “tap1″ for the second and so on.
TunTap.open do |tap, ifname|
end
Inside the block, you can do
pkt = tap.sysread(64*1024)
to receive a raw Ethernet frame written by the networking stack. To inject a frame into the networking stack, use tap.syswrite which are all standard Ruby IO object methods.
When the block returns, the tap interface is automatically destroyed.

Pingback: Buy Facebook Fans
Pingback: guaranteed rankings
Pingback: best supplements for muscle gain
Pingback: Dallas Website Design
Pingback: Dallas Marketing
Pingback: All New Kia Picanto
Pingback: Dallas Wedding Photographers
Pingback: downtown dentist toronto
Pingback: pre workout supplements
Pingback: Escort girl Paris
Pingback: best creatine supplements
Pingback: Grassy Knoll
Pingback: best bcaa
Pingback: stop smoking
Pingback: Cruises Deals
Pingback: LED Lights
Pingback: inkjet cartridges
Pingback: uzaktan egitim
Pingback: read
Pingback: Cary Leung Sun Life
Pingback: Alvin Blog
Pingback: property investment
Pingback: Super Bowl 46 Picks
Pingback: bingo game cage
Pingback: free seo analysis
Pingback: omega-3 fish oil
Pingback: i hate my job
Pingback: bsn syntha-6
Pingback: parkland florida homes
Pingback: motivation for weight loss
Pingback: how to make your hair wavy without heat
Pingback: bleeding while pregnant third trimester
Pingback: Calculator Online
Pingback: URL
Pingback: find
Pingback: Scott Tucker Payday Loans
Pingback: Water Softener
Pingback: electricians
Pingback: movies news
Pingback: Scott Tucker Racing
Pingback: Scott Tucker CBS
Pingback: Scott Tucker CBS
Pingback: Scott Tucker Leawood
Pingback: passive income
Pingback: that is awesome
Pingback: Brazzers Password
Pingback: Appraisal Management Companies
Pingback: broker price opinion companies
Pingback: betta fish accessories
Pingback: Website Hosting Solutions