packetgen 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/packetgen/config.rb +15 -5
- data/lib/packetgen/header/dns/rrsection.rb +0 -18
- data/lib/packetgen/types/array.rb +73 -4
- data/lib/packetgen/types/int.rb +10 -0
- data/lib/packetgen/version.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: eee53816de9d4f92c8e4eaef9d0e7e366fccdae2
|
4
|
+
data.tar.gz: a02bf2781972588fadd2f9bf2a94603b81353563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf215ff8ebb85469fc383a77a4a92f63cb7b384afa7aabec96b1d69efb2fe41dde5f5b44cefacde92c9af0d3c7c4244c6a1f29ed39d45ac3221b2cd9fe485345
|
7
|
+
data.tar.gz: c0a6cd54c3fb4813bd31e56c718057ad985e8f54d0ae25766d2c445fa0144af2831e34ec7fdc38fe26bb8eedc4be79dbd89a7e99b956463c2a8ef77a5e6a5abd
|
data/lib/packetgen/config.rb
CHANGED
@@ -5,6 +5,7 @@ module PacketGen
|
|
5
5
|
|
6
6
|
# Config class to provide +config+ object to pgconsole
|
7
7
|
# @author Sylvain Daubert
|
8
|
+
# @author Kent 'picat' Gruber
|
8
9
|
class Config
|
9
10
|
|
10
11
|
# Default network interface
|
@@ -20,18 +21,27 @@ module PacketGen
|
|
20
21
|
# @return [String]
|
21
22
|
attr_reader :ip6addr
|
22
23
|
|
23
|
-
# Create a configuration object. If +iface+ is not set,
|
24
|
-
#
|
24
|
+
# Create a configuration object. If +iface+ is not set,
|
25
|
+
# attempt to find it automatically or default to the
|
26
|
+
# first available loopback interface.
|
25
27
|
# @param [String,nil] iface
|
26
28
|
def initialize(iface=nil)
|
27
29
|
if iface.nil?
|
28
|
-
|
29
|
-
|
30
|
+
begin
|
31
|
+
iface = Pcap.lookupdev
|
32
|
+
rescue PCAPRUB::BindingError
|
33
|
+
iface = NetworkInterface.interfaces.select { |iface| iface =~ /lo/ }.first
|
34
|
+
end
|
30
35
|
end
|
31
36
|
@iface = iface
|
32
37
|
|
33
38
|
addresses = NetworkInterface.addresses(iface)
|
34
|
-
@hwaddr =
|
39
|
+
@hwaddr = case RbConfig::CONFIG['target_os']
|
40
|
+
when /darwin/
|
41
|
+
addresses[Socket::AF_LINK][0]['addr'] if addresses[Socket::AF_LINK]
|
42
|
+
else
|
43
|
+
addresses[Socket::AF_PACKET][0]['addr'] if addresses[Socket::AF_PACKET]
|
44
|
+
end
|
35
45
|
@ipaddr = addresses[Socket::AF_INET][0]['addr'] if addresses[Socket::AF_INET]
|
36
46
|
@ip6addr = addresses[Socket::AF_INET6][0]['addr'] if addresses[Socket::AF_INET6]
|
37
47
|
end
|
@@ -30,24 +30,6 @@ module PacketGen
|
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
33
|
-
# Add a ressource record to this section. Increment associated counter
|
34
|
-
# @param [RR,Hash] rr
|
35
|
-
# @return [RRSection] self
|
36
|
-
def <<(rr)
|
37
|
-
push rr
|
38
|
-
@counter.read(@counter.to_i + 1)
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
# Delete a ressource
|
43
|
-
# @param [RR] rr
|
44
|
-
# @return [RR]
|
45
|
-
def delete(rr)
|
46
|
-
obj = super
|
47
|
-
@counter.read(@counter.to_i - 1) if obj
|
48
|
-
obj
|
49
|
-
end
|
50
|
-
|
51
33
|
private
|
52
34
|
|
53
35
|
def record_from_hash(hsh)
|
@@ -6,11 +6,50 @@
|
|
6
6
|
module PacketGen
|
7
7
|
module Types
|
8
8
|
|
9
|
-
# @abstract
|
10
|
-
#
|
9
|
+
# @abstract Base class to define set of {Fields} subclasses.
|
10
|
+
# == #record_from_hash
|
11
|
+
# Subclasses should define private method +#record_from_hash+. This method
|
12
|
+
# is called by {#push} to add an object to the set.
|
13
|
+
#
|
14
|
+
# A default method is defined by {Array}: it calls constructor of class defined
|
15
|
+
# by {.set_of}.
|
11
16
|
# @author Sylvain Daubert
|
12
17
|
class Array < ::Array
|
13
18
|
|
19
|
+
# Separator used in {#to_human}.
|
20
|
+
# May be ovverriden by subclasses
|
21
|
+
HUMAN_SEPARATOR = ','
|
22
|
+
|
23
|
+
# Define type of objects in set. Used by {#read} and {#push}.
|
24
|
+
# @param [Class] klass
|
25
|
+
# @return [void]
|
26
|
+
def self.set_of(klass)
|
27
|
+
@klass = klass
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [Hash] options
|
31
|
+
# @option options [Int] counter Int object used as a counter for this set
|
32
|
+
def initialize(options={})
|
33
|
+
super()
|
34
|
+
@counter = options[:counter]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Populate object from a string
|
38
|
+
# @param [String] str
|
39
|
+
# @return [self]
|
40
|
+
def read(str)
|
41
|
+
clear
|
42
|
+
return self if str.nil?
|
43
|
+
force_binary str
|
44
|
+
klass = self.class.class_eval { @klass }
|
45
|
+
while str.length > 0
|
46
|
+
obj = klass.new.read(str)
|
47
|
+
self.push obj
|
48
|
+
str.slice!(0, obj.sz)
|
49
|
+
end
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
14
53
|
# @abstract depend on private method +#record_from_hash+ which should be
|
15
54
|
# declared by subclasses.
|
16
55
|
# Add an object to this array
|
@@ -25,7 +64,26 @@ module PacketGen
|
|
25
64
|
end
|
26
65
|
super(obj)
|
27
66
|
end
|
28
|
-
|
67
|
+
|
68
|
+
# @abstract depend on private method +#record_from_hash+ which should be
|
69
|
+
# declared by subclasses.
|
70
|
+
# Add an object to this array, and increment associated counter, if any
|
71
|
+
# @param [Object] obj type depends on subclass
|
72
|
+
# @return [Array] self
|
73
|
+
def <<(obj)
|
74
|
+
push obj
|
75
|
+
@counter.read(@counter.to_i + 1) if @counter
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
# Delete an object from this array. Update associated counter if any
|
80
|
+
# @param [Object] obj
|
81
|
+
# @return [Object] deleted object
|
82
|
+
def delete(obj)
|
83
|
+
deleted = super
|
84
|
+
@counter.read(@counter.to_i - 1) if @counter && deleted
|
85
|
+
deleted
|
86
|
+
end
|
29
87
|
|
30
88
|
# Get binary string
|
31
89
|
# @return [String]
|
@@ -36,7 +94,7 @@ module PacketGen
|
|
36
94
|
# Get a human readable string
|
37
95
|
# @return [String]
|
38
96
|
def to_human
|
39
|
-
map(&:to_human).join(
|
97
|
+
map(&:to_human).join(self.class::HUMAN_SEPARATOR)
|
40
98
|
end
|
41
99
|
|
42
100
|
# Get size in bytes
|
@@ -51,6 +109,17 @@ module PacketGen
|
|
51
109
|
def force_binary(str)
|
52
110
|
PacketGen.force_binary str
|
53
111
|
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def record_from_hash(obj)
|
116
|
+
obj_klass = self.class.class_eval { @klass }
|
117
|
+
if obj_klass
|
118
|
+
obj_klass.new(obj)
|
119
|
+
else
|
120
|
+
raise NotImplementedError, 'class should define #record_from_hash or declare type of elements in set with .set_of'
|
121
|
+
end
|
122
|
+
end
|
54
123
|
end
|
55
124
|
end
|
56
125
|
end
|
data/lib/packetgen/types/int.rb
CHANGED
@@ -55,13 +55,23 @@ module PacketGen
|
|
55
55
|
[to_i].pack(@packstr[@endian])
|
56
56
|
end
|
57
57
|
|
58
|
+
# Convert Int to Integer
|
59
|
+
# @return [Integer]
|
58
60
|
def to_i
|
59
61
|
@value || @default
|
60
62
|
end
|
61
63
|
|
64
|
+
# Convert Int to Float
|
65
|
+
# @return [Float]
|
62
66
|
def to_f
|
63
67
|
to_i.to_f
|
64
68
|
end
|
69
|
+
|
70
|
+
# Give size in bytes of self
|
71
|
+
# @return [Integer]
|
72
|
+
def sz
|
73
|
+
to_s.size
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
# One byte integer
|
data/lib/packetgen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packetgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pcaprub
|