packetnom 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3ce9ae5feaae80c9ab5fe6ee5304910c3999a57
4
- data.tar.gz: c15e5afb9cd789f7df847ddfcdc75cf6f606a1c3
3
+ metadata.gz: da39ff5a4480b640bc6d56830c833db9d9eace99
4
+ data.tar.gz: e5342d68de92bb8ca831506d4ff7a0be09814a77
5
5
  SHA512:
6
- metadata.gz: 29b2f7bc0be31b0b2493cd5b0fb39c959560da6e6c64c23ad5ae08fa5e07720fc5af0f1fd4cec4c9dae293843b5254b7120780b6a6feb2fccd48906fccc98e80
7
- data.tar.gz: 065c452fba28b6465cfc37dbadd49c2cafb2df6bfa6d897896652eb60f76adee69eea8dedfee57cd14c9682b57ac93b2b3a02e3488091bbf2be79ce7646da512
6
+ metadata.gz: 0be19443b6ec3a24f9067f82ea261a173d7abe48f1a583307928eef13cbb641b59f7568cb00cd404f17d5a598fb2ca029afd7e9c921c5a131153db05f1126f2c
7
+ data.tar.gz: 9f44f180e04fba37d016d42a0b0a55fdf269e8a0eab2eb46388664e55ce42c8e99396824d2c816a314112a9f07d1b8f1686efc02bf9b00bb670723b5bb692d20
data/lib/packet/eth.rb CHANGED
@@ -10,7 +10,7 @@ module Packetnom
10
10
  attr_accessor :type
11
11
 
12
12
  # Initialize the packet
13
- def initialize( bytes )
13
+ def initialize( bytes )
14
14
  # Layer 2
15
15
  @dst = bytes[0..5].join(':')
16
16
  @src = bytes[6..11].join(':')
@@ -20,6 +20,7 @@ module Packetnom
20
20
  def type
21
21
  types = {
22
22
  "0800" => "ip",
23
+ "86dd" => "ipv6"
23
24
  }
24
25
 
25
26
  types[ @type ]
@@ -2,7 +2,7 @@ module Packetnom
2
2
 
3
3
  class Packet
4
4
 
5
- class Ip
5
+ class IPv4
6
6
 
7
7
  # Attributes
8
8
  attr_accessor :version
@@ -40,6 +40,9 @@ module Packetnom
40
40
  alias_method :length, :len
41
41
  alias_method :checksum, :sum
42
42
 
43
+ def protonum
44
+ @proto.to_i
45
+ end
43
46
  def proto
44
47
  protocol( @proto.to_i )
45
48
  end
@@ -0,0 +1,79 @@
1
+ module Packetnom
2
+
3
+ class Packet
4
+
5
+ class IPv6
6
+
7
+ # Attributes
8
+ attr_accessor :version
9
+ attr_accessor :ihl
10
+ attr_accessor :ds
11
+ attr_accessor :len
12
+ attr_accessor :id
13
+ attr_accessor :flags
14
+ attr_accessor :offset
15
+ attr_accessor :ttl
16
+ attr_accessor :proto
17
+ attr_accessor :sum
18
+ attr_accessor :src
19
+ attr_accessor :dst
20
+
21
+ # Initialize the packet
22
+ def initialize( bytes )
23
+ @version = bytes[14].split(//)[0]
24
+ @ihl = bytes[14].split(//)[1]
25
+ @ds = bytes[15]
26
+ @len = bytes[16..17].join().to_i(16)
27
+ @id = bytes[18..19].join()
28
+
29
+ @flags = bytes[20].split(//)[0].to_i(16) #todo
30
+ @offset = "#{bytes[20].split(//)[1]}#{bytes[21]}".to_i(16) #todo
31
+
32
+ @ttl = bytes[22].to_i(16)
33
+ @proto = bytes[23].to_i(16)
34
+ @sum = bytes[24..25].join().to_i(16)
35
+ @src = bytes[26..29].map{|octet| octet.to_i(16).to_s(10)}.join('.')
36
+ @dst = bytes[30..33].map{|octet| octet.to_i(16).to_s(10)}.join('.')
37
+
38
+ end
39
+
40
+ alias_method :length, :len
41
+ alias_method :checksum, :sum
42
+
43
+ def protonum
44
+ @proto.to_i
45
+ end
46
+ def proto
47
+ protocol( @proto.to_i )
48
+ end
49
+ alias_method :protocol, :proto
50
+
51
+ def src
52
+ IPAddress @src
53
+ end
54
+ alias_method :source, :src
55
+ alias_method :from, :src
56
+
57
+
58
+ def dst
59
+ IPAddress @dst
60
+ end
61
+ alias_method :dest, :dst
62
+ alias_method :target, :dst
63
+
64
+ private
65
+
66
+ def protocol( proto )
67
+ protocols = {
68
+ 6 => "tcp",
69
+ 17 => "udp",
70
+ }
71
+
72
+ protocols[ proto ]
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end
data/lib/packet/udp.rb CHANGED
@@ -23,8 +23,8 @@ module Packetnom
23
23
  alias_method :sport, :src_port
24
24
  alias_method :dest_port, :dst_port
25
25
  alias_method :dport, :dst_port
26
- alias_method :len, :length
27
- alias_method :checksum, :sum
26
+ alias_method :len, :length
27
+ alias_method :checksum, :sum
28
28
 
29
29
  end
30
30
 
data/lib/packetnom.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'packet/eth'
2
- require 'packet/ip'
2
+
3
+ require 'packet/ipv4'
4
+ #require 'packet/ipv6'
3
5
 
4
6
  require 'packet/tcp'
5
7
  require 'packet/udp'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packetnom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Mackintosh
@@ -60,7 +60,8 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - lib/packetnom.rb
62
62
  - lib/packet/eth.rb
63
- - lib/packet/ip.rb
63
+ - lib/packet/ipv4.rb
64
+ - lib/packet/ipv6.rb
64
65
  - lib/packet/tcp.rb
65
66
  - lib/packet/udp.rb
66
67
  homepage: http://github.com/mikemackintosh/packetnom