mt_racket 1.0.12a

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.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/README +76 -0
  3. data/examples/arp-send +24 -0
  4. data/examples/arp-send2 +30 -0
  5. data/examples/cdp +39 -0
  6. data/examples/cdp-spew +52 -0
  7. data/examples/dhcp +42 -0
  8. data/examples/dhcp-spew +48 -0
  9. data/examples/dns +38 -0
  10. data/examples/egp +30 -0
  11. data/examples/hsrp +43 -0
  12. data/examples/hsrp_takeover +69 -0
  13. data/examples/icmp-recv +34 -0
  14. data/examples/icmp-spew +50 -0
  15. data/examples/icmpv6 +84 -0
  16. data/examples/icmpv6-spew +50 -0
  17. data/examples/igmpv1 +27 -0
  18. data/examples/igmpv2 +27 -0
  19. data/examples/igrp-send +25 -0
  20. data/examples/ipv6 +35 -0
  21. data/examples/nat-pimp +32 -0
  22. data/examples/ntp +38 -0
  23. data/examples/ntp2 +42 -0
  24. data/examples/sctp +32 -0
  25. data/examples/stp-send +21 -0
  26. data/examples/synflood +147 -0
  27. data/examples/tcp +43 -0
  28. data/examples/tcp2udp +65 -0
  29. data/examples/udp +46 -0
  30. data/examples/vrrp +34 -0
  31. data/examples/vtp +28 -0
  32. data/lib/racket/l2/eightotwodotthree.rb +48 -0
  33. data/lib/racket/l2/ethernet.rb +62 -0
  34. data/lib/racket/l2/llc.rb +50 -0
  35. data/lib/racket/l2/misc.rb +67 -0
  36. data/lib/racket/l2/snap.rb +40 -0
  37. data/lib/racket/l2/vlan.rb +61 -0
  38. data/lib/racket/l2/vtp.rb +124 -0
  39. data/lib/racket/l2.rb +30 -0
  40. data/lib/racket/l3/arp.rb +63 -0
  41. data/lib/racket/l3/cdp.rb +85 -0
  42. data/lib/racket/l3/egp.rb +53 -0
  43. data/lib/racket/l3/ipv4.rb +132 -0
  44. data/lib/racket/l3/ipv6.rb +66 -0
  45. data/lib/racket/l3/misc.rb +159 -0
  46. data/lib/racket/l3/stp.rb +81 -0
  47. data/lib/racket/l3.rb +30 -0
  48. data/lib/racket/l4/gre.rb +65 -0
  49. data/lib/racket/l4/icmp.rb +295 -0
  50. data/lib/racket/l4/icmpv6.rb +446 -0
  51. data/lib/racket/l4/igmpv1.rb +79 -0
  52. data/lib/racket/l4/igmpv2.rb +76 -0
  53. data/lib/racket/l4/igrp.rb +138 -0
  54. data/lib/racket/l4/misc.rb +35 -0
  55. data/lib/racket/l4/sctp.rb +163 -0
  56. data/lib/racket/l4/tcp.rb +152 -0
  57. data/lib/racket/l4/udp.rb +81 -0
  58. data/lib/racket/l4/vrrp.rb +95 -0
  59. data/lib/racket/l4.rb +30 -0
  60. data/lib/racket/l5/bootp.rb +106 -0
  61. data/lib/racket/l5/dns.rb +110 -0
  62. data/lib/racket/l5/hsrp.rb +73 -0
  63. data/lib/racket/l5/misc.rb +35 -0
  64. data/lib/racket/l5/nat-pmp.rb +41 -0
  65. data/lib/racket/l5/ntp.rb +59 -0
  66. data/lib/racket/l5.rb +30 -0
  67. data/lib/racket/misc/lv.rb +108 -0
  68. data/lib/racket/misc/misc.rb +62 -0
  69. data/lib/racket/misc/orderedhash.rb +63 -0
  70. data/lib/racket/misc/raw.rb +35 -0
  71. data/lib/racket/misc/tlv.rb +103 -0
  72. data/lib/racket/misc/vt.rb +114 -0
  73. data/lib/racket/misc.rb +30 -0
  74. data/lib/racket/racket.rb +166 -0
  75. data/lib/racket/racketpart.rb +66 -0
  76. data/lib/racket.rb +4 -0
  77. data/test/l2/ts_ethernet.rb +22 -0
  78. data/test/l2/ts_misc.rb +23 -0
  79. data/test/l2/ts_vlan.rb +15 -0
  80. data/test/l3/ts_ipv4.rb +44 -0
  81. data/test/l3/ts_ipv6.rb +26 -0
  82. data/test/l3/ts_misc.rb +31 -0
  83. data/test/l4/ts_icmp.rb +38 -0
  84. data/test/l4/ts_tcp.rb +55 -0
  85. data/test/l4/ts_udp.rb +40 -0
  86. data/test/misc/ts_lv.rb +59 -0
  87. data/test/misc/ts_orderedhash.rb +33 -0
  88. data/test/misc/ts_tlv.rb +47 -0
  89. data/test/misc/ts_vt.rb +56 -0
  90. data/test/ts_all.rb +14 -0
  91. metadata +153 -0
@@ -0,0 +1,295 @@
1
+ # $Id: icmp.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L4
30
+ # Internet Control Message Protcol.
31
+ #
32
+ # RFC792 (http://www.faqs.org/rfcs/rfc792.html)
33
+ #
34
+ # Generic ICMP class from which all ICMP variants spawn. This should never be used directly.
35
+ class ICMPGeneric < RacketPart
36
+ ICMP_TYPE_ECHO_REPLY = 0
37
+ ICMP_TYPE_DESTINATION_UNREACHABLE = 3
38
+ ICMP_TYPE_SOURCE_QUENCH = 4
39
+ ICMP_TYPE_REDIRECT = 5
40
+ ICMP_TYPE_ECHO_REQUEST = 8
41
+ ICMP_TYPE_MOBILE_IP_ADVERTISEMENT = 9
42
+ ICMP_TYPE_ROUTER_SOLICITATION = 10
43
+ ICMP_TYPE_TIME_EXCEEDED = 11
44
+ ICMP_TYPE_PARAMETER_PROBLEM = 12
45
+ ICMP_TYPE_TIMESTAMP_REQUEST = 13
46
+ ICMP_TYPE_TIMESTAMP_REPLY = 14
47
+ ICMP_TYPE_INFO_REQUEST = 15
48
+ ICMP_TYPE_INFO_REPLY = 16
49
+ ICMP_TYPE_ADDRESS_MASK_REQUEST = 17
50
+ ICMP_TYPE_ADDRESS_MASK_REPLY = 18
51
+
52
+ # Type
53
+ unsigned :type, 8
54
+ # Code
55
+ unsigned :code, 8
56
+ # Checksum
57
+ unsigned :checksum, 16
58
+ rest :message
59
+
60
+ # check the checksum for this ICMP packet
61
+ def checksum?
62
+ self.checksum == compute_checksum
63
+ end
64
+
65
+ def initialize(*args)
66
+ super(*args)
67
+ @autofix = false
68
+ end
69
+
70
+
71
+ # compute and set the checksum for this ICMP packet
72
+ def checksum!
73
+ self.checksum = compute_checksum
74
+ end
75
+
76
+ # 'fix' this ICMP packet up for sending.
77
+ # (really, just set the checksum)
78
+ def fix!
79
+ self.checksum!
80
+ end
81
+
82
+ private
83
+ def compute_checksum
84
+ # pseudo header used for checksum calculation as per RFC 768
85
+ pseudo = [ self.type, self.code, 0, self.message ]
86
+ L3::Misc.checksum(pseudo.pack("CCna*"))
87
+ end
88
+ end
89
+
90
+ # Send raw ICMP packets of your own design
91
+ class ICMP < ICMPGeneric
92
+ rest :payload
93
+ end
94
+
95
+ # ICMP Echo. Generic class that ICMPEchoRequest and ICMPEchoReply inherit
96
+ class ICMPEcho < ICMPGeneric
97
+ # ID for tracking requests/replies
98
+ unsigned :id, 16
99
+ # sequence number for tracking request/replies
100
+ unsigned :sequence, 16
101
+ rest :payload
102
+
103
+ def initialize(*args)
104
+ super(*args)
105
+ self.type = 8
106
+ self.code = 0
107
+ end
108
+ end
109
+
110
+ # ICMP Echo Request
111
+ class ICMPEchoRequest < ICMPEcho
112
+ rest :payload
113
+
114
+ def initialize(*args)
115
+ super(*args)
116
+ self.type = 8
117
+ self.code = 0
118
+ end
119
+ end
120
+
121
+ # ICMP Echo Reply
122
+ class ICMPEchoReply < ICMPEcho
123
+ rest :payload
124
+
125
+ def initialize(*args)
126
+ super(*args)
127
+ self.type = 0
128
+ self.code = 0
129
+ end
130
+ end
131
+
132
+ # ICMP Destination Unreachable Message
133
+ class ICMPDestinationUnreachable < ICMPGeneric
134
+ ICMP_CODE_NETWORK_UNREACHABLE = 0
135
+ ICMP_CODE_HOST_UNREACHABLE = 1
136
+ ICMP_CODE_PROTOCOL_UNREACHABLE = 2
137
+ ICMP_CODE_PORT_UNREACHABLE = 3
138
+ ICMP_CODE_FRAG_NEEDED_DF_SET = 4
139
+ ICMP_CODE_SOURCE_ROUTE_FAILED = 5
140
+ # This is never used according to the RFC
141
+ unsigned :unused, 32
142
+ # Internet header + 64 bits of original datagram
143
+ rest :payload
144
+
145
+ def initialize(*args)
146
+ super(*args)
147
+ self.type = 3
148
+ end
149
+ end
150
+
151
+ # ICMP Time Exceeded Message
152
+ class ICMPTimeExceeded < ICMPGeneric
153
+ ICMP_CODE_TTL_EXCEEDED_IN_TRANSIT = 0
154
+ ICMP_CODE_FRAG_REASSEMBLY_TIME_EXCEEDED = 1
155
+ # This is never used according to the RFC
156
+ unsigned :unused, 32
157
+ # Internet header + 64 bits of original datagram
158
+ rest :payload
159
+
160
+ def initialize(*args)
161
+ super(*args)
162
+ self.type = 11
163
+ end
164
+ end
165
+
166
+ # ICMP Parameter Problem Message
167
+ class ICMPParameterProblem < ICMPGeneric
168
+ # pointer to the octet where the error was detected
169
+ unsigned :pointer, 8
170
+ # This is never used according to the RFC
171
+ unsigned :unused, 24
172
+ # Internet header + 64 bits of original datagram
173
+ rest :payload
174
+
175
+ def initialize(*args)
176
+ super(*args)
177
+ self.type = 12
178
+ self.code = 0
179
+ end
180
+ end
181
+
182
+ # ICMP Source Quench Message
183
+ class ICMPSourceQuench < ICMPGeneric
184
+ # This is never used according to the RFC
185
+ unsigned :unused, 32
186
+ # Internet header + 64 bits of original datagram
187
+ rest :payload
188
+
189
+ def initialize(*args)
190
+ super(*args)
191
+ self.type = 4
192
+ self.code = 0
193
+ end
194
+ end
195
+
196
+ # ICMP Redirect Message
197
+ class ICMPRedirect < ICMPGeneric
198
+ ICMP_CODE_REDIRECT_NETWORK = 0
199
+ ICMP_CODE_REDIRECT_HOST = 1
200
+ ICMP_CODE_REDIRECT_TOS_NETWORK = 2
201
+ ICMP_CODE_REDIRECT_TOS_HOST = 3
202
+
203
+ # Gateway internet address
204
+ octets :gateway_ip, 32
205
+ # Internet header + 64 bits of original datagram
206
+ rest :payload
207
+
208
+ def initialize(*args)
209
+ super(*args)
210
+ self.type = 5
211
+ self.code = 0
212
+ end
213
+ end
214
+
215
+ # Generic ICMP Timestamp Message from which ICMPTimestampRequest and
216
+ # ICMPTimestampReply inherit
217
+ class ICMPTimestamp < ICMPGeneric
218
+ # an identifier to add in matching timestamp and replies
219
+ unsigned :id, 16
220
+ # a sequence number to aid in matching timestamp and replies
221
+ unsigned :sequence, 16
222
+ # time the sender last touched the message before sending it in number of milliseconds since midnight UT
223
+ unsigned :originate_timestamp, 32
224
+ # time the echoer first touched it on receipt in number of milliseconds since midnight UT
225
+ unsigned :receive_timestamp, 32
226
+ # time the echoers last touched the message on sending it in number of milliseconds since midnight UT
227
+ unsigned :transmit_timestamp, 32
228
+ # probably never used ...
229
+ rest :payload
230
+
231
+ def initialize(*args)
232
+ super(*args)
233
+ end
234
+
235
+ end
236
+
237
+ # ICMP Timestamp Request Message
238
+ class ICMPTimestampRequest < ICMPTimestamp
239
+ # probably never used ...
240
+ rest :payload
241
+
242
+ def initialize(*args)
243
+ super(*args)
244
+ self.type = 13
245
+ self.code = 0
246
+ end
247
+ end
248
+
249
+ # ICMP Timestamp Reply Message
250
+ class ICMPTimestampReply < ICMPTimestamp
251
+ # probably never used ...
252
+ rest :payload
253
+
254
+ def initialize(*args)
255
+ super(*args)
256
+ self.type = 14
257
+ self.code = 0
258
+ end
259
+ end
260
+
261
+ # ICMP Information Request Message
262
+ class ICMPInformationRequest < ICMPGeneric
263
+ # an identifier to add in matching timestamp and replies
264
+ unsigned :id, 16
265
+ # a sequence number to aid in matching timestamp and replies
266
+ unsigned :sequence, 16
267
+ # probably never used ...
268
+ rest :payload
269
+
270
+ def initialize(*args)
271
+ super(*args)
272
+ self.type = 15
273
+ self.code = 0
274
+ end
275
+
276
+ end
277
+
278
+ # ICMP Information Reply Message
279
+ class ICMPInformationReply < ICMPGeneric
280
+ # an identifier to add in matching timestamp and replies
281
+ unsigned :id, 16
282
+ # a sequence number to aid in matching timestamp and replies
283
+ unsigned :sequence, 16
284
+ # probably never used ...
285
+ rest :payload
286
+
287
+ def initialize(*args)
288
+ super(*args)
289
+ self.type = 16
290
+ self.code = 0
291
+ end
292
+ end
293
+ end
294
+ end
295
+ # vim: set ts=2 et sw=2: