From 2809c966d60a562525ca11d87c208531fba96649 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 23 Oct 2023 09:58:38 -0400 Subject: fix sent to other iface bug --- pkg/ipstack/ipstack.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'pkg/ipstack/ipstack.go') 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. -- cgit v1.2.3-70-g09d2