Class: Arpoon::Table

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arpoon/table.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

Types =
{
	0  => :netrom,
	1  => :ether,
	2  => :eether,
	3  => :ax25,
	4  => :pronet,
	5  => :chaos,
	6  => :ieee802,
	7  => :arcnet,
	8  => :appletlk,
	15 => :dlci,
	19 => :atm,
	23 => :metricom,
	24 => :ieee1394,
	27 => :eui64,
	32 => :infiniband
}
Flags =
Bitmap.new(
	completed: 0x02,
	permanent: 0x04,
	publish:   0x08,

	has_requested_trailers: 0x10,
	wants_netmask:          0x20,

	dont_publish: 0x40
)

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



73
74
75
76
77
78
79
80
81
# File 'lib/arpoon/table.rb', line 73

def initialize
	@entries = []

	File.open('/proc/net/arp', 'r').each_line {|line|
		next if line.start_with? 'IP address'

		@entries << Entry.new(*line.split(/\s+/))
	}
end

Instance Method Details

#[](what) ⇒ Object



93
94
95
96
97
# File 'lib/arpoon/table.rb', line 93

def [] (what)
	find {|entry|
		what == entry.ip || what == entry.mac
	}
end

#each(device = nil) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/arpoon/table.rb', line 83

def each (device = nil)
	return enum_for :each, device unless block_given?

	@entries.each {|entry|
		yield entry if !device || device.to_s == entry.device
	}

	self
end