racket2 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/README +76 -0
  2. data/examples/arp-send +24 -0
  3. data/examples/arp-send2 +30 -0
  4. data/examples/cdp +39 -0
  5. data/examples/cdp-spew +52 -0
  6. data/examples/dhcp +42 -0
  7. data/examples/dhcp-spew +48 -0
  8. data/examples/dns +38 -0
  9. data/examples/egp +30 -0
  10. data/examples/hsrp +43 -0
  11. data/examples/hsrp_takeover +69 -0
  12. data/examples/icmp-recv +34 -0
  13. data/examples/icmp-spew +50 -0
  14. data/examples/icmpv6 +84 -0
  15. data/examples/icmpv6-spew +50 -0
  16. data/examples/igmpv1 +27 -0
  17. data/examples/igmpv2 +27 -0
  18. data/examples/igrp-send +25 -0
  19. data/examples/ipv6 +35 -0
  20. data/examples/ipv6-option +40 -0
  21. data/examples/ntp +38 -0
  22. data/examples/ntp2 +42 -0
  23. data/examples/sctp +32 -0
  24. data/examples/stp-send +21 -0
  25. data/examples/synflood +147 -0
  26. data/examples/tcp +43 -0
  27. data/examples/tcp2udp +65 -0
  28. data/examples/udp +46 -0
  29. data/examples/vrrp +34 -0
  30. data/examples/vtp +28 -0
  31. data/lib/racket.rb +4 -0
  32. data/lib/racket/l2.rb +30 -0
  33. data/lib/racket/l2/eightotwodotthree.rb +48 -0
  34. data/lib/racket/l2/ethernet.rb +62 -0
  35. data/lib/racket/l2/llc.rb +50 -0
  36. data/lib/racket/l2/misc.rb +67 -0
  37. data/lib/racket/l2/snap.rb +40 -0
  38. data/lib/racket/l2/vlan.rb +61 -0
  39. data/lib/racket/l2/vtp.rb +124 -0
  40. data/lib/racket/l3.rb +30 -0
  41. data/lib/racket/l3/arp.rb +63 -0
  42. data/lib/racket/l3/cdp.rb +85 -0
  43. data/lib/racket/l3/egp.rb +53 -0
  44. data/lib/racket/l3/ipv4.rb +132 -0
  45. data/lib/racket/l3/ipv6.rb +66 -0
  46. data/lib/racket/l3/misc.rb +165 -0
  47. data/lib/racket/l3/stp.rb +81 -0
  48. data/lib/racket/l4.rb +30 -0
  49. data/lib/racket/l4/gre.rb +65 -0
  50. data/lib/racket/l4/icmp.rb +295 -0
  51. data/lib/racket/l4/icmpv6.rb +460 -0
  52. data/lib/racket/l4/igmpv1.rb +79 -0
  53. data/lib/racket/l4/igmpv2.rb +76 -0
  54. data/lib/racket/l4/igrp.rb +138 -0
  55. data/lib/racket/l4/misc.rb +35 -0
  56. data/lib/racket/l4/sctp.rb +163 -0
  57. data/lib/racket/l4/tcp.rb +152 -0
  58. data/lib/racket/l4/udp.rb +81 -0
  59. data/lib/racket/l4/vrrp.rb +95 -0
  60. data/lib/racket/l5.rb +30 -0
  61. data/lib/racket/l5/bootp.rb +106 -0
  62. data/lib/racket/l5/dns.rb +110 -0
  63. data/lib/racket/l5/hsrp.rb +73 -0
  64. data/lib/racket/l5/misc.rb +35 -0
  65. data/lib/racket/l5/ntp.rb +59 -0
  66. data/lib/racket/misc.rb +30 -0
  67. data/lib/racket/misc/lv.rb +108 -0
  68. data/lib/racket/misc/misc.rb +61 -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/racket.rb +164 -0
  74. data/lib/racket/racketpart.rb +66 -0
  75. data/test/l2/ts_ethernet.rb +22 -0
  76. data/test/l2/ts_misc.rb +23 -0
  77. data/test/l2/ts_vlan.rb +15 -0
  78. data/test/l3/ts_ipv4.rb +44 -0
  79. data/test/l3/ts_ipv6.rb +26 -0
  80. data/test/l3/ts_misc.rb +31 -0
  81. data/test/l4/ts_icmp.rb +38 -0
  82. data/test/l4/ts_tcp.rb +55 -0
  83. data/test/l4/ts_udp.rb +40 -0
  84. data/test/misc/ts_lv.rb +59 -0
  85. data/test/misc/ts_orderedhash.rb +33 -0
  86. data/test/misc/ts_tlv.rb +47 -0
  87. data/test/misc/ts_vt.rb +56 -0
  88. data/test/ts_all.rb +14 -0
  89. metadata +156 -0
@@ -0,0 +1,152 @@
1
+ # $Id: tcp.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
+ # Transmission Control Protocol: TCP
31
+ #
32
+ # RFC793 (http://www.faqs.org/rfcs/rfc793.html)
33
+ class TCP < RacketPart
34
+ # Source port
35
+ unsigned :src_port, 16
36
+ # Destination port
37
+ unsigned :dst_port, 16
38
+ # Sequence number
39
+ unsigned :seq, 32
40
+ # Acknowledgement number
41
+ unsigned :ack, 32
42
+ # Data Offset
43
+ unsigned :offset, 4
44
+ # Reserved
45
+ unsigned :reserved, 4
46
+ # CWR
47
+ unsigned :flag_cwr, 1
48
+ # ECE
49
+ unsigned :flag_ece, 1
50
+ # URG
51
+ unsigned :flag_urg, 1
52
+ # ACK
53
+ unsigned :flag_ack, 1
54
+ # PSH
55
+ unsigned :flag_psh, 1
56
+ # RST
57
+ unsigned :flag_rst, 1
58
+ # SYN
59
+ unsigned :flag_syn, 1
60
+ # FIN
61
+ unsigned :flag_fin, 1
62
+ # Window size
63
+ unsigned :window, 16
64
+ # Checksum
65
+ unsigned :checksum, 16
66
+ # Urgent pointer
67
+ unsigned :urg, 16
68
+ # Payload
69
+ rest :payload
70
+
71
+ # Add an TCP option to this TCP object.
72
+ # All rejiggering will happen when the call to fix!
73
+ # happens automagically.
74
+ # If the result is not on a 32-bit boundry, pad with NOPs.
75
+ def add_option(number, value)
76
+ t = Misc::TLV.new(1,1)
77
+ t.type = number
78
+ t.value = value
79
+ t.length = value.length + 2
80
+ opts = t.encode
81
+ opts += ("\x01" * (4-(opts.size % 4))) if (opts.size % 4) != 0
82
+ @options << opts
83
+ end
84
+
85
+ # Add a raw TCP option to this packet. It is entirely your
86
+ # responsibility (or irresponsibility, as the case may be) to
87
+ # properly pad or otherwise define this
88
+ def add_raw_option(value)
89
+ @options << value
90
+ end
91
+
92
+ # Check the checksum for this TCP packet
93
+ def checksum?(ip_src, ip_dst)
94
+ self.checksum == compute_checksum(ip_src, ip_dst)
95
+ end
96
+
97
+ # Compute and set the checksum for this TCP packet
98
+ def checksum!(ip_src, ip_dst)
99
+ self.checksum = compute_checksum(ip_src, ip_dst)
100
+ end
101
+
102
+ # Fix this packet up for proper sending. Sets the length
103
+ # and checksum properly.
104
+ def fix!(ip_src, ip_dst, next_payload)
105
+ newpayload = @options.join
106
+
107
+ # pad to a multiple of 32 bits
108
+ if ((self.class.bit_length/8 + newpayload.length) % 4 != 0)
109
+ # fill the beginning as needed with NOPs
110
+ while ((self.class.bit_length/8 + newpayload.length) % 4 != 4)
111
+ puts (self.class.bit_length/8 + newpayload.length) % 4
112
+ newpayload = "\x01#{newpayload}"
113
+ end
114
+ end
115
+
116
+ self.payload = newpayload + self.payload + next_payload
117
+ self.offset = self.class.bit_length/32 + newpayload.length/4
118
+ self.checksum!(ip_src, ip_dst)
119
+ self.payload = newpayload
120
+ end
121
+
122
+ def initialize(*args)
123
+ @options = []
124
+ super
125
+ @autofix = false
126
+ end
127
+
128
+ private
129
+ # Compute the checksum for this TCP packet
130
+ def compute_checksum(ip_src, ip_dst)
131
+ tmp = self.offset << 12
132
+ tmp = tmp | (0x0f00 & (self.reserved << 8))
133
+ tmp = tmp | (0x00ff & (
134
+ (self.flag_cwr << 7 & 0b10000000) +
135
+ (self.flag_ece << 6 & 0b01000000) +
136
+ (self.flag_urg << 5 & 0b00100000) +
137
+ (self.flag_ack << 4 & 0b00010000) +
138
+ (self.flag_psh << 3 & 0b00001000) +
139
+ (self.flag_rst << 2 & 0b00000100) +
140
+ (self.flag_syn << 1 & 0b00000010) +
141
+ (self.flag_fin << 0 & 0b00000001)
142
+ ))
143
+
144
+ pseudo = [L3::Misc.ipv42long(ip_src), L3::Misc.ipv42long(ip_dst), 6, self.class.bit_length/8 + self.payload.length ]
145
+ header = [self.src_port, self.dst_port, self.seq, self.ack, tmp,
146
+ self.window, 0, self.urg, self.payload]
147
+ L3::Misc.checksum((pseudo << header).flatten.pack("NNnnnnNNnnnna*"))
148
+ end
149
+ end
150
+ end
151
+ end
152
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,81 @@
1
+ # $Id: udp.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
+ # User Datagram Protocol: UDP
31
+ #
32
+ # RFC768 (http://www.faqs.org/rfcs/rfc768.html)
33
+ class UDP < RacketPart
34
+ # Source Port
35
+ unsigned :src_port, 16
36
+ # Destination Port
37
+ unsigned :dst_port, 16
38
+ # Datagram Length
39
+ unsigned :len, 16
40
+ # Checksum
41
+ unsigned :checksum, 16
42
+ # Payload
43
+ rest :payload
44
+
45
+ # Check the checksum for this UDP datagram
46
+ def checksum?(src_ip, dst_ip)
47
+ self.checksum == 0 || (self.checksum == compute_checksum(src_ip, dst_ip))
48
+ end
49
+
50
+ # Compute and set the checksum for this UDP datagram
51
+ def checksum!(src_ip, dst_ip)
52
+ # set the checksum to 0 for usage in the pseudo header...
53
+ self.checksum = 0
54
+ self.checksum = compute_checksum(src_ip, dst_ip)
55
+ end
56
+
57
+ # Fix this packet up for proper sending. Sets the length
58
+ # and checksum properly.
59
+ def fix!(src_ip, dst_ip)
60
+ self.len = self.class.bit_length/8 + self.payload.length
61
+ self.checksum!(src_ip, dst_ip)
62
+ end
63
+
64
+ def initialize(*args)
65
+ super
66
+ @autofix = false
67
+ end
68
+
69
+ private
70
+ # Compute the checksum for this UDP datagram
71
+ def compute_checksum(src_ip, dst_ip)
72
+ # pseudo header used for checksum calculation as per RFC 768
73
+ pseudo = [L3::Misc.ipv42long(src_ip), L3::Misc.ipv42long(dst_ip), 17, self.payload.length + self.class.bit_length/8 ]
74
+ header = [self.src_port, self.dst_port, self.payload.length + self.class.bit_length/8, 0, self.payload]
75
+ L3::Misc.checksum((pseudo << header).flatten.pack("NNnnnnnna*"))
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,95 @@
1
+ # $Id: vrrp.rb 127 2009-11-29 01:30:46Z jhart $
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
+ # Virtual Router Redundancy Protocol (VRRP)
31
+ # http://tools.ietf.org/html/rfc2338
32
+ # http://tools.ietf.org/html/rfc3768
33
+ class VRRP < RacketPart
34
+ # Version
35
+ unsigned :version, 4
36
+ # VRRP packet type
37
+ unsigned :type, 4
38
+ # Virtual Router Identifier (VRID)
39
+ unsigned :id, 8
40
+ # the sending VRRP router's priority for the virtual router.
41
+ # Higher values equal higher priority.
42
+ unsigned :priority, 8
43
+ # Total number of IPs contained in this VRRP message
44
+ unsigned :num_ips, 8
45
+ # Authentication type (0, 1, 2)
46
+ unsigned :auth_type, 8
47
+ # Advertisement interval
48
+ unsigned :interval, 8
49
+ # Checksum
50
+ unsigned :checksum, 16
51
+ rest :payload
52
+
53
+ # Add a new IP to this message
54
+ def add_ip(ip)
55
+ @ips << L3::Misc.ipv42long(ip)
56
+ end
57
+
58
+ # Add authentication data
59
+ def add_auth(authdata)
60
+ @authdata = authdata[0,8].ljust(32, "\x00")
61
+ end
62
+
63
+ # Validate the checksum
64
+ def checksum?
65
+ self.checksum == compute_checksum
66
+ end
67
+
68
+ # compute and set the checksum
69
+ def checksum!
70
+ self.checksum = compute_checksum
71
+ end
72
+
73
+ # (really, just set the checksum)
74
+ def fix!
75
+ self.payload = [@ips, @authdata].flatten.pack("N#{@ips.size}a*")
76
+ self.num_ips = @ips.size
77
+ self.checksum!
78
+ end
79
+
80
+ def initialize(*args)
81
+ @ips = []
82
+ @authdata = ""
83
+ super
84
+ end
85
+
86
+ private
87
+ def compute_checksum
88
+ # pseudo header used for checksum calculation as per RFC 768
89
+ pseudo = [ ((self.version << 4) | self.type), self.id, self.priority, self.num_ips, self.auth_type, self.interval, 0, self.payload ]
90
+ L3::Misc.checksum(pseudo.pack("CCCCCCna*"))
91
+ end
92
+ end
93
+ end
94
+ end
95
+ # vim: set ts=2 et sw=2:
@@ -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,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: