nfnetlink 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nfnetlink.rb +24 -8
- data/samples/list_interfaces.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56759251fb9b704112db8a1489cc29f3e652c97a
|
4
|
+
data.tar.gz: b2c3d5c831ee7114c28551a202e4b750de6113d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 759bce571acea422ec8efd3d48d4f1359190fbdbe2d381fe4a5d0a866455010939b3bd9b8b780719783b966f3fd3d2ca74aeff51a0630ff7a60eb8dbfaa49c83
|
7
|
+
data.tar.gz: 092ad37e73975bf62e6b7a6398009833b1b32cf51753ad059447480e9cc9a30a22bb02a84e2c1355ba70d431aa7275a321645e03b3c4295d99b8608508daa873
|
data/lib/nfnetlink.rb
CHANGED
@@ -89,6 +89,7 @@ module Netfilter
|
|
89
89
|
@nlif_handle = Netlink.nlif_open
|
90
90
|
raise NetlinkError, "nlif_open has failed" if @nlif_handle.null?
|
91
91
|
|
92
|
+
query_table
|
92
93
|
ObjectSpace.define_finalizer(self, proc { Netlink.nlif_close(@nlif_handle) })
|
93
94
|
end
|
94
95
|
|
@@ -98,7 +99,7 @@ module Netfilter
|
|
98
99
|
# Returns nil if interface does not exist.
|
99
100
|
#
|
100
101
|
def [](index)
|
101
|
-
update_table
|
102
|
+
update_table
|
102
103
|
get_iface(index)
|
103
104
|
end
|
104
105
|
|
@@ -107,23 +108,37 @@ module Netfilter
|
|
107
108
|
#
|
108
109
|
def each
|
109
110
|
update_table
|
110
|
-
|
111
|
-
index = 1
|
112
|
-
loop do
|
111
|
+
for index in 1..65535
|
113
112
|
iface = get_iface(index)
|
114
|
-
|
113
|
+
next if iface.nil?
|
115
114
|
|
116
115
|
yield(iface)
|
117
|
-
index += 1
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
121
119
|
private
|
122
120
|
|
123
121
|
#
|
124
|
-
#
|
122
|
+
# Process netlink events and updates list of interfaces.
|
125
123
|
#
|
126
124
|
def update_table
|
125
|
+
nlif_fd = Netlink.nlif_fd(@nlif_handle)
|
126
|
+
raise NetlinkError, "nlif_fd has failed" if nlif_fd < 0
|
127
|
+
|
128
|
+
nlif_io = IO.new(nlif_fd)
|
129
|
+
rs, _ws, _es = IO.select([nlif_io], [], [], 0)
|
130
|
+
|
131
|
+
if rs and rs.length > 0 and rs[0] == nlif_io
|
132
|
+
if Netlink.nlif_catch(@nlif_handle) < 0
|
133
|
+
raise NetlinkError, "nlif_catch has failed"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Gets the internal list of interfaces.
|
140
|
+
#
|
141
|
+
def query_table
|
127
142
|
if Netlink.nlif_query(@nlif_handle) < 0
|
128
143
|
raise NetlinkError, "nlif_query has failed"
|
129
144
|
end
|
@@ -150,7 +165,8 @@ module Netfilter
|
|
150
165
|
flags = ifflags.read_bytes(ifflags.total).unpack("I")[0]
|
151
166
|
flags_set = IFFLAGS.select { |bit, name| flags & bit != 0 }.values
|
152
167
|
|
153
|
-
{ :
|
168
|
+
{ :index => index,
|
169
|
+
:name => name,
|
154
170
|
:flags => flags_set }
|
155
171
|
end
|
156
172
|
end
|
data/samples/list_interfaces.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nfnetlink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Delugré
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|