diff options
Diffstat (limited to 'pkg/ipstack/ipstack.go')
-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. |