diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-10-23 09:58:38 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-10-23 09:58:38 -0400 |
commit | 2809c966d60a562525ca11d87c208531fba96649 (patch) | |
tree | 80cb650bb8d63edceb7c96f3052a23be7b0375cd /pkg/ipstack | |
parent | fce81b0ba78d52427fc2ba43af63732d3205dcf1 (diff) |
fix sent to other iface bug
Diffstat (limited to 'pkg/ipstack')
-rw-r--r-- | pkg/ipstack/ipstack.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index e949824..59afbcd 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -455,16 +455,12 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de } func RecvIP(iface *Interface, isOpen *bool) error { - // deconstruct interface - prefix := iface.IpPrefix - conn := iface.RecvSocket - buffer := make([]byte, MAX_IP_PACKET_SIZE) // TODO: fix wordking // Read on the UDP port // Too much printing so I commented it out // fmt.Println("wating to read from UDP socket") - _, _, err := conn.ReadFromUDP(buffer) + _, _, err := iface.RecvSocket.ReadFromUDP(buffer) if err != nil { return err } @@ -520,18 +516,20 @@ func RecvIP(iface *Interface, isOpen *bool) error { if hdr.Protocol != RIP_PROTOCOL { fmt.Println("I see a non-rip packet") } - if hdr.Dst == prefix.Addr() { - // see if there is a handler for this protocol - if handler, ok := protocolHandlers[hdr.Protocol]; ok { - if hdr.Protocol != RIP_PROTOCOL { - // fmt.Println("this test packet is exactly for me") - } - err := handler(iface, nil, message, hdr) - if err != nil { - fmt.Println(err) + for _, myIface := range myInterfaces { + if hdr.Dst == myIface.IpPrefix.Addr() { + // see if there is a handler for this protocol + if handler, ok := protocolHandlers[hdr.Protocol]; ok { + if hdr.Protocol != RIP_PROTOCOL { + // fmt.Println("this test packet is exactly for me") + } + err := handler(myIface, nil, message, hdr) + if err != nil { + fmt.Println(err) + } } + return nil } - return nil } // 4) check forwarding table. |