Skip to content

Commit

Permalink
fix mixed tabs w/ spaces indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
garmr-ulfr committed Oct 19, 2023
1 parent 2497714 commit 3b5f264
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
9 changes: 0 additions & 9 deletions actions/action_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package actions_test

import (
"encoding/binary"
"fmt"
"testing"

Expand Down Expand Up @@ -49,14 +48,6 @@ func TestIPv4HeaderChecksum(t *testing.T) {
if chksum != expected {
t.Fatalf("expected %#04x, got %#04x", expected, chksum)
}

if val := binary.BigEndian.Uint16(header[10:]); val != expected {
t.Fatalf("expected %#04x in header, got %#04x", expected, val)
}

if !actions.VerifyIPv4Checksum(header) {
t.Fatal("checksum validation failed")
}
}

func TestSendAction(t *testing.T) {
Expand Down
13 changes: 5 additions & 8 deletions common/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ func UpdateIPv4Checksum(ip *layers.IPv4) {
// CalculateIPv4Checksum calculates the IPv4 checksum for the given bytes.
// copied from gopacket/layers/ip4.go because they didn't export one. for whatever some reason..
func CalculateIPv4Checksum(bytes []byte) uint16 {
buf := make([]byte, len(bytes), 60)
copy(buf, bytes)

// Clear checksum bytes
buf[10] = 0
buf[11] = 0
bytes[10] = 0
bytes[11] = 0

// Compute checksum
var csum uint32
for i := 0; i < len(buf); i += 2 {
csum += uint32(buf[i]) << 8
csum += uint32(buf[i+1])
for i := 0; i < len(bytes); i += 2 {
csum += uint32(bytes[i]) << 8
csum += uint32(bytes[i+1])
}

for csum > 0xFFFF {
Expand Down

0 comments on commit 3b5f264

Please sign in to comment.