mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/ctrld: use network service on darwin
This commit is contained in:
committed by
Cuong Manh Le
parent
05cfb9b661
commit
47c280cf1d
@@ -613,5 +613,8 @@ func netIfaceFromName(ifaceName string) (*net.Interface, error) {
|
||||
if iface == nil {
|
||||
return nil, errors.New("interface not found")
|
||||
}
|
||||
if err := patchNetIfaceName(iface); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iface, err
|
||||
}
|
||||
|
||||
34
cmd/ctrld/net_darwin.go
Normal file
34
cmd/ctrld/net_darwin.go
Normal file
@@ -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
|
||||
}
|
||||
7
cmd/ctrld/net_others.go
Normal file
7
cmd/ctrld/net_others.go
Normal file
@@ -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