ip_frag 0.0.2 → 0.0.3
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.
- data/.gitignore +17 -17
- data/.travis.yml +11 -0
- data/Gemfile +5 -3
- data/LICENSE +21 -21
- data/README.md +18 -18
- data/Rakefile +5 -0
- data/ip_frag.gemspec +17 -17
- data/lib/ip_frag.rb +3 -5
- data/lib/ip_frag/generator.rb +35 -7
- data/lib/ip_frag/version.rb +3 -3
- data/spec/generator_spec.rb +20 -2
- metadata +11 -7
data/.gitignore
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
18
|
spec/helper/*.dat
|
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
#- "1.8.7"
|
4
|
+
#- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
#- jruby-18mode # JRuby in 1.8 mode
|
7
|
+
#- jruby-19mode # JRuby in 1.9 mode
|
8
|
+
#- rbx-18mode
|
9
|
+
#- rbx-19mode
|
10
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
11
|
+
# script: rake
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2012 yafei Lee
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2012 yafei Lee
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# IpFrag
|
2
|
-
|
1
|
+
# IpFrag
|
2
|
+
|
3
3
|
Help you quickly create fragged packets, used by network test.
|
4
4
|
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
$ gem install ip_frag
|
9
|
-
|
10
|
-
## Usage
|
11
|
-
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install ip_frag
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
12
|
$ ipgen --size 2000 --mtu 1480
|
13
13
|
|
14
|
-
It will generate **2** UDP packets fragged.
|
15
|
-
|
16
|
-
## Contributing
|
17
|
-
|
18
|
-
1. Fork it
|
19
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
20
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
21
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
22
|
-
5. Create new Pull Request
|
14
|
+
It will generate **2** UDP packets fragged.
|
15
|
+
|
16
|
+
## Contributing
|
17
|
+
|
18
|
+
1. Fork it
|
19
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
20
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
21
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
22
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ip_frag.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/ip_frag/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["yafei Lee"]
|
6
|
-
gem.email = ["lyfi2003@gmail.com"]
|
7
|
-
gem.description = %q{ip frag tool}
|
8
|
-
gem.summary = %q{ip frag tool}
|
9
|
-
gem.homepage = ""
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "ip_frag"
|
15
|
-
gem.require_paths = ["lib"]
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ip_frag/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["yafei Lee"]
|
6
|
+
gem.email = ["lyfi2003@gmail.com"]
|
7
|
+
gem.description = %q{ip frag tool}
|
8
|
+
gem.summary = %q{ip frag tool}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ip_frag"
|
15
|
+
gem.require_paths = ["lib"]
|
16
16
|
gem.version = IPFrag::VERSION
|
17
|
-
gem.add_dependency "DIY-pcap", ">= 0.3.7"
|
18
|
-
end
|
17
|
+
gem.add_dependency "DIY-pcap", ">= 0.3.7"
|
18
|
+
end
|
data/lib/ip_frag.rb
CHANGED
data/lib/ip_frag/generator.rb
CHANGED
@@ -8,22 +8,25 @@ module IPFrag
|
|
8
8
|
|
9
9
|
def split_to_ip_packet
|
10
10
|
ret = []
|
11
|
-
|
11
|
+
|
12
12
|
offset = 0
|
13
13
|
ret << make_ip_packet(packet_offset) do |p|
|
14
14
|
p.offset = make_offset(offset)
|
15
|
+
p.payload = udp_offset( contant(udp_size_from(@size), p), 1)
|
15
16
|
end
|
16
17
|
offset += packet_offset
|
17
18
|
|
18
|
-
(packet_count - 2).times do
|
19
|
+
(packet_count - 2).times do |i|
|
19
20
|
ret << make_ip_packet(packet_offset) do |p|
|
20
21
|
p.offset = make_offset(offset)
|
22
|
+
p.payload = udp_offset( contant(udp_size_from(@size), p), i+2)
|
21
23
|
end
|
22
24
|
offset += packet_offset
|
23
25
|
end
|
24
26
|
|
25
27
|
ret << make_ip_packet(packet_left) do |p|
|
26
28
|
p.offset = make_offset(offset, true)
|
29
|
+
p.payload = udp_offset( contant(udp_size_from(@size), p), packet_count)
|
27
30
|
end
|
28
31
|
|
29
32
|
ret
|
@@ -71,7 +74,6 @@ module IPFrag
|
|
71
74
|
|
72
75
|
def make_ip_packet(size)
|
73
76
|
ip = Mu::Pcap::IPv4.new(src_ip, dst_ip)
|
74
|
-
ip.payload = contant(size)
|
75
77
|
ip.proto = Mu::Pcap::IP::IPPROTO_UDP
|
76
78
|
yield ip if block_given?
|
77
79
|
ip
|
@@ -97,7 +99,7 @@ module IPFrag
|
|
97
99
|
def check_size_mtu
|
98
100
|
|
99
101
|
if @size <= @mtu
|
100
|
-
raise "Size#{@size} MUST be big than Mtu#{@mtu}."
|
102
|
+
raise "Size #{@size} MUST be big than Mtu #{@mtu}."
|
101
103
|
end
|
102
104
|
|
103
105
|
if @mtu <= 0
|
@@ -121,10 +123,36 @@ module IPFrag
|
|
121
123
|
@dst_mac ||= '00:00:00:00:00:02'
|
122
124
|
end
|
123
125
|
|
124
|
-
|
126
|
+
def src_port
|
127
|
+
@src_port ||= 1000
|
128
|
+
end
|
129
|
+
|
130
|
+
def dst_port
|
131
|
+
@dst_port ||= 2000
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
attr_writer :src_ip, :dst_ip, :src_mac, :dst_mac, :src_port, :dst_port
|
136
|
+
|
137
|
+
def udp_offset( udp, packet_num)
|
138
|
+
size = @mtu
|
139
|
+
udp[(packet_num-1)*size..packet_num*size -1 ]
|
140
|
+
end
|
141
|
+
|
142
|
+
def udp_size_from(ip_size)
|
143
|
+
ip_size - 8
|
144
|
+
end
|
145
|
+
|
125
146
|
|
126
|
-
|
127
|
-
|
147
|
+
# 生成特定长度的 UDP 报文
|
148
|
+
def contant(size, ip)
|
149
|
+
return @udp_packet if @udp_packet
|
150
|
+
udp = Mu::Pcap::UDP.new(src_port, dst_port)
|
151
|
+
udp.payload = 'a' * size
|
152
|
+
udp_packet_str = StringIO.new
|
153
|
+
udp.write(udp_packet_str, ip)
|
154
|
+
udp_packet_str.rewind
|
155
|
+
@udp_packet ||= udp_packet_str.read
|
128
156
|
end
|
129
157
|
end
|
130
158
|
|
data/lib/ip_frag/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module IPFrag
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
1
|
+
module IPFrag
|
2
|
+
VERSION = "0.0.3"
|
3
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
describe IPFrag do
|
4
5
|
it "show version" do
|
@@ -13,13 +14,30 @@ describe IPFrag do
|
|
13
14
|
end
|
14
15
|
|
15
16
|
it "#split" do
|
16
|
-
g = IPFrag::Generator.new(
|
17
|
+
g = IPFrag::Generator.new(1000, 80)
|
17
18
|
g.split_to_ip_packet.size.should == 13
|
18
19
|
g.split_to_ethernet_packet.size.should == 13
|
19
20
|
end
|
20
21
|
|
21
22
|
it "#write_dat" do
|
22
23
|
g = IPFrag::Generator.new(2000, 1460)
|
23
|
-
|
24
|
+
FileUtils.mkdir('tmp') rescue nil
|
25
|
+
g.write_dat('tmp')
|
26
|
+
Dir["tmp/*"].size.should == 2
|
27
|
+
FileUtils.rm_rf('tmp')
|
24
28
|
end
|
29
|
+
|
30
|
+
it "#65535 split" do
|
31
|
+
g = IPFrag::Generator.new(65535, 696)
|
32
|
+
g.split_to_ip_packet.size.should == 95
|
33
|
+
g.split_to_ethernet_packet.size.should == 95
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#contant" do
|
37
|
+
g = IPFrag::Generator.new(2000, 1500)
|
38
|
+
ip = mock
|
39
|
+
ip.stub(:pseudo_header).and_return("123")
|
40
|
+
g.contant(g.udp_size_from(1000), ip).size.should == g.udp_size_from(1000) + 8
|
41
|
+
end
|
42
|
+
|
25
43
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip_frag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- yafei Lee
|
@@ -14,8 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2012-
|
18
|
-
default_executable:
|
18
|
+
date: 2012-12-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: DIY-pcap
|
@@ -25,6 +25,7 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 29
|
28
29
|
segments:
|
29
30
|
- 0
|
30
31
|
- 3
|
@@ -43,9 +44,11 @@ extra_rdoc_files: []
|
|
43
44
|
|
44
45
|
files:
|
45
46
|
- .gitignore
|
47
|
+
- .travis.yml
|
46
48
|
- Gemfile
|
47
49
|
- LICENSE
|
48
50
|
- README.md
|
51
|
+
- Rakefile
|
49
52
|
- bin/ipgen
|
50
53
|
- ip_frag.gemspec
|
51
54
|
- lib/ip_frag.rb
|
@@ -54,7 +57,6 @@ files:
|
|
54
57
|
- lib/ip_frag/version.rb
|
55
58
|
- spec/generator_spec.rb
|
56
59
|
- spec/spec_helper.rb
|
57
|
-
has_rdoc: true
|
58
60
|
homepage: ""
|
59
61
|
licenses: []
|
60
62
|
|
@@ -68,6 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
70
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
71
74
|
segments:
|
72
75
|
- 0
|
73
76
|
version: "0"
|
@@ -76,13 +79,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
79
|
requirements:
|
77
80
|
- - ">="
|
78
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
79
83
|
segments:
|
80
84
|
- 0
|
81
85
|
version: "0"
|
82
86
|
requirements: []
|
83
87
|
|
84
88
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.8.24
|
86
90
|
signing_key:
|
87
91
|
specification_version: 3
|
88
92
|
summary: ip frag tool
|