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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e039ab509c97a99fea8c133ac430107da73aca7
4
- data.tar.gz: 98f4d8d484e37e5108fa01a21c76dd812c66a23f
3
+ metadata.gz: 56759251fb9b704112db8a1489cc29f3e652c97a
4
+ data.tar.gz: b2c3d5c831ee7114c28551a202e4b750de6113d2
5
5
  SHA512:
6
- metadata.gz: c6aa7996c8ae420235fa6e787ca0b83a0f6190172cfc665411ede0444997bd9e0c4c6ee3d689aa74e421b16cb01d184d41b4a166494064526fad1727db544f58
7
- data.tar.gz: bb77c6132f5b1c41a9465e8658c68142a128c2044c2c08b38900360f6d4c23bb20c96f63a441b23a21c759230e8a9fc2d488a5407330df00e0e94a66fa2a5630
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
- break if iface.nil?
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
- # Update the internal list of interfaces.
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
- { :name => name,
168
+ { :index => index,
169
+ :name => name,
154
170
  :flags => flags_set }
155
171
  end
156
172
  end
@@ -3,5 +3,5 @@
3
3
  require 'nfnetlink'
4
4
 
5
5
  Netfilter::Netlink.interfaces.each do |iface|
6
- puts "%12s: %s" % [ iface[:name], iface[:flags].join(", ") ]
6
+ puts "[%d] %12s: %s" % [ iface[:index], iface[:name], iface[:flags].join(", ") ]
7
7
  end
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.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-16 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi