@@ -27,6 +27,9 @@ type PlatformIO struct {
2727 // Socket protector from mobile platform (Android VpnService.protect).
2828 protectFn func (fd int32 ) bool
2929
30+ // noProtectorLogged suppresses repeated "no socket protector" warnings.
31+ noProtectorLogged bool
32+
3033 // Interface data from mobile platform (JSON string).
3134 interfacesJSON string
3235
@@ -85,6 +88,7 @@ func (p *PlatformIO) SetSocketProtector(fn func(fd int32) bool) {
8588 defer p .mu .Unlock ()
8689 slog .Debug ("[SetSocketProtector]" , "registered" , fn != nil )
8790 p .protectFn = fn
91+ p .noProtectorLogged = false
8892}
8993
9094// SetIncludeAllNetworks sets whether the VPN configuration uses includeAllNetworks (iOS).
@@ -150,8 +154,9 @@ func (p *PlatformIO) AutoDetectInterfaceControl(fd int32) error {
150154 if ! ok {
151155 return fmt .Errorf ("protect fd %d failed" , fd )
152156 }
153- } else {
154- slog .Warn ("AutoDetectInterfaceControl: no socket protector" , "fd" , fd )
157+ } else if ! p .noProtectorLogged {
158+ p .noProtectorLogged = true
159+ slog .Warn ("AutoDetectInterfaceControl: no socket protector registered, subsequent warnings suppressed" )
155160 }
156161 return nil
157162}
@@ -362,7 +367,7 @@ func detectDefaultInterface(ctx context.Context, listener libbox.InterfaceUpdate
362367 return
363368 }
364369 targets := []string {"8.8.8.8:53" , "1.1.1.1:53" }
365- for attempt := 0 ; attempt < 5 ; attempt ++ {
370+ for attempt := range 5 {
366371 select {
367372 case <- ctx .Done ():
368373 slog .Debug ("detect interface: cancelled" )
@@ -451,6 +456,16 @@ func parseInterfacesJSON(jsonStr string) (libbox.NetworkInterfaceIterator, error
451456 return & networkInterfaceIterator {items : result }, nil
452457}
453458
459+ // POSIX network interface flag bits (decimal values for cross-platform portability).
460+ const (
461+ iffUP int32 = 0x1
462+ iffBroadcast int32 = 0x2
463+ iffLoopback int32 = 0x8
464+ iffPointToPoint int32 = 0x10
465+ iffRunning int32 = 0x40
466+ iffMulticast int32 = 0x1000
467+ )
468+
454469func buildDesktopInterfaces (ifaces []net.Interface ) (libbox.NetworkInterfaceIterator , error ) {
455470 var result []* libbox.NetworkInterface
456471 for _ , iface := range ifaces {
@@ -469,22 +484,22 @@ func buildDesktopInterfaces(ifaces []net.Interface) (libbox.NetworkInterfaceIter
469484
470485 var flags int32
471486 if iface .Flags & net .FlagUp != 0 {
472- flags |= 0x1 // IFF_UP
487+ flags |= iffUP
473488 }
474489 if iface .Flags & net .FlagRunning != 0 {
475- flags |= 0x40 // IFF_RUNNING
490+ flags |= iffRunning
476491 }
477492 if iface .Flags & net .FlagBroadcast != 0 {
478- flags |= 0x2 // IFF_BROADCAST
493+ flags |= iffBroadcast
479494 }
480495 if iface .Flags & net .FlagLoopback != 0 {
481- flags |= 0x8 // IFF_LOOPBACK
496+ flags |= iffLoopback
482497 }
483498 if iface .Flags & net .FlagPointToPoint != 0 {
484- flags |= 0x10 // IFF_POINTOPOINT
499+ flags |= iffPointToPoint
485500 }
486501 if iface .Flags & net .FlagMulticast != 0 {
487- flags |= 0x1000 // IFF_MULTICAST
502+ flags |= iffMulticast
488503 }
489504
490505 result = append (result , & libbox.NetworkInterface {
0 commit comments