summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go99
1 files changed, 29 insertions, 70 deletions
diff --git a/main.go b/main.go
index 1d4d4df..7e172ad 100644
--- a/main.go
+++ b/main.go
@@ -1,90 +1,49 @@
-// This creates a simple hello world window
+// This is a control panel for DNS
package main
import (
- "log"
- "net"
- "github.com/fsnotify/fsnotify"
+ "runtime"
+ // "net"
"git.wit.org/wit/gui"
arg "github.com/alexflint/go-arg"
)
-var me Host
-
func main() {
arg.MustParse(&args)
- // fmt.Println(args.Foo, args.Bar, args.User)
- log.Println("Toolkit = ", args.Toolkit)
-
- me.ips = make(map[string]*IPtype)
- // gui.InitPlugins([]string{"andlabs"})
+ // initialize the maps to track IP addresses and network interfaces
+ me.ipmap = make(map[string]*IPtype)
+ me.ifmap = make(map[int]*IFtype)
- scanInterfaces()
- watchNetworkInterfaces()
- go inotifyNetworkInterfaceChanges()
- gui.Main(initGUI)
-}
+ go checkNetworkChanges()
-func watchNetworkInterfaces() {
- // Get list of network interfaces
- interfaces, _ := net.Interfaces()
+ log()
+ log(true, "this is true")
+ log(false, "this is false")
+ sleep(.4)
+ sleep(.3)
+ sleep(.2)
+ sleep("done scanning net")
+ // exit("done scanning net")
- // Set up a notification channel
- notification := make(chan net.Interface)
+ // Example_listLink()
+ // exit()
- // Start goroutine to watch for changes
- go func() {
- for {
- // Check for changes in each interface
- for _, i := range interfaces {
- if status := i.Flags & net.FlagUp; status != 0 {
- notification <- i
- log.Println("something on i =", i)
- }
- }
- }
- }()
+ log("Toolkit = ", args.Toolkit)
+ // gui.InitPlugins([]string{"andlabs"})
+ gui.Main(initGUI)
}
-func inotifyNetworkInterfaceChanges() error {
- watcher, err := fsnotify.NewWatcher()
- if err != nil {
- return err
- }
- defer watcher.Close()
-
- // Watch for network interface changes
- err = watcher.Add("/sys/class/net")
- if err != nil {
- return err
- }
+/*
+ Poll for changes to the networking settings
+*/
+func checkNetworkChanges() {
for {
- select {
- case event := <-watcher.Events:
- log.Println("inotifyNetworkInterfaceChanges() event =", event)
- if event.Op&fsnotify.Create == fsnotify.Create {
- // Do something on network interface creation
- }
- case err := <-watcher.Errors:
- return err
- }
- }
-}
-
-func scanInterfaces() {
- ifaces, _ := net.Interfaces()
- for _, i := range ifaces {
- log.Println(i)
- addrs, _ := i.Addrs()
- for _, addr := range addrs {
- log.Println("\taddr =", addr)
- switch v := addr.(type) {
- case *net.IPNet:
- log.Println("\t\taddr.(type) = *net.IPNet")
- default:
- log.Println("\t\taddr.(type) =", v)
- }
+ sleep(2)
+ if (runtime.GOOS == "linux") {
+ scanInterfaces()
+ } else {
+ log("Windows and MacOS don't work yet")
}
}
}