4 namespace eval excentis {
14 namespace eval basic {
23 proc Checksum.Udp.Calculate { frame {vlanCount 0} } {
36 foreach {byte} $temp {
37 lappend frame [
format 0x%02X $byte]
41 set offSet [
expr 14 + $vlanCount * 4]
42 set frame [
lrange $frame $offSet end]
45 set protocol [
lrange $frame 9 9 ]
46 set sourceIp [
lrange $frame 12 15 ]
47 set destIp [
lrange $frame 16 19 ]
48 set sourcePort [
lrange $frame 20 21 ]
49 set destPort [
lrange $frame 22 23 ]
50 set udpLength [
lrange $frame 24 25 ]
51 set udpData [
lrange $frame 28 end ]
54 set checksumCalcBytes [ list ]
55 eval lappend checksumCalcBytes $sourceIp $destIp "0x00" $protocol $udpLength $sourcePort $destPort $udpLength "0x00" "0x00" $udpData
56 if { [ expr [llength $udpData ] % 2 ] != 0} {
57 eval lappend checksumCalcBytes "0x00"
66 proc Checksum.Udpv6.Calculate { frame {vlanCount 0} } {
79 foreach {byte} $temp {
80 lappend frame [
format 0x%02X $byte]
84 set offSet [
expr 14 + $vlanCount * 4]
85 set frame [
lrange $frame $offSet end]
88 set nextHeader [
lrange $frame 6 6 ]
89 set sourceIp [
lrange $frame 8 23 ]
90 set destIp [
lrange $frame 24 39 ]
91 set sourcePort [
lrange $frame 40 41 ]
92 set destPort [
lrange $frame 42 43 ]
93 set udpLength [
lrange $frame 44 45 ]
94 set udpData [
lrange $frame 48 end ]
97 set checksumCalcBytes [ list ]
98 eval lappend checksumCalcBytes $sourceIp $destIp "0x00" "0x00" $udpLength "0x00" "0x00" "0x00" $nextHeader $sourcePort $destPort $udpLength "0x00" "0x00" $udpData
99 if { [ expr [llength $udpData ] % 2 ] != 0} {
100 eval lappend checksumCalcBytes "0x00"
109 proc Checksum.Tcp.Calculate { frame {vlanCount 0} } {
122 foreach {byte} $temp {
123 lappend frame [
format 0x%02X $byte]
127 set offSet [
expr 14 + $vlanCount * 4]
128 set frame [
lrange $frame $offSet end]
132 set protocol [
lrange $frame 9 9 ]
133 set sourceIp [
lrange $frame 12 15 ]
134 set destIp [
lrange $frame 16 19 ]
135 set sourcePort [
lrange $frame 20 21 ]
136 set destPort [
lrange $frame 22 23 ]
137 set seqNumber [
lrange $frame 24 27 ]
138 set ackNumber [
lrange $frame 28 31 ]
139 set stuff [
lrange $frame 32 33 ]
140 set window [
lrange $frame 34 35 ]
141 set urgPointer [
lrange $frame 38 39 ]
142 set tcpData [
lrange $frame 40 end ]
145 set checksumCalcBytes [ list ]
146 eval lappend checksumCalcBytes $sourceIp $destIp "0x00" $protocol $tcpLength $sourcePort $destPort $seqNumber $ackNumber $stuff $window "0x00" "0x00" $urgPointer $tcpData
147 if { [ expr [llength $tcpData ] % 2 ] != 0} {
148 eval lappend checksumCalcBytes "0x00"
157 proc Checksum.Tcpv6.Calculate { frame {vlanCount 0} } {
170 foreach {byte} $temp {
171 lappend frame [
format 0x%02X $byte]
175 set offSet [
expr 14 + $vlanCount * 4]
176 set frame [
lrange $frame $offSet end]
179 set tcpLength [
lrange $frame 4 5 ]
180 set nextHeader [
lrange $frame 6 6 ]
181 set sourceIp [
lrange $frame 8 23 ]
182 set destIp [
lrange $frame 24 39 ]
183 set sourcePort [
lrange $frame 40 41 ]
184 set destPort [
lrange $frame 42 43 ]
185 set seqNumber [
lrange $frame 44 47 ]
186 set ackNumber [
lrange $frame 48 51 ]
187 set stuff [
lrange $frame 52 53 ]
188 set window [
lrange $frame 54 55 ]
189 set urgPointer [
lrange $frame 58 59 ]
190 set tcpData [
lrange $frame 60 end ]
193 set checksumCalcBytes [ list ]
194 eval lappend checksumCalcBytes $sourceIp $destIp $tcpLength "0x00" "0x00" "0x00" $nextHeader $sourcePort $destPort $seqNumber $ackNumber $stuff $window "0x00" "0x00" $urgPointer $tcpData
195 if { [ expr [llength $tcpData ] % 2 ] != 0} {
196 eval lappend checksumCalcBytes "0x00"
205 proc Checksum.Ipv4.Calculate { frame {vlanCount 0} } {
217 foreach { byte } $temp {
218 lappend frame [
format 0x%02X $byte]
222 set offSet [
expr 14 + $vlanCount * 4]
223 set frame [
lrange $frame $offSet end]
226 set ihl [
expr [
lindex $frame 0] & 0x0F ]
227 set prechecksum [
lrange $frame 0 9 ]
228 set postchecksum [
lrange $frame 12 [
expr 4 * $ihl - 1] ]