aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-10-24 01:12:05 +0000
committersotech117 <michael_foiani@brown.edu>2023-10-24 01:12:05 +0000
commit87b6e36391a0a37f5136910dfc331807add61eef (patch)
treeefcf0df633d1cf72545f823d44856394e552f704
parent6ac55a56369b2f98f094e7e36fa917b84c02cd07 (diff)
more descriptive errors to match reference. final commit :)
-rw-r--r--cmd/vhost/main.go4
-rw-r--r--cmd/vrouter/main.go3
-rw-r--r--pkg/ipstack/ipstack.go8
-rwxr-xr-xvhostbin3105198 -> 3105174 bytes
-rwxr-xr-xvrouterbin3105238 -> 3105198 bytes
5 files changed, 6 insertions, 9 deletions
diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go
index e83d1bf..c0e5ad8 100644
--- a/cmd/vhost/main.go
+++ b/cmd/vhost/main.go
@@ -71,11 +71,9 @@ func main() {
if neighbor.VipAddr == address ||
neighbor.VipAddr == hop.VIP && hop.Type == "S" {
bytesWritten, err := ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil)
+ fmt.Printf("Sent %d bytes to %s\n", bytesWritten, neighbor.VipAddr.String())
if err != nil {
fmt.Println(err)
- } else {
- fmt.Printf("Sent %d bytes to %s\n", bytesWritten, neighbor.VipAddr.String())
-
}
}
}
diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go
index bc8cb2b..2736525 100644
--- a/cmd/vrouter/main.go
+++ b/cmd/vrouter/main.go
@@ -90,10 +90,9 @@ func main() {
neighbor.VipAddr == hop.VIP {
// send the message to the neighbor
bytesWritten, err := ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil)
+ fmt.Printf("Sent %d bytes to %s\n", bytesWritten, neighbor.VipAddr.String())
if err != nil {
fmt.Println(err)
- } else {
- fmt.Printf("Sent %d bytes to %s\n", bytesWritten, neighbor.VipAddr.String())
}
}
}
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index d3178b8..fe8d743 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -330,7 +330,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
// check if the interface is up
iface, err := GetInterfaceByName(dest.Name)
if !iface.State {
- return -1, errors.Errorf("error SEND: %s is down", iface.Name)
+ return 0, errors.Errorf("error SEND: %s is down", iface.Name)
}
// if the header is nil, create a new one
if hdr == nil {
@@ -371,7 +371,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
// Assemble the header into a byte array
headerBytes, err := hdr.Marshal()
if err != nil {
- return -1, err
+ return 0, err
}
// Compute the checksum (see below)
@@ -397,7 +397,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
bytesWritten, err := iface.Socket.WriteToUDP(bytesToSend, sendAddr)
if err != nil {
fmt.Println("Error writing to UDP socket")
- return -1, errors.WithMessage(err, "Error writing to UDP socket")
+ return 0, errors.WithMessage(err, "Error writing to UDP socket")
}
return bytesWritten, nil
@@ -1005,4 +1005,4 @@ func CleanUp() {
routingTable = make(map[netip.Prefix]Hop)
time.Sleep(5 * time.Millisecond)
-} \ No newline at end of file
+}
diff --git a/vhost b/vhost
index 8ecce6f..3c30a1f 100755
--- a/vhost
+++ b/vhost
Binary files differ
diff --git a/vrouter b/vrouter
index 948abfc..f86f584 100755
--- a/vrouter
+++ b/vrouter
Binary files differ