diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-10-22 09:30:00 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-10-22 09:30:00 -0400 |
commit | 0e9b4d3c70b0244299706da0992ca0306ce033de (patch) | |
tree | 84e94ee6a4be680409594f72bfe252d5a444af06 /pkg | |
parent | 36b61f5f38bd2aae78353fa112c0787f0a89a31f (diff) |
fix checksum bug
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/ipstack/ipstack.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index 334aab5..4a552cf 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -402,7 +402,21 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de Options: []byte{}, } } else { - hdr.TTL-- + hdr = &ipv4header.IPv4Header{ + Version: 4, + Len: 20, // Header length is always 20 when no IP options + TOS: 0, + TotalLen: ipv4header.HeaderLen + len(message), + ID: 0, + Flags: 0, + FragOff: 0, + TTL: hdr.TTL - 1, + Protocol: protocolNum, + Checksum: 0, // Should be 0 until checksum is computed + Src: *src, + Dst: netip.MustParseAddr(destIP), + Options: []byte{}, + } } // Assemble the header into a byte array @@ -442,8 +456,6 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de } func RecvIP(iface *Interface, isOpen *bool) error { - fmt.Printf("Receiving IP packet on %s\n", iface.Name) - // deconstruct interface prefix := iface.IpPrefix conn := iface.RecvSocket @@ -541,7 +553,7 @@ func RecvIP(iface *Interface, isOpen *bool) error { // if it's a local route, then the name is the interface name for _, neighbor := range myNeighbors[hop.Interface.Name] { if neighbor.VipAddr == hdr.Dst { - err2 := SendIP(nil, neighbor, hdr.Protocol, message, hdr.Dst.String(), hdr) + err2 := SendIP(&hdr.Src, neighbor, hdr.Protocol, message, hdr.Dst.String(), hdr) if err2 != nil { return err2 } @@ -554,7 +566,7 @@ func RecvIP(iface *Interface, isOpen *bool) error { // if it's a rip route, then the check is against the hop vip for _, neighbor := range myNeighbors[hop.Interface.Name] { if neighbor.VipAddr == hop.VIP { - err2 := SendIP(nil, neighbor, hdr.Protocol, message, hdr.Dst.String(), hdr) + err2 := SendIP(&hdr.Src, neighbor, hdr.Protocol, message, hdr.Dst.String(), hdr) if err2 != nil { return err2 } |