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.
- checksums.yaml +7 -0
- data/README +76 -0
- data/examples/arp-send +24 -0
- data/examples/arp-send2 +30 -0
- data/examples/cdp +39 -0
- data/examples/cdp-spew +52 -0
- data/examples/dhcp +42 -0
- data/examples/dhcp-spew +48 -0
- data/examples/dns +38 -0
- data/examples/egp +30 -0
- data/examples/hsrp +43 -0
- data/examples/hsrp_takeover +69 -0
- data/examples/icmp-recv +34 -0
- data/examples/icmp-spew +50 -0
- data/examples/icmpv6 +84 -0
- data/examples/icmpv6-spew +50 -0
- data/examples/igmpv1 +27 -0
- data/examples/igmpv2 +27 -0
- data/examples/igrp-send +25 -0
- data/examples/ipv6 +35 -0
- data/examples/nat-pimp +32 -0
- data/examples/ntp +38 -0
- data/examples/ntp2 +42 -0
- data/examples/sctp +32 -0
- data/examples/stp-send +21 -0
- data/examples/synflood +147 -0
- data/examples/tcp +43 -0
- data/examples/tcp2udp +65 -0
- data/examples/udp +46 -0
- data/examples/vrrp +34 -0
- data/examples/vtp +28 -0
- data/lib/racket/l2/eightotwodotthree.rb +48 -0
- data/lib/racket/l2/ethernet.rb +62 -0
- data/lib/racket/l2/llc.rb +50 -0
- data/lib/racket/l2/misc.rb +67 -0
- data/lib/racket/l2/snap.rb +40 -0
- data/lib/racket/l2/vlan.rb +61 -0
- data/lib/racket/l2/vtp.rb +124 -0
- data/lib/racket/l2.rb +30 -0
- data/lib/racket/l3/arp.rb +63 -0
- data/lib/racket/l3/cdp.rb +85 -0
- data/lib/racket/l3/egp.rb +53 -0
- data/lib/racket/l3/ipv4.rb +132 -0
- data/lib/racket/l3/ipv6.rb +66 -0
- data/lib/racket/l3/misc.rb +159 -0
- data/lib/racket/l3/stp.rb +81 -0
- data/lib/racket/l3.rb +30 -0
- data/lib/racket/l4/gre.rb +65 -0
- data/lib/racket/l4/icmp.rb +295 -0
- data/lib/racket/l4/icmpv6.rb +446 -0
- data/lib/racket/l4/igmpv1.rb +79 -0
- data/lib/racket/l4/igmpv2.rb +76 -0
- data/lib/racket/l4/igrp.rb +138 -0
- data/lib/racket/l4/misc.rb +35 -0
- data/lib/racket/l4/sctp.rb +163 -0
- data/lib/racket/l4/tcp.rb +152 -0
- data/lib/racket/l4/udp.rb +81 -0
- data/lib/racket/l4/vrrp.rb +95 -0
- data/lib/racket/l4.rb +30 -0
- data/lib/racket/l5/bootp.rb +106 -0
- data/lib/racket/l5/dns.rb +110 -0
- data/lib/racket/l5/hsrp.rb +73 -0
- data/lib/racket/l5/misc.rb +35 -0
- data/lib/racket/l5/nat-pmp.rb +41 -0
- data/lib/racket/l5/ntp.rb +59 -0
- data/lib/racket/l5.rb +30 -0
- data/lib/racket/misc/lv.rb +108 -0
- data/lib/racket/misc/misc.rb +62 -0
- data/lib/racket/misc/orderedhash.rb +63 -0
- data/lib/racket/misc/raw.rb +35 -0
- data/lib/racket/misc/tlv.rb +103 -0
- data/lib/racket/misc/vt.rb +114 -0
- data/lib/racket/misc.rb +30 -0
- data/lib/racket/racket.rb +166 -0
- data/lib/racket/racketpart.rb +66 -0
- data/lib/racket.rb +4 -0
- data/test/l2/ts_ethernet.rb +22 -0
- data/test/l2/ts_misc.rb +23 -0
- data/test/l2/ts_vlan.rb +15 -0
- data/test/l3/ts_ipv4.rb +44 -0
- data/test/l3/ts_ipv6.rb +26 -0
- data/test/l3/ts_misc.rb +31 -0
- data/test/l4/ts_icmp.rb +38 -0
- data/test/l4/ts_tcp.rb +55 -0
- data/test/l4/ts_udp.rb +40 -0
- data/test/misc/ts_lv.rb +59 -0
- data/test/misc/ts_orderedhash.rb +33 -0
- data/test/misc/ts_tlv.rb +47 -0
- data/test/misc/ts_vt.rb +56 -0
- data/test/ts_all.rb +14 -0
- metadata +153 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
# $Id: bootp.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 L5
|
30
|
+
# Bootstrap Protocol -- BOOTP
|
31
|
+
#
|
32
|
+
# RFC951 (http://www.faqs.org/rfcs/rfc951.html)
|
33
|
+
class BOOTP < RacketPart
|
34
|
+
BOOTP_REQUEST = 1
|
35
|
+
BOOTP_REPLY = 2
|
36
|
+
|
37
|
+
# Message type
|
38
|
+
unsigned :type, 8
|
39
|
+
# Hardware address type
|
40
|
+
unsigned :hwtype, 8, { :default => 1 }
|
41
|
+
# Hardware adddress length
|
42
|
+
unsigned :hwlen, 8, { :default => 6 }
|
43
|
+
# Hops between client and server
|
44
|
+
unsigned :hops, 8
|
45
|
+
# Transaction ID
|
46
|
+
unsigned :id, 32
|
47
|
+
# Seceonds elapsed since client started trying to boot
|
48
|
+
unsigned :secs, 16
|
49
|
+
# Flags. Generally unused
|
50
|
+
unsigned :flags, 16
|
51
|
+
# Client IP address
|
52
|
+
octets :cip, 32
|
53
|
+
# "Your" (client) IP address.
|
54
|
+
octets :yip, 32
|
55
|
+
# Server IP address
|
56
|
+
octets :sip, 32
|
57
|
+
# Gateway IP address
|
58
|
+
octets :gip, 32
|
59
|
+
# Client hardware address
|
60
|
+
hex_octets :chaddr, 128
|
61
|
+
# Optional server host name
|
62
|
+
text :server, 512
|
63
|
+
# Boot file name
|
64
|
+
text :file, 1024
|
65
|
+
# Payload
|
66
|
+
rest :payload
|
67
|
+
|
68
|
+
def add_option(number, value)
|
69
|
+
o = Racket::Misc::TLV.new(1,1)
|
70
|
+
o.type = number
|
71
|
+
o.value = value
|
72
|
+
o.length = value.length
|
73
|
+
@options << o.encode
|
74
|
+
end
|
75
|
+
|
76
|
+
def fix!
|
77
|
+
# tack on an EOL to the options
|
78
|
+
newpayload = @options.join + "\xff"
|
79
|
+
|
80
|
+
# pad out to 64 bytes
|
81
|
+
while (newpayload.length != 64)
|
82
|
+
newpayload += "\x00"
|
83
|
+
end
|
84
|
+
|
85
|
+
self.payload = newpayload + self.payload
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
puts "to_s"
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_str
|
93
|
+
puts to_str
|
94
|
+
end
|
95
|
+
|
96
|
+
def initialize(*args)
|
97
|
+
@options = []
|
98
|
+
@options << "\x63\x82\x53\x63" # magic
|
99
|
+
super
|
100
|
+
@autofix = false
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# $Id: dns.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 L5
|
30
|
+
# Domain Name System
|
31
|
+
class DNS < RacketPart
|
32
|
+
# Transaction ID
|
33
|
+
unsigned :tx_id, 16
|
34
|
+
# Response
|
35
|
+
unsigned :response, 1
|
36
|
+
# Opcode
|
37
|
+
unsigned :opcode, 4
|
38
|
+
# Authoritative?
|
39
|
+
unsigned :authoritative, 1
|
40
|
+
# Truncated?
|
41
|
+
unsigned :truncated, 1
|
42
|
+
# Recursion Desired?
|
43
|
+
unsigned :recursion_d, 1
|
44
|
+
# Recursion Available?
|
45
|
+
unsigned :recursion_a, 1
|
46
|
+
# Reserved
|
47
|
+
unsigned :reserved, 1
|
48
|
+
# Answer authenticated?
|
49
|
+
unsigned :auth, 1
|
50
|
+
# Non-authenticated data OK?
|
51
|
+
unsigned :nonauth, 1
|
52
|
+
# Reply Code
|
53
|
+
unsigned :reply_code, 4
|
54
|
+
# Number of questions
|
55
|
+
unsigned :question_rr, 16
|
56
|
+
# Number of answer RR
|
57
|
+
unsigned :answer_rr, 16
|
58
|
+
# Number of authority RR
|
59
|
+
unsigned :authority_rr, 16
|
60
|
+
# Number of additional RR
|
61
|
+
unsigned :additional_rr, 16
|
62
|
+
rest :payload
|
63
|
+
|
64
|
+
def initialize(*args)
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
# Add an additional record. Automatically increases +additional_rr+
|
69
|
+
def add_additional(name, type, klass)
|
70
|
+
self.payload += self.add_record(name, type, klass).encode
|
71
|
+
self.additional_rr += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
# Add an answer record. Automatically increases +answer_rr+
|
75
|
+
def add_answer(name, type, klass)
|
76
|
+
self.payload += self.add_record(name, type, klass).encode
|
77
|
+
self.answer_rr += 1
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add an authority record. Automatically increases +authority_rr+
|
81
|
+
# XXX: broken. authns records are much more complicated than this.
|
82
|
+
def add_authority(name, type, klass)
|
83
|
+
self.payload += self.add_record(name, type, klass).encode
|
84
|
+
self.authority_rr += 1
|
85
|
+
end
|
86
|
+
|
87
|
+
# Add a question record. Automatically increases +question_rr+
|
88
|
+
def add_question(name, type, klass)
|
89
|
+
self.payload += add_record(name, type, klass).encode
|
90
|
+
self.question_rr += 1
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def add_record(name, type, klass)
|
95
|
+
q = Racket::Misc::VT.new(2,2)
|
96
|
+
name.split(/\./).each do |p|
|
97
|
+
lv = Racket::Misc::LV.new(1)
|
98
|
+
lv.values << p
|
99
|
+
lv.lengths << p.length
|
100
|
+
q.value << lv.encode
|
101
|
+
end
|
102
|
+
q.types << type
|
103
|
+
q.types << klass
|
104
|
+
q
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# $Id: hsrp.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 L5
|
30
|
+
# Hot Standby Router Protocol: HSRP
|
31
|
+
#
|
32
|
+
# RFC2281 (http://www.faqs.org/rfcs/rfc2281.html)
|
33
|
+
class HSRP < RacketPart
|
34
|
+
HSRP_HELLO = 0
|
35
|
+
HSRP_COUP = 1
|
36
|
+
HSRP_RESIGN = 2
|
37
|
+
|
38
|
+
HSRP_INITIAL = 0
|
39
|
+
HSRP_LEARN = 1
|
40
|
+
HSRP_LISTEN = 2
|
41
|
+
HSRP_SPEAK = 4
|
42
|
+
HSRP_STANDBY = 8
|
43
|
+
HSRP_ACTIVE = 16
|
44
|
+
|
45
|
+
# Version of the HSRP message contained in this packet. Defaults to 0
|
46
|
+
unsigned :version, 8
|
47
|
+
# Type of the HSRP message contained in this packet.
|
48
|
+
unsigned :opcode, 8
|
49
|
+
# Current state of the router sending the message
|
50
|
+
unsigned :state, 8
|
51
|
+
# Time between the hello messages that this router sends. Obviously only
|
52
|
+
# useful in hello messages
|
53
|
+
unsigned :hellotime, 8
|
54
|
+
# Length of time that this hello message should be considered valid.
|
55
|
+
# Obviously only useful in hello messages.
|
56
|
+
unsigned :holdtime, 8, { :default => 10 }
|
57
|
+
# Priority used to determine active and standby routers. Higher priorities
|
58
|
+
# win, but a higher IP address wins in the event of a tie.
|
59
|
+
unsigned :priority, 8
|
60
|
+
# Standby group
|
61
|
+
unsigned :group, 8
|
62
|
+
# reserved, never used, should be 0
|
63
|
+
unsigned :reserved, 8
|
64
|
+
# Clear-text, 8-character reused password. Defaults to 'cisco'
|
65
|
+
text :password, 64, { :default => 'cisco' }
|
66
|
+
# Virtual IP address used by this group
|
67
|
+
octets :vip, 32
|
68
|
+
# Payload. Generally unused.
|
69
|
+
rest :payload
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# $Id$
|
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 L5
|
30
|
+
# Miscelaneous L3 helper methods
|
31
|
+
module Misc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Racket
|
2
|
+
module L5
|
3
|
+
# Network Address Translation Port Mapping Protocol (NAT-PMP)
|
4
|
+
#
|
5
|
+
# (http://tools.ietf.org/html/draft-cheshire-nat-pmp-03)
|
6
|
+
#
|
7
|
+
# Generic NAT-PMP which all NAT-PMP variants spawn. This should never be used directly.
|
8
|
+
class NATPMPGeneric < RacketPart
|
9
|
+
# Version
|
10
|
+
unsigned :version, 8
|
11
|
+
# Opcode
|
12
|
+
unsigned :opcode, 8
|
13
|
+
rest :message
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super(*args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Send raw NATPMP packets of your own design
|
21
|
+
class NATPMP < NATPMPGeneric
|
22
|
+
rest :payload
|
23
|
+
end
|
24
|
+
|
25
|
+
# NATPMP
|
26
|
+
class NATPMPMappingRequest < NATPMPGeneric
|
27
|
+
unsigned :reserved, 16
|
28
|
+
unsigned :internal_port, 16
|
29
|
+
unsigned :external_port, 16
|
30
|
+
unsigned :lifetime, 32
|
31
|
+
rest :payload
|
32
|
+
|
33
|
+
def initialize(*args)
|
34
|
+
super(*args)
|
35
|
+
self.version = 0
|
36
|
+
self.opcode = 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
## vim: set ts=2 et sw=2:
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# $Id: ntp.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 L5
|
30
|
+
# Network time protocol
|
31
|
+
class NTP < RacketPart
|
32
|
+
# Leap Indicator
|
33
|
+
unsigned :leap, 2
|
34
|
+
# Local Clock Status
|
35
|
+
unsigned :status, 6
|
36
|
+
# Reference Clock Type
|
37
|
+
unsigned :type, 8
|
38
|
+
# Local Clock Precision
|
39
|
+
unsigned :precision, 16
|
40
|
+
# Estimated Error
|
41
|
+
unsigned :error_est, 32
|
42
|
+
# Estimated Drift Rate
|
43
|
+
unsigned :drift_est, 32
|
44
|
+
# Reference Clock Identifier
|
45
|
+
unsigned :ref_clock, 32
|
46
|
+
# Reference Timestamp
|
47
|
+
unsigned :ref_ts, 64
|
48
|
+
# Originate Timestamp
|
49
|
+
unsigned :orig_ts, 64
|
50
|
+
# Receive Timestamp
|
51
|
+
unsigned :rec_ts, 64
|
52
|
+
# Transmit Timestamp
|
53
|
+
unsigned :tr_ts, 64
|
54
|
+
rest :payload
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# vim: set ts=2 et sw=2:
|
59
|
+
|
data/lib/racket/l5.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# $Id: l5.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
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'l5/*.rb')).each { |f| require f }
|
29
|
+
|
30
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# $Id: lv.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 Misc
|
30
|
+
# Simple class to represent data structures that
|
31
|
+
# consist of an arbitrary number of length value pairs.
|
32
|
+
class LV
|
33
|
+
# An array containing the values parsed from this LV
|
34
|
+
attr_accessor :values
|
35
|
+
# The lengths of the values parsed from this LV
|
36
|
+
attr_accessor :lengths
|
37
|
+
# everything else
|
38
|
+
attr_accessor :rest
|
39
|
+
|
40
|
+
# Create a new LV object whose L sizes are specified in +args+
|
41
|
+
def initialize(*args)
|
42
|
+
@sizes = args
|
43
|
+
@values = []
|
44
|
+
@lengths = []
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def decode(data)
|
49
|
+
n = 0
|
50
|
+
values = []
|
51
|
+
lengths = []
|
52
|
+
@sizes.each do |s|
|
53
|
+
# XXX: raise an error here if there is not enough data to
|
54
|
+
# unpack this next LV
|
55
|
+
lengths[n] = data.unpack("#{punpack_string(s)}")[0]
|
56
|
+
data = data.slice(s, data.length)
|
57
|
+
values[n] = data.unpack("a#{lengths[n]}")[0]
|
58
|
+
data = data.slice(lengths[n], data.length)
|
59
|
+
n += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
# data now contains "rest"
|
63
|
+
[lengths, values, data]
|
64
|
+
end
|
65
|
+
|
66
|
+
def decode!(data)
|
67
|
+
@lengths, @values, @rest = self.decode(data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def encode
|
71
|
+
n = 0
|
72
|
+
s = ""
|
73
|
+
@lengths.each do |l|
|
74
|
+
s << [l].pack("#{punpack_string(@sizes[n])}")
|
75
|
+
s << [@values[n]].pack("a#{l}")
|
76
|
+
n += 1
|
77
|
+
end
|
78
|
+
s
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
encode
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_str
|
86
|
+
encode
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def punpack_string(size)
|
92
|
+
s = ""
|
93
|
+
case size
|
94
|
+
when 1
|
95
|
+
s << "C"
|
96
|
+
when 2
|
97
|
+
s << "n"
|
98
|
+
when 4
|
99
|
+
s << "N"
|
100
|
+
else
|
101
|
+
raise ArgumentError, "Size #{s} not supported"
|
102
|
+
end
|
103
|
+
s
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# $Id: misc.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 Misc
|
30
|
+
# Return a number that is at most size bits long
|
31
|
+
def Misc.randbits(size)
|
32
|
+
bits = 0
|
33
|
+
srand Time.now.usec
|
34
|
+
0.upto(size-1) {
|
35
|
+
bits <<= 1
|
36
|
+
bits |= rand(2)
|
37
|
+
}
|
38
|
+
bits
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return a byte that is at most size bytes long
|
42
|
+
def Misc.randbytes(size)
|
43
|
+
bytes = 0
|
44
|
+
0.upto(size-1) {
|
45
|
+
bytes <<= 8
|
46
|
+
bytes |= randbits(8)
|
47
|
+
}
|
48
|
+
bytes
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return a string that is at most size characters long
|
52
|
+
def Misc.randstring(size)
|
53
|
+
s = ""
|
54
|
+
0.upto(size-1) {
|
55
|
+
s += sprintf("%c", randbytes(1))
|
56
|
+
}
|
57
|
+
s.force_encoding("BINARY") if s.respond_to?(:force_encoding)
|
58
|
+
s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# $Id: orderedhash.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 Misc
|
30
|
+
# Simple ordered hash.
|
31
|
+
#
|
32
|
+
# XXX: todo -- add a method for moving/shifting
|
33
|
+
# members around
|
34
|
+
class OrderedHash < Hash
|
35
|
+
def initialize
|
36
|
+
@keys = []
|
37
|
+
end
|
38
|
+
|
39
|
+
def []=(key, val)
|
40
|
+
@keys << key unless (self[key])
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(key)
|
45
|
+
@keys.delete(key)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def each
|
50
|
+
@keys.each { |k| yield k, self[k] }
|
51
|
+
end
|
52
|
+
|
53
|
+
def each_key
|
54
|
+
@keys.each { |k| yield k }
|
55
|
+
end
|
56
|
+
|
57
|
+
def each_value
|
58
|
+
@keys.each { |k| yield self[k] }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# vim: set ts=2 et sw=2:
|