mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
cmd/ctrld: use network service on darwin
This commit is contained in:
@@ -613,5 +613,8 @@ func netIfaceFromName(ifaceName string) (*net.Interface, error) {
|
|||||||
if iface == nil {
|
if iface == nil {
|
||||||
return nil, errors.New("interface not found")
|
return nil, errors.New("interface not found")
|
||||||
}
|
}
|
||||||
|
if err := patchNetIfaceName(iface); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return iface, err
|
return iface, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"net"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func patchNetIfaceName(iface *net.Interface) error {
|
||||||
|
b, err := exec.Command("networksetup", "-listnetworkserviceorder").Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(bytes.NewReader(b))
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
if strings.Contains(line, "*") {
|
||||||
|
// Network services is disabled.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.Contains(line, "Device: "+iface.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts := strings.Split(line, ",")
|
||||||
|
if _, networkServiceName, ok := strings.Cut(parts[0], "(Hardware Port: "); ok {
|
||||||
|
mainLog.Debug().Str("network_service", networkServiceName).Msg("found network service name for interface")
|
||||||
|
iface.Name = networkServiceName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build !darwin
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
func patchNetIfaceName(iface *net.Interface) error { return nil }
|
||||||
Reference in New Issue
Block a user