ffi-packets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eric Monti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ = ffi-packets
2
+
3
+ A collection of packet structures defined using FFI::Structs.
4
+
5
+ This gem is designed for use with ffi bindings to raw network libraries such as libnet, libdnet, and libpcap.
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ * Fork the project.
10
+ * Make your feature addition or bug fix.
11
+ * Add tests for it. This is important so I don't break it in a
12
+ future version unintentionally.
13
+ * Commit, do not mess with rakefile, version, or history.
14
+ (if you want to have your own version, that is fine but
15
+ bump version in a commit by itself I can ignore when I pull)
16
+ * Send me a pull request. Bonus points for topic branches.
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2010 Eric Monti. See LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "ffi-packets"
9
+ gem.summary = %Q{A collection of common network packets structures}
10
+ gem.description = %Q{A collection of common network packets structures in FFI::Struct form for use with bindings to raw network libraries such as libdnet, libnet, or libpcap.}
11
+ gem.email = "emonti@matasano.com"
12
+ gem.homepage = "http://github.com/emonti/ffi-packets"
13
+ gem.authors = ["Eric Monti"]
14
+ gem.add_dependency "ffi"
15
+ gem.add_dependency "ffi_dry"
16
+ gem.add_development_dependency "rspec"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ if File.exist?('VERSION')
42
+ version = File.read('VERSION')
43
+ else
44
+ version = ""
45
+ end
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "ffi-packets #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ffi-packets}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Monti"]
12
+ s.date = %q{2010-01-02}
13
+ s.description = %q{A collection of common network packets structures in FFI::Struct form for use with bindings to raw network libraries such as libdnet, libnet, or libpcap.}
14
+ s.email = %q{emonti@matasano.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "ffi-packets.gemspec",
27
+ "lib/ffi/packets.rb",
28
+ "lib/ffi/packets/arp.rb",
29
+ "lib/ffi/packets/constants.rb",
30
+ "lib/ffi/packets/eth.rb",
31
+ "lib/ffi/packets/icmp.rb",
32
+ "lib/ffi/packets/ip.rb",
33
+ "lib/ffi/packets/tcp.rb",
34
+ "lib/ffi/packets/udp.rb",
35
+ "lib/ffi/packets/util.rb",
36
+ "spec/ffi-packets_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/emonti/ffi-packets}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{A collection of common network packets structures}
44
+ s.test_files = [
45
+ "spec/ffi-packets_spec.rb",
46
+ "spec/spec_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
55
+ s.add_runtime_dependency(%q<ffi_dry>, [">= 0"])
56
+ s.add_development_dependency(%q<rspec>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<ffi>, [">= 0"])
59
+ s.add_dependency(%q<ffi_dry>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<ffi>, [">= 0"])
64
+ s.add_dependency(%q<ffi_dry>, [">= 0"])
65
+ s.add_dependency(%q<rspec>, [">= 0"])
66
+ end
67
+ end
@@ -0,0 +1,14 @@
1
+
2
+ begin ; require 'rubygems'; rescue LoadError; end
3
+ require 'ffi'
4
+ require 'ffi/dry'
5
+
6
+ require 'ffi/packets/constants'
7
+ require 'ffi/packets/util'
8
+
9
+ require 'ffi/packets/eth'
10
+ require 'ffi/packets/ip'
11
+ require 'ffi/packets/arp'
12
+ require 'ffi/packets/icmp'
13
+ require 'ffi/packets/tcp'
14
+ require 'ffi/packets/udp'
@@ -0,0 +1,60 @@
1
+ # Address resolution Protocol
2
+
3
+ module FFI::Packets
4
+ module Arp
5
+ # ARP header
6
+ #
7
+ # field :hrd, :uint16, :desc => 'format of hardware address'
8
+ # field :pro, :uint16, :desc => 'format of protocol address'
9
+ # field :hln, :uint16, :desc => 'length of hw address (ETH_ADDR_LEN)'
10
+ # field :pln, :uint16, :desc => 'length of proto address (IP_ADDR_LEN)'
11
+ # field :op, :uint16, :desc => 'operation'
12
+ #
13
+ class Hdr < ::FFI::Struct
14
+ include ::FFI::DRY::NetStructHelper
15
+
16
+ dsl_layout do
17
+ field :hrd, :uint16, :desc => 'format of hardware address'
18
+ field :pro, :uint16, :desc => 'format of protocol address'
19
+ field :hln, :uint16, :desc => 'length of hw address (ETH_ADDR_LEN)'
20
+ field :pln, :uint16, :desc => 'length of proto address (IP_ADDR_LEN)'
21
+ field :op, :uint16, :desc => 'operation'
22
+ end
23
+
24
+ # ARP operations
25
+ module Op
26
+ Constants.constants.grep(/^(ARP_OP_([A-Z][A-Z0-9_]+))$/) do
27
+ self.const_set $2, Constants.const_get($1)
28
+ end
29
+
30
+ module_function
31
+ def list
32
+ @@list ||= constants.inject({}){|h,c| h.merge! c => const_get(c) }
33
+ end
34
+ end # Op
35
+ end # Hdr
36
+
37
+ # Ethernet/IP ARP message
38
+ #
39
+ # array :sha, [:uint8, ETH_ADDR_LEN], :desc => 'sender hardware address'
40
+ # array :spa, [:uint8, IP_ADDR_LEN], :desc => 'sender protocol address'
41
+ # array :tha, [:uint8, ETH_ADDR_LEN], :desc => 'target hardware address'
42
+ # array :tpa, [:uint8, IP_ADDR_LEN], :desc => 'target protocol address'
43
+ #
44
+ class Ethip < ::FFI::Struct
45
+ include ::FFI::DRY::NetStructHelper
46
+ ETH_ADDR_LEN = Constants::ETH_ADDR_LEN
47
+ IP_ADDR_LEN = Constants::IP_ADDR_LEN
48
+
49
+ dsl_layout do
50
+ array :sha, [:uint8, ETH_ADDR_LEN], :desc => 'sender hardware address'
51
+ array :spa, [:uint8, IP_ADDR_LEN], :desc => 'sender protocol address'
52
+ array :tha, [:uint8, ETH_ADDR_LEN], :desc => 'target hardware address'
53
+ array :tpa, [:uint8, IP_ADDR_LEN], :desc => 'target protocol address'
54
+ end
55
+
56
+ end # Ethip
57
+
58
+ end # module Arp
59
+
60
+ end
@@ -0,0 +1,478 @@
1
+ module FFI::Packets
2
+ module Constants
3
+
4
+ ARP_HDR_LEN = 8 # base ARP header length
5
+ ARP_ETHIP_LEN = 20 # base ARP message length
6
+
7
+ ARP_HRD_ETH = 0x0001 # ethernet hardware
8
+ ARP_HRD_IEEE802 = 0x0006 # IEEE 802 hardware
9
+
10
+ ARP_PRO_IP = 0x0800 # IP protocol
11
+
12
+ ARP_OP_REQUEST = 1 # request to resolve ha given pa
13
+ ARP_OP_REPLY = 2 # response giving hardware address
14
+ ARP_OP_REVREQUEST = 3 # request to resolve pa given ha
15
+ ARP_OP_REVREPLY = 4 # response giving protocol address
16
+
17
+
18
+ ETH_ADDR_LEN = 6
19
+ ETH_ADDR_BITS = 48
20
+ ETH_TYPE_LEN = 2
21
+ ETH_CRC_LEN = 4
22
+ ETH_HDR_LEN = 14
23
+ ETH_LEN_MIN = 64 # minimum frame length with CRC
24
+ ETH_LEN_MAX = 1518 # maximum frame length with CRC
25
+
26
+ ETH_TYPE_PUP = 0x0200 # PUP protocol
27
+ ETH_TYPE_IP = 0x0800 # IP protocol
28
+ ETH_TYPE_ARP = 0x0806 # address resolution protocol
29
+ ETH_TYPE_REVARP = 0x8035 # reverse addr resolution protocol
30
+ ETH_TYPE_8021Q = 0x8100 # IEEE 802.1Q VLAN tagging
31
+ ETH_TYPE_IPV6 = 0x86DD # IPv6 protocol
32
+ ETH_TYPE_MPLS = 0x8847 # MPLS
33
+ ETH_TYPE_MPLS_MCAST = 0x8848 # MPLS Multicast
34
+ ETH_TYPE_PPPOEDISC = 0x8863 # PPP Over Ethernet Discovery Stage
35
+ ETH_TYPE_PPPOE = 0x8864 # PPP Over Ethernet Session Stage
36
+ ETH_TYPE_LOOPBACK = 0x9000 # used to test interfaces
37
+ ETH_ADDR_BROADCAST = "\xff\xff\xff\xff\xff\xff"
38
+
39
+ # ETH_IS_MULTICAST(ea) (*(ea) & 0x01) # is address mcast/bcast? XXX implement
40
+
41
+
42
+ ICMP_HDR_LEN = 4 # base ICMP header length
43
+ ICMP_LEN_MIN = 8 # minimum ICMP message size, with header
44
+
45
+ # ICMP Types (ICMP::Hdr->icmp_type)
46
+ # http://www.iana.org/assignments/icmp-parameters
47
+
48
+ ICMP_TYPE_ECHOREPLY = 0 # echo reply
49
+ ICMP_TYPE_UNREACH = 3 # dest unreachable, codes:
50
+ ICMP_TYPE_SRCQUENCH = 4 # packet lost, slow down
51
+ ICMP_TYPE_REDIRECT = 5 # shorter route, codes:
52
+ ICMP_TYPE_ALTHOSTADDR = 6 # alternate host address
53
+ ICMP_TYPE_ECHO = 8 # echo service
54
+ ICMP_TYPE_RTRADVERT = 9 # router advertise, codes:
55
+ ICMP_TYPE_RTRSOLICIT = 10 # router solicitation
56
+ ICMP_TYPE_TIMEXCEED = 11 # time exceeded, code:
57
+ ICMP_TYPE_PARAMPROB = 12 # ip header bad
58
+ ICMP_TYPE_TSTAMP = 13 # timestamp request
59
+ ICMP_TYPE_TSTAMPREPLY = 14 # timestamp reply
60
+ ICMP_TYPE_INFO = 15 # information request
61
+ ICMP_TYPE_INFOREPLY = 16 # information reply
62
+ ICMP_TYPE_MASK = 17 # address mask request
63
+ ICMP_TYPE_MASKREPLY = 18 # address mask reply
64
+ ICMP_TYPE_TRACEROUTE = 30 # traceroute
65
+ ICMP_TYPE_DATACONVERR = 31 # data conversion error
66
+ ICMP_TYPE_MOBILE_REDIRECT = 32 # mobile host redirect
67
+ ICMP_TYPE_IPV6_WHEREAREYOU = 33 # IPv6 where-are-you
68
+ ICMP_TYPE_IPV6_IAMHERE = 34 # IPv6 i-am-here
69
+ ICMP_TYPE_MOBILE_REG = 35 # mobile registration req
70
+ ICMP_TYPE_MOBILE_REGREPLY = 36 # mobile registration reply
71
+ ICMP_TYPE_DNS = 37 # domain name request
72
+ ICMP_TYPE_DNSREPLY = 38 # domain name reply
73
+ ICMP_TYPE_SKIP = 39 # SKIP
74
+ ICMP_TYPE_PHOTURIS = 40 # Photuris
75
+
76
+ # ICMP Sub-codes (ICMP::Hdr->icmp_code)
77
+ # http://www.iana.org/assignments/icmp-parameters
78
+
79
+ ICMP_UNREACH_NET = 0 # bad net
80
+ ICMP_UNREACH_HOST = 1 # bad host
81
+ ICMP_UNREACH_PROTO = 2 # bad protocol
82
+ ICMP_UNREACH_PORT = 3 # bad port
83
+ ICMP_UNREACH_NEEDFRAG = 4 # IP_DF caused drop
84
+ ICMP_UNREACH_SRCFAIL = 5 # src route failed
85
+ ICMP_UNREACH_NET_UNKNOWN = 6 # unknown net
86
+ ICMP_UNREACH_HOST_UNKNOWN = 7 # unknown host
87
+ ICMP_UNREACH_ISOLATED = 8 # src host isolated
88
+ ICMP_UNREACH_NET_PROHIB = 9 # for crypto devs
89
+ ICMP_UNREACH_HOST_PROHIB = 10 # ditto
90
+ ICMP_UNREACH_TOSNET = 11 # bad tos for net
91
+ ICMP_UNREACH_TOSHOST = 12 # bad tos for host
92
+ ICMP_UNREACH_FILTER_PROHIB = 13 # prohibited access
93
+ ICMP_UNREACH_HOST_PRECEDENCE = 14 # precedence error
94
+ ICMP_UNREACH_PRECEDENCE_CUTOFF = 15 # precedence cutoff
95
+
96
+ ICMP_REDIRECT_NET = 0 # for network
97
+ ICMP_REDIRECT_HOST = 1 # for host
98
+ ICMP_REDIRECT_TOSNET = 2 # for tos and net
99
+ ICMP_REDIRECT_TOSHOST = 3 # for tos and host
100
+
101
+ ICMP_RTRADVERT_NORMAL = 0 # normal
102
+ ICMP_RTRADVERT_NOROUTE_COMMON = 16 # selective routing
103
+
104
+ ICMP_TIMEXCEED_INTRANS = 0 # ttl==0 in transit
105
+ ICMP_TIMEXCEED_REASS = 1 # ttl==0 in reass
106
+
107
+ ICMP_PARAMPROB_ERRATPTR = 0 # req. opt. absent
108
+ ICMP_PARAMPROB_OPTABSENT = 1 # req. opt. absent
109
+ ICMP_PARAMPROB_LENGTH = 2 # bad length
110
+
111
+ ICMP_PHOTURIS_UNKNOWN_INDEX = 0 # unknown sec index
112
+ ICMP_PHOTURIS_AUTH_FAILED = 1 # auth failed
113
+ ICMP_PHOTURIS_DECOMPRESS_FAILED = 2 # decompress failed
114
+ ICMP_PHOTURIS_DECRYPT_FAILED = 3 # decrypt failed
115
+ ICMP_PHOTURIS_NEED_AUTHN = 4 # no authentication
116
+ ICMP_PHOTURIS_NEED_AUTHZ = 5 # no authorization
117
+
118
+
119
+ ICMP_RTR_PREF_NODEFAULT = 0x80000000 # do not use as default gw
120
+
121
+
122
+ IP_ADDR_LEN = 4 # IP address length
123
+ IP_ADDR_BITS = 32 # IP address bits
124
+ IP_HDR_LEN = 20 # base IP header length
125
+ IP_OPT_LEN = 2 # base IP option length
126
+ IP_OPT_LEN_MAX = 40
127
+ IP_HDR_LEN_MAX = (IP_HDR_LEN + IP_OPT_LEN_MAX)
128
+ IP_LEN_MAX = 65535
129
+ IP_LEN_MIN = IP_HDR_LEN
130
+
131
+ IP_TOS_DEFAULT = 0x00 # default
132
+ IP_TOS_LOWDELAY = 0x10 # low delay
133
+ IP_TOS_THROUGHPUT = 0x08 # high throughput
134
+ IP_TOS_RELIABILITY = 0x04 # high reliability
135
+ IP_TOS_LOWCOST = 0x02 # low monetary cost - XXX
136
+ IP_TOS_ECT = 0x02 # ECN-capable transport
137
+ IP_TOS_CE = 0x01 # congestion experienced
138
+
139
+ IP_TOS__PREC_ROUTINE = 0x00
140
+ IP_TOS__PREC_PRIORITY = 0x20
141
+ IP_TOS__PREC_IMMEDIATE = 0x40
142
+ IP_TOS__PREC_FLASH = 0x60
143
+ IP_TOS__PREC_FLASHOVERRIDE = 0x80
144
+ IP_TOS__PREC_CRITIC_ECP = 0xa0
145
+ IP_TOS__PREC_INTERNETCONTROL = 0xc0
146
+ IP_TOS__PREC_NETCONTROL = 0xe0
147
+
148
+ IP_RF = 0x8000 # reserved
149
+ IP_DF = 0x4000 # don't fragment
150
+ IP_MF = 0x2000 # more fragments (not last frag)
151
+ IP_OFFMASK = 0x1fff # mask for fragment offset
152
+
153
+ IP_TTL_DEFAULT = 64 # default ttl, RFC 1122, RFC 1340
154
+ IP_TTL_MAX = 255 # maximum ttl
155
+
156
+
157
+ # Protocols (proto) - http://www.iana.org/assignments/protocol-numbers
158
+
159
+ IP_PROTO_IP = 0 # dummy for IP
160
+ IP_PROTO_ICMP = 1 # ICMP
161
+ IP_PROTO_IGMP = 2 # IGMP
162
+ IP_PROTO_GGP = 3 # gateway-gateway protocol
163
+ IP_PROTO_IPIP = 4 # IP in IP
164
+ IP_PROTO_ST = 5 # ST datagram mode
165
+ IP_PROTO_TCP = 6 # TCP
166
+ IP_PROTO_CBT = 7 # CBT
167
+ IP_PROTO_EGP = 8 # exterior gateway protocol
168
+ IP_PROTO_IGP = 9 # interior gateway protocol
169
+ IP_PROTO_BBNRCC = 10 # BBN RCC monitoring
170
+ IP_PROTO_NVP = 11 # Network Voice Protocol
171
+ IP_PROTO_PUP = 12 # PARC universal packet
172
+ IP_PROTO_ARGUS = 13 # ARGUS
173
+ IP_PROTO_EMCON = 14 # EMCON
174
+ IP_PROTO_XNET = 15 # Cross Net Debugger
175
+ IP_PROTO_CHAOS = 16 # Chaos
176
+ IP_PROTO_UDP = 17 # UDP
177
+ IP_PROTO_MUX = 18 # multiplexing
178
+ IP_PROTO_DCNMEAS = 19 # DCN measurement
179
+ IP_PROTO_HMP = 20 # Host Monitoring Protocol
180
+ IP_PROTO_PRM = 21 # Packet Radio Measurement
181
+ IP_PROTO_IDP = 22 # Xerox NS IDP
182
+ IP_PROTO_TRUNK1 = 23 # Trunk-1
183
+ IP_PROTO_TRUNK2 = 24 # Trunk-2
184
+ IP_PROTO_LEAF1 = 25 # Leaf-1
185
+ IP_PROTO_LEAF2 = 26 # Leaf-2
186
+ IP_PROTO_RDP = 27 # "Reliable Datagram" proto
187
+ IP_PROTO_IRTP = 28 # Inet Reliable Transaction
188
+ IP_PROTO_TP = 29 # ISO TP class 4
189
+ IP_PROTO_NETBLT = 30 # Bulk Data Transfer
190
+ IP_PROTO_MFPNSP = 31 # MFE Network Services
191
+ IP_PROTO_MERITINP = 32 # Merit Internodal Protocol
192
+ IP_PROTO_SEP = 33 # Sequential Exchange proto
193
+ IP_PROTO_THIRDPC = 34 # Third Party Connect proto
194
+ IP_PROTO_IDPR = 35 # Interdomain Policy Route
195
+ IP_PROTO_XTP = 36 # Xpress Transfer Protocol
196
+ IP_PROTO_DDP = 37 # Datagram Delivery Proto
197
+ IP_PROTO_CMTP = 38 # IDPR Ctrl Message Trans
198
+ IP_PROTO_TPPP = 39 # TP++ Transport Protocol
199
+ IP_PROTO_IL = 40 # IL Transport Protocol
200
+ IP_PROTO_IPV6 = 41 # IPv6
201
+ IP_PROTO_SDRP = 42 # Source Demand Routing
202
+ IP_PROTO_ROUTING = 43 # IPv6 routing header
203
+ IP_PROTO_FRAGMENT = 44 # IPv6 fragmentation header
204
+ IP_PROTO_RSVP = 46 # Reservation protocol
205
+ IP_PROTO_GRE = 47 # General Routing Encap
206
+ IP_PROTO_MHRP = 48 # Mobile Host Routing
207
+ IP_PROTO_ENA = 49 # ENA
208
+ IP_PROTO_ESP = 50 # Encap Security Payload
209
+ IP_PROTO_AH = 51 # Authentication Header
210
+ IP_PROTO_INLSP = 52 # Integated Net Layer Sec
211
+ IP_PROTO_SWIPE = 53 # SWIPE
212
+ IP_PROTO_NARP = 54 # NBMA Address Resolution
213
+ IP_PROTO_MOBILE = 55 # Mobile IP, RFC 2004
214
+ IP_PROTO_TLSP = 56 # Transport Layer Security
215
+ IP_PROTO_SKIP = 57 # SKIP
216
+ IP_PROTO_ICMPV6 = 58 # ICMP for IPv6
217
+ IP_PROTO_NONE = 59 # IPv6 no next header
218
+ IP_PROTO_DSTOPTS = 60 # IPv6 destination options
219
+ IP_PROTO_ANYHOST = 61 # any host internal proto
220
+ IP_PROTO_CFTP = 62 # CFTP
221
+ IP_PROTO_ANYNET = 63 # any local network
222
+ IP_PROTO_EXPAK = 64 # SATNET and Backroom EXPAK
223
+ IP_PROTO_KRYPTOLAN = 65 # Kryptolan
224
+ IP_PROTO_RVD = 66 # MIT Remote Virtual Disk
225
+ IP_PROTO_IPPC = 67 # Inet Pluribus Packet Core
226
+ IP_PROTO_DISTFS = 68 # any distributed fs
227
+ IP_PROTO_SATMON = 69 # SATNET Monitoring
228
+ IP_PROTO_VISA = 70 # VISA Protocol
229
+ IP_PROTO_IPCV = 71 # Inet Packet Core Utility
230
+ IP_PROTO_CPNX = 72 # Comp Proto Net Executive
231
+ IP_PROTO_CPHB = 73 # Comp Protocol Heart Beat
232
+ IP_PROTO_WSN = 74 # Wang Span Network
233
+ IP_PROTO_PVP = 75 # Packet Video Protocol
234
+ IP_PROTO_BRSATMON = 76 # Backroom SATNET Monitor
235
+ IP_PROTO_SUNND = 77 # SUN ND Protocol
236
+ IP_PROTO_WBMON = 78 # WIDEBAND Monitoring
237
+ IP_PROTO_WBEXPAK = 79 # WIDEBAND EXPAK
238
+ IP_PROTO_EON = 80 # ISO CNLP
239
+ IP_PROTO_VMTP = 81 # Versatile Msg Transport
240
+ IP_PROTO_SVMTP = 82 # Secure VMTP
241
+ IP_PROTO_VINES = 83 # VINES
242
+ IP_PROTO_TTP = 84 # TTP
243
+ IP_PROTO_NSFIGP = 85 # NSFNET-IGP
244
+ IP_PROTO_DGP = 86 # Dissimilar Gateway Proto
245
+ IP_PROTO_TCF = 87 # TCF
246
+ IP_PROTO_EIGRP = 88 # EIGRP
247
+ IP_PROTO_OSPF = 89 # Open Shortest Path First
248
+ IP_PROTO_SPRITERPC = 90 # Sprite RPC Protocol
249
+ IP_PROTO_LARP = 91 # Locus Address Resolution
250
+ IP_PROTO_MTP = 92 # Multicast Transport Proto
251
+ IP_PROTO_AX25 = 93 # AX.25 Frames
252
+ IP_PROTO_IPIPENCAP = 94 # yet-another IP encap
253
+ IP_PROTO_MICP = 95 # Mobile Internet Ctrl
254
+ IP_PROTO_SCCSP = 96 # Semaphore Comm Sec Proto
255
+ IP_PROTO_ETHERIP = 97 # Ethernet in IPv4
256
+ IP_PROTO_ENCAP = 98 # encapsulation header
257
+ IP_PROTO_ANYENC = 99 # private encryption scheme
258
+ IP_PROTO_GMTP = 100 # GMTP
259
+ IP_PROTO_IFMP = 101 # Ipsilon Flow Mgmt Proto
260
+ IP_PROTO_PNNI = 102 # PNNI over IP
261
+ IP_PROTO_PIM = 103 # Protocol Indep Multicast
262
+ IP_PROTO_ARIS = 104 # ARIS
263
+ IP_PROTO_SCPS = 105 # SCPS
264
+ IP_PROTO_QNX = 106 # QNX
265
+ IP_PROTO_AN = 107 # Active Networks
266
+ IP_PROTO_IPCOMP = 108 # IP Payload Compression
267
+ IP_PROTO_SNP = 109 # Sitara Networks Protocol
268
+ IP_PROTO_COMPAQPEER = 110 # Compaq Peer Protocol
269
+ IP_PROTO_IPXIP = 111 # IPX in IP
270
+ IP_PROTO_VRRP = 112 # Virtual Router Redundancy
271
+ IP_PROTO_PGM = 113 # PGM Reliable Transport
272
+ IP_PROTO_ANY0HOP = 114 # 0-hop protocol
273
+ IP_PROTO_L2TP = 115 # Layer 2 Tunneling Proto
274
+ IP_PROTO_DDX = 116 # D-II Data Exchange (DDX)
275
+ IP_PROTO_IATP = 117 # Interactive Agent Xfer
276
+ IP_PROTO_STP = 118 # Schedule Transfer Proto
277
+ IP_PROTO_SRP = 119 # SpectraLink Radio Proto
278
+ IP_PROTO_UTI = 120 # UTI
279
+ IP_PROTO_SMP = 121 # Simple Message Protocol
280
+ IP_PROTO_SM = 122 # SM
281
+ IP_PROTO_PTP = 123 # Performance Transparency
282
+ IP_PROTO_ISIS = 124 # ISIS over IPv4
283
+ IP_PROTO_FIRE = 125 # FIRE
284
+ IP_PROTO_CRTP = 126 # Combat Radio Transport
285
+ IP_PROTO_CRUDP = 127 # Combat Radio UDP
286
+ IP_PROTO_SSCOPMCE = 128 # SSCOPMCE
287
+ IP_PROTO_IPLT = 129 # IPLT
288
+ IP_PROTO_SPS = 130 # Secure Packet Shield
289
+ IP_PROTO_PIPE = 131 # Private IP Encap in IP
290
+ IP_PROTO_SCTP = 132 # Stream Ctrl Transmission
291
+ IP_PROTO_FC = 133 # Fibre Channel
292
+ IP_PROTO_RSVPIGN = 134 # RSVP-E2E-IGNORE
293
+ IP_PROTO_RAW = 255 # Raw IP packets
294
+
295
+ IP_PROTO__RESERVED = IP_PROTO_RAW # Reserved
296
+ IP_PROTO__HOPOPTS = IP_PROTO_IP # IPv6 hop-by-hop options
297
+ IP_PROTO_3PC = IP_PROTO_THIRDPC # Third Party Connect proto
298
+
299
+ # Opt bits
300
+
301
+ IP_OPT_CONTROL = 0x00 # control
302
+ IP_OPT_DEBMEAS = 0x40 # debugging & measurement
303
+ IP_OPT_COPY = 0x80 # copy into all fragments
304
+ IP_OPT_RESERVED1 = 0x20
305
+ IP_OPT_RESERVED2 = 0x60
306
+
307
+ # Option types (otype) - http://www.iana.org/assignments/ip-parameters
308
+ #
309
+ # values renamed IP_OPT_* to IP_OTYPE_*
310
+
311
+ IP_OTYPE_EOL = 0 # terminates option list
312
+ IP_OTYPE_NOP = 1 # no operation
313
+ IP_OTYPE_SEC = (2|IP_OPT_COPY) # DoD basic security
314
+ IP_OTYPE_LSRR = (3|IP_OPT_COPY) # loose source route
315
+ IP_OTYPE_TS = (4|IP_OPT_DEBMEAS) # timestamp
316
+ IP_OTYPE_ESEC = (5|IP_OPT_COPY) # DoD extended security
317
+ IP_OTYPE_CIPSO = (6|IP_OPT_COPY) # commercial security
318
+ IP_OTYPE_RR = 7 # record route
319
+ IP_OTYPE_SATID = (8|IP_OPT_COPY) # stream ID (obsolete)
320
+ IP_OTYPE_SSRR = (9|IP_OPT_COPY) # strict source route
321
+ IP_OTYPE_ZSU = 10 # experimental measurement
322
+ IP_OTYPE_MTUP = 11 # MTU probe
323
+ IP_OTYPE_MTUR = 12 # MTU reply
324
+ IP_OTYPE_FINN = (13|IP_OPT_COPY|IP_OPT_DEBMEAS) # exp flow control
325
+ IP_OTYPE_VISA = (14|IP_OPT_COPY) # exp access control
326
+ IP_OTYPE_ENCODE = 15 # ???
327
+ IP_OTYPE_IMITD = (16|IP_OPT_COPY) # IMI traffic descriptor
328
+ IP_OTYPE_EIP = (17|IP_OPT_COPY) # extended IP, RFC 1385
329
+ IP_OTYPE_TR = (18|IP_OPT_DEBMEAS) # traceroute
330
+ IP_OTYPE_ADDEXT = (19|IP_OPT_COPY) # IPv7 ext addr, RFC 1475
331
+ IP_OTYPE_RTRALT = (20|IP_OPT_COPY) # router alert, RFC 2113
332
+ IP_OTYPE_SDB = (21|IP_OPT_COPY) # directed bcast, RFC 1770
333
+ IP_OTYPE_NSAPA = (22|IP_OPT_COPY) # NSAP addresses
334
+ IP_OTYPE_DPS = (23|IP_OPT_COPY) # dynamic packet state
335
+ IP_OTYPE_UMP = (24|IP_OPT_COPY) # upstream multicast
336
+ IP_OTYPE_MAX = 25
337
+
338
+ # Security option data - RFC 791, 3.1
339
+
340
+ IP_OPT_SEC_UNCLASS = 0x0000 # unclassified
341
+ IP_OPT_SEC_CONFID = 0xf135 # confidential
342
+ IP_OPT_SEC_EFTO = 0x789a # EFTO
343
+ IP_OPT_SEC_MMMM = 0xbc4d # MMMM
344
+ IP_OPT_SEC_PROG = 0x5e26 # PROG
345
+ IP_OPT_SEC_RESTR = 0xaf13 # restricted
346
+ IP_OPT_SEC_SECRET = 0xd788 # secret
347
+ IP_OPT_SEC_TOPSECRET = 0x6bc5 # top secret
348
+
349
+ # Timestamp option data - RFC 791, 3.1
350
+
351
+ IP_OPT_TS_TSONLY = 0 # timestamps only
352
+ IP_OPT_TS_TSADDR = 1 # IP address / timestamp pairs
353
+ IP_OPT_TS_PRESPEC = 3 # IP address / zero timestamp pairs
354
+
355
+
356
+ IP6_ADDR_LEN = 16
357
+ IP6_ADDR_BITS = 128
358
+
359
+ IP6_HDR_LEN = 40 # IPv6 header length
360
+ IP6_LEN_MIN = IP6_HDR_LEN
361
+ IP6_LEN_MAX = 65535 # non-jumbo payload
362
+
363
+ IP6_MTU_MIN = 1280 # minimum MTU (1024 + 256)
364
+
365
+ IP6_VERSION = 0x60
366
+ IP6_VERSION_MASK = 0xf0 # ip6_vfc version
367
+
368
+
369
+ # Hop limit (ip6_hlim)
370
+ IP6_HLIM_DEFAULT = 64
371
+ IP6_HLIM_MAX = 255
372
+
373
+
374
+ # Fragmentation offset, reserved, and flags (offlg)
375
+
376
+ IP6_OFF_MASK = 0xfff8 # mask out offset from offlg
377
+ IP6_RESERVED_MASK = 0x0006 # reserved bits in offlg
378
+ IP6_MORE_FRAG = 0x0001 # more-fragments flag
379
+
380
+
381
+ # XXX implement? IP6_OPT_TYPE(o)
382
+ #define IP6_OPT_TYPE(o) ((o) & 0xC0) /* high 2 bits of opt_type */
383
+
384
+ IP6_OPT_PAD1 = 0x00 # 00 0 00000
385
+ IP6_OPT_PADN = 0x01 # 00 0 00001
386
+ IP6_OPT_JUMBO = 0xC2 # 11 0 00010 = 194
387
+ IP6_OPT_JUMBO_LEN = 6
388
+ IP6_OPT_RTALERT = 0x05 # 00 0 00101
389
+ IP6_OPT_RTALERT_LEN = 4
390
+ IP6_OPT_RTALERT_MLD = 0 # Datagram contains an MLD message
391
+ IP6_OPT_RTALERT_RSVP = 1 # Datagram contains an RSVP message
392
+ IP6_OPT_RTALERT_ACTNET = 2 # contains an Active Networks msg
393
+ IP6_OPT_LEN_MIN = 2
394
+
395
+ IP6_OPT_TYPE_SKIP = 0x00 # continue processing on failure
396
+ IP6_OPT_TYPE_DISCARD = 0x40 # discard packet on failure
397
+ IP6_OPT_TYPE_FORCEICMP = 0x80 # discard and send ICMP on failure
398
+ IP6_OPT_TYPE_ICMP = 0xC0 # ...only if non-multicast dst
399
+
400
+ IP6_OPT_MUTABLE = 0x20 # option data may change en route
401
+
402
+
403
+ TCP_HDR_LEN = 20 # base TCP header length
404
+ TCP_OPT_LEN = 2 # base TCP option length
405
+ TCP_OPT_LEN_MAX = 40
406
+ TCP_HDR_LEN_MAX = (TCP_HDR_LEN + TCP_OPT_LEN_MAX)
407
+
408
+ TCP_PORT_MAX = 65535 # maximum port
409
+ TCP_WIN_MAX = 65535 # maximum (unscaled) window
410
+
411
+ TH_FIN = 0x01 # terminates data
412
+ TH_SYN = 0x02 # synchronize sequence numbers
413
+ TH_RST = 0x04 # reset connection
414
+ TH_PUSH = 0x08 # push
415
+ TH_ACK = 0x10 # acknowledgment number set
416
+ TH_URG = 0x20 # urgent pointer set
417
+ TH_ECE = 0x40 # ECN echo, RFC 3168
418
+ TH_CWR = 0x80 # congestion window reduced
419
+
420
+
421
+ # TCP FSM states
422
+
423
+ TCP_STATE_CLOSED = 0 # closed
424
+ TCP_STATE_LISTEN = 1 # listening from connection
425
+ TCP_STATE_SYN_SENT = 2 # active, have sent SYN
426
+ TCP_STATE_SYN_RECEIVED = 3 # have sent and received SYN
427
+
428
+ TCP_STATE_ESTABLISHED = 4 # established
429
+ TCP_STATE_CLOSE_WAIT = 5 # rcvd FIN, waiting for close
430
+
431
+ TCP_STATE_FIN_WAIT_1 = 6 # have closed, sent FIN
432
+ TCP_STATE_CLOSING = 7 # closed xchd FIN, await FIN-ACK
433
+ TCP_STATE_LAST_ACK = 8 # had FIN and close, await FIN-ACK
434
+
435
+ TCP_STATE_FIN_WAIT_2 = 9 # have closed, FIN is acked
436
+ TCP_STATE_TIME_WAIT = 10 # in 2*MSL quiet wait after close
437
+
438
+ TCP_STATE_MAX = 11
439
+
440
+
441
+ # Options (opt_type) - http://www.iana.org/assignments/tcp-parameters
442
+ #
443
+ # renamed TCP_OPT_* to TCP_OTYPE_*
444
+
445
+ TCP_OTYPE_EOL = 0 # end of option list
446
+ TCP_OTYPE_NOP = 1 # no operation
447
+ TCP_OTYPE_MSS = 2 # maximum segment size
448
+ TCP_OTYPE_WSCALE = 3 # window scale factor, RFC 1072
449
+ TCP_OTYPE_SACKOK = 4 # SACK permitted, RFC 2018
450
+ TCP_OTYPE_SACK = 5 # SACK, RFC 2018
451
+ TCP_OTYPE_ECHO = 6 # echo (obsolete), RFC 1072
452
+ TCP_OTYPE_ECHOREPLY = 7 # echo reply (obsolete), RFC 1072
453
+ TCP_OTYPE_TIMESTAMP = 8 # timestamp, RFC 1323
454
+ TCP_OTYPE_POCONN = 9 # partial order conn, RFC 1693
455
+ TCP_OTYPE_POSVC = 10 # partial order service, RFC 1693
456
+ TCP_OTYPE_CC = 11 # connection count, RFC 1644
457
+ TCP_OTYPE_CCNEW = 12 # CC.NEW, RFC 1644
458
+ TCP_OTYPE_CCECHO = 13 # CC.ECHO, RFC 1644
459
+ TCP_OTYPE_ALTSUM = 14 # alt checksum request, RFC 1146
460
+ TCP_OTYPE_ALTSUMDATA = 15 # alt checksum data, RFC 1146
461
+ TCP_OTYPE_SKEETER = 16 # Skeeter
462
+ TCP_OTYPE_BUBBA = 17 # Bubba
463
+ TCP_OTYPE_TRAILSUM = 18 # trailer checksum
464
+ TCP_OTYPE_MD5 = 19 # MD5 signature, RFC 2385
465
+ TCP_OTYPE_SCPS = 20 # SCPS capabilities
466
+ TCP_OTYPE_SNACK = 21 # selective negative acks
467
+ TCP_OTYPE_REC = 22 # record boundaries
468
+ TCP_OTYPE_CORRUPT = 23 # corruption experienced
469
+ TCP_OTYPE_SNAP = 24 # SNAP
470
+ TCP_OTYPE_TCPCOMP = 26 # TCP compression filter
471
+ TCP_OTYPE_MAX = 27
472
+
473
+
474
+ UDP_HDR_LEN = 8
475
+ UDP_PORT_MAX = 65535
476
+
477
+ end
478
+ end