diff options
| author | Jeff Carr <[email protected]> | 2024-01-21 02:23:47 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-21 02:23:47 -0600 |
| commit | 433d83e63678e4483e1d8af2e522c7b05c7d7909 (patch) | |
| tree | 7a6168fd19f27c5af9b241c45d0fe33ef9be21d7 /net.go | |
| parent | fdac7e7b8944d51b8207c1797edd0be9450de7b8 (diff) | |
fix name changesv0.5.6
new gadgets
correct go mod
updated paths
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'net.go')
| -rw-r--r-- | net.go | 84 |
1 files changed, 45 insertions, 39 deletions
@@ -1,7 +1,7 @@ // This creates a simple hello world window package linuxstatus -import ( +import ( // "log" "net" "sort" @@ -15,7 +15,7 @@ func IsIPv6(address string) bool { } func (t *IPtype) IsReal() bool { - if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) { + if t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast() { log.Log(NET, "\t\tIP is Real = false") return false } else { @@ -25,7 +25,7 @@ func (t *IPtype) IsReal() bool { } func IsReal(ip *net.IP) bool { - if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { + if ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast() { log.Log(NET, "\t\tIP is Real = false") return false } else { @@ -36,22 +36,22 @@ func IsReal(ip *net.IP) bool { func renameInterface(i *net.Interface) { /* - /sbin/ip link set eth1 down - /sbin/ip link set eth1 name eth123 - /sbin/ip link set eth123 up + /sbin/ip link set eth1 down + /sbin/ip link set eth1 name eth123 + /sbin/ip link set eth123 up */ } // Will figure out if an interface was just added func checkInterface(i net.Interface) { val, ok := me.ifmap[i.Index] - if ! ok { + if !ok { log.Log(INFO, i.Name, "is a new network interface. The linux kernel index =", i.Index) me.ifmap[i.Index] = new(IFtype) me.ifmap[i.Index].gone = false me.ifmap[i.Index].iface = &i me.changed = true - if (me.Interfaces != nil) { + if me.Interfaces != nil { me.Interfaces.AddText(i.Name) me.Interfaces.SetText(i.Name) } @@ -59,11 +59,11 @@ func checkInterface(i net.Interface) { } me.ifmap[i.Index].gone = false log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name) - if (val.iface.Name != i.Name) { + if val.iface.Name != i.Name { log.Log(INFO, val.iface.Name, "has changed to it's name to", i.Name) me.ifmap[i.Index].iface = &i me.changed = true - if (me.Interfaces != nil) { + if me.Interfaces != nil { me.Interfaces.AddText(i.Name) me.Interfaces.SetText(i.Name) } @@ -72,15 +72,15 @@ func checkInterface(i net.Interface) { } /* - These are the real IP address you have been - given from DHCP +These are the real IP address you have been +given from DHCP */ func realAAAA() []string { var aaaa []string for s, t := range me.ipmap { - if (t.IsReal()) { - if (t.ipv6) { + if t.IsReal() { + if t.ipv6 { aaaa = append(aaaa, s) } } @@ -92,8 +92,8 @@ func realA() []string { var a []string for s, t := range me.ipmap { - if (t.IsReal()) { - if (t.ipv4) { + if t.IsReal() { + if t.ipv4 { a = append(a, s) } } @@ -111,12 +111,12 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) { for s, t := range me.ipmap { i := t.iface ipt := "IPv4" - if (t.ipv6) { + if t.ipv6 { ipt = "IPv6" } - if (t.IsReal()) { + if t.IsReal() { log.Log(INFO, "\tIP is Real ", ipt, i.Index, i.Name, s) - if (t.ipv6) { + if t.ipv6 { ipv6s[s] = t } else { ipv4s[s] = t @@ -149,21 +149,21 @@ func checkIP(ip *net.IPNet, i net.Interface) bool { me.ipmap[realip].ip = ip.IP me.ipmap[realip].iface = &i t := "IPv4" - if (IsIPv6(ip.String())) { + if IsIPv6(ip.String()) { me.ipmap[realip].ipv6 = true me.ipmap[realip].ipv4 = false t = "IPv6" - if (me.IPv6 != nil) { - me.IPv6.Set(realip) + if me.IPv6 != nil { + me.IPv6.SetValue(realip) } } else { me.ipmap[realip].ipv6 = false me.ipmap[realip].ipv4 = true - if (me.IPv4 != nil) { - me.IPv4.Set(realip) + if me.IPv4 != nil { + me.IPv4.SetValue(realip) } } - if (IsReal(&ip.IP)) { + if IsReal(&ip.IP) { log.Log(INFO, "\tIP is Real ", t, i.Index, i.Name, realip) } else { log.Log(INFO, "\tIP is not Real", t, i.Index, i.Name, realip) @@ -215,10 +215,10 @@ func updateRealAAAA() { var all4 []string var all6 []string for s, t := range me.ipmap { - if (t.ipv4) { + if t.ipv4 { all4 = append(all4, s) log.Log(NET, "IPv4 =", s) - } else if (t.ipv6) { + } else if t.ipv6 { all6 = append(all6, s) log.Log(NET, "IPv6 =", s) } else { @@ -232,14 +232,14 @@ func updateRealAAAA() { s4 := strings.Join(all4, "\n") s6 := strings.Join(all6, "\n") - if (me.IPv4.Get() != s4) { + if me.IPv4.String() != s4 { log.Log(CHANGE, "IPv4 addresses have changed", s4) - me.IPv4.Set(s4) + me.IPv4.SetValue(s4) me.changed = true } - if (me.IPv6.Get() != s6) { + if me.IPv6.String() != s6 { log.Log(CHANGE, "IPv6 addresses have changed", s6) - me.IPv6.Set(s6) + me.IPv6.SetValue(s6) me.changed = true } } @@ -248,7 +248,7 @@ func updateRealAAAA() { func deleteChanges() bool { var changed bool = false for i, t := range me.ifmap { - if (t.gone) { + if t.gone { log.Log(CHANGE, "DELETE int =", i, "name =", t.name, t.iface) delete(me.ifmap, i) changed = true @@ -256,7 +256,7 @@ func deleteChanges() bool { t.gone = true } for s, t := range me.ipmap { - if (t.gone) { + if t.gone { log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4) log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6) log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface) @@ -271,19 +271,25 @@ func deleteChanges() bool { } func (ls *LinuxStatus) GetIPv6() []string { - if ! me.Ready() {return nil} - tmp := me.workingIPv6.Get() + if !me.Ready() { + return nil + } + tmp := me.workingIPv6.String() return strings.Split(tmp, "\n") } func (ls *LinuxStatus) GetIPv4() []string { - if ! me.Ready() {return nil} - tmp := me.workingIPv4.Get() + if !me.Ready() { + return nil + } + tmp := me.workingIPv4.String() return strings.Split(tmp, "\n") } func (ls *LinuxStatus) GetNameservers() []string { - if ! me.Ready() {return nil} - tmp := me.resolver.Get() + if !me.Ready() { + return nil + } + tmp := me.resolver.String() return strings.Split(tmp, "\n") } |
