refactor codebase and fix bugs

- merge dante.go and dante_control.go into single dante.go
- consolidate buildDantePacket and buildDantePacket28 into one function
- fix broken comparison logic in SetDanteClockMaster
- split ARP parsing into platform-specific files with build tags
- implement Linux ARP table parsing via /proc/net/arp
- run gofmt on all files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-23 23:21:51 -08:00
parent f4b2351de8
commit 7e8ec697ae
10 changed files with 888 additions and 877 deletions

66
arp.go
View File

@@ -1,12 +1,9 @@
package tendrils
import (
"bufio"
"context"
"log"
"net"
"os/exec"
"runtime"
"strings"
"time"
)
@@ -54,69 +51,6 @@ func (t *Tendrils) readARPTable() {
}
}
func (t *Tendrils) parseARPTable() []arpEntry {
if runtime.GOOS == "darwin" {
return t.parseARPDarwin()
}
return t.parseARPLinux()
}
func (t *Tendrils) parseARPDarwin() []arpEntry {
cmd := exec.Command("arp", "-an")
output, err := cmd.Output()
if err != nil {
return nil
}
var entries []arpEntry
scanner := bufio.NewScanner(strings.NewReader(string(output)))
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "permanent") {
continue
}
fields := strings.Fields(line)
if len(fields) < 6 {
continue
}
ipStr := strings.Trim(fields[1], "()")
ip := net.ParseIP(ipStr)
if ip == nil {
continue
}
macStr := fields[3]
if macStr == "(incomplete)" {
continue
}
macStr = normalizeMACAddress(macStr)
mac, err := net.ParseMAC(macStr)
if err != nil {
log.Printf("[arp] failed to parse MAC %q for IP %s: %v", macStr, ipStr, err)
continue
}
ifaceName := fields[5]
entries = append(entries, arpEntry{
ip: ip,
mac: mac,
iface: ifaceName,
})
}
return entries
}
func (t *Tendrils) parseARPLinux() []arpEntry {
var entries []arpEntry
return entries
}
func normalizeMACAddress(mac string) string {
parts := strings.Split(mac, ":")
for i, part := range parts {