Files
ctrld/internal/clientinfo/arp_windows.go
Cuong Manh Le d88c860cac Add explanatory comments for variable overwrites and code flow decisions
This commit adds detailed explanatory comments throughout the codebase to explain
WHY certain logic is needed, not just WHAT the code does. This improves code
maintainability and helps developers understand the reasoning behind complex
decisions.

Key improvements:
- Version string processing: Explain why "v" prefix is added for semantic versioning
- Control-D configuration: Explain why config is reset to prevent mixing of settings
- DNS server categorization: Explain LAN vs public server handling for performance
- Listener configuration: Document complex fallback logic for port/IP selection
- MAC address normalization: Explain cross-platform compatibility needs
- IPv6 address processing: Document Unix-specific interface suffix handling
- Log content truncation: Explain why large content is limited to prevent flooding
- IP address categorization: Document RFC1918 prioritization logic
- IPv4/IPv6 separation: Explain network stack compatibility needs
- DNS priority logic: Document different priority levels for different scenarios
- Domain controller processing: Explain Windows API prefix handling
- Reverse mapping creation: Document API encoding/decoding needs
- Default value fallbacks: Explain why defaults prevent system failures
- IP stack configuration: Document different defaults for different upstream types

These comments help future developers understand the reasoning behind complex
business logic, making the codebase more maintainable and reducing the risk of
incorrect modifications during maintenance.
2025-10-09 17:49:21 +07:00

43 lines
919 B
Go

package clientinfo
import (
"os/exec"
"strings"
)
func (a *arpDiscover) scan() {
data, err := exec.Command("arp", "-a").Output()
if err != nil {
return
}
header := false
for _, line := range strings.Split(string(data), "\n") {
if len(line) == 0 {
continue // empty lines
}
if line[0] != ' ' {
// Mark that we've found an interface header line
// Windows "arp -a" output has interface headers followed by ARP entries
header = true // "Interface:" lines, next is header line.
continue
}
if header {
// Skip the header line that follows interface names
// These lines contain column headers like "Internet Address" and "Physical Address"
header = false // header lines
continue
}
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
ip := fields[0]
mac := strings.ReplaceAll(fields[1], "-", ":")
a.mac.Store(ip, mac)
a.ip.Store(mac, ip)
}
}