-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (34 loc) · 950 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/bradfield-csi-5/chettriyuvraj/Prework-5-Traceroute/pkg/traceroute"
"golang.org/x/sys/unix"
)
/* Default destination */
var DESTADDR unix.SockaddrInet4 = unix.SockaddrInet4{Port: 5431, Addr: [4]byte{0x8E, 0xFA, 0xB7, 0xCE}}
func main() {
if len(os.Args) < 2 {
fmt.Printf("\n\n No destination found, using default \n\n")
traceroute.Trace(DESTADDR)
} else {
/* Grab and validate first arg which should be dest address */
args := os.Args[1:]
destIP := strings.Split(args[0], ".")
if len(destIP) != 4 {
log.Fatal("\n\nInvalid IPv4 address \n\n")
}
destAddr := unix.SockaddrInet4{Port: 5431, Addr: [4]byte{0x00, 0x00, 0x00, 0x00}}
for i := 0; i < 4; i++ {
val, err := strconv.Atoi(destIP[i])
if err != nil || val > 255 {
log.Fatal("\n\nError in IPv4 address \n\n")
}
destAddr.Addr[i] = byte(val)
}
traceroute.Trace(destAddr)
}
}