From 8410dde94f746c254d62461947abbe68d25009b2 Mon Sep 17 00:00:00 2001 From: David Doan Date: Mon, 23 Oct 2023 18:00:09 -0400 Subject: comments and refactoring --- cmd/vhost/main.go | 7 ++++--- cmd/vrouter/main.go | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go index 26280ef..a72dc98 100644 --- a/cmd/vhost/main.go +++ b/cmd/vhost/main.go @@ -56,8 +56,9 @@ func main() { // combine message into one string messageToSend := strings.Join(message, " ") messageToSendBytes := []byte(messageToSend) - - hop, err := ipstack.LongestPrefix(netip.MustParseAddr(ipAddr)) + + address, _ := netip.ParseAddr(ipAddr) + hop, err := ipstack.LongestPrefix(address) if err != nil { fmt.Println(err) continue @@ -65,7 +66,7 @@ func main() { myAddr := hop.Interface.IpPrefix.Addr() for _, neighbor := range ipstack.GetNeighbors()[hop.Interface.Name] { // TODO: fix multiple send bug here on static route - if neighbor.VipAddr == netip.MustParseAddr(ipAddr) || + if neighbor.VipAddr == address || neighbor.VipAddr == hop.VIP && hop.Type == "S" { bytesWritten, err := ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil) if err != nil { diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go index 02104c5..0bc4d98 100644 --- a/cmd/vrouter/main.go +++ b/cmd/vrouter/main.go @@ -76,7 +76,8 @@ func main() { messageToSendBytes := []byte(messageToSend) // get the longest prefix match for the destination - hop, err := ipstack.LongestPrefix(netip.MustParseAddr(ipAddr)) + address, _ := netip.ParseAddr(ipAddr) + hop, err := ipstack.LongestPrefix(address) if err != nil { fmt.Println(err) continue @@ -85,7 +86,7 @@ func main() { myAddr := hop.Interface.IpPrefix.Addr() // attempt to send the message to the destination for _, neighbor := range ipstack.GetNeighbors()[hop.Interface.Name] { - if neighbor.VipAddr == netip.MustParseAddr(ipAddr) || + if neighbor.VipAddr == address || neighbor.VipAddr == hop.VIP { // send the message to the neighbor bytesWritten, err := ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil) -- cgit v1.2.3-70-g09d2