pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/netutil/netutil_linux.go (about) 1 package netutil 2 3 // ////////////////////////////////////////////////////////////////////////////////// // 4 // // 5 // Copyright (c) 2022 ESSENTIAL KAOS // 6 // Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // 7 // // 8 // ////////////////////////////////////////////////////////////////////////////////// // 9 10 import ( 11 "bufio" 12 "os" 13 14 "pkg.re/essentialkaos/ek.v12/strutil" 15 ) 16 17 // ////////////////////////////////////////////////////////////////////////////////// // 18 19 // Path to file with routes info in procfs 20 var procRouteFile = "/proc/net/route" 21 22 // ////////////////////////////////////////////////////////////////////////////////// // 23 24 func getDefaultRouteInterface() string { 25 fd, err := os.OpenFile(procRouteFile, os.O_RDONLY, 0) 26 27 if err != nil { 28 return "" 29 } 30 31 defer fd.Close() 32 33 r := bufio.NewReader(fd) 34 s := bufio.NewScanner(r) 35 36 var header bool 37 38 for s.Scan() { 39 if !header { 40 header = true 41 continue 42 } 43 44 if strutil.ReadField(s.Text(), 1, true) == "00000000" { 45 return strutil.ReadField(s.Text(), 0, true) 46 } 47 } 48 49 return "" 50 }