MCPcopy Create free account
hub / github.com/encodeous/nylon / getIFIndex

Function getIFIndex

polyamide/tun/tun_linux.go:203–229  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

201}
202
203func getIFIndex(name string) (int32, error) {
204 fd, err := unix.Socket(
205 unix.AF_INET,
206 unix.SOCK_DGRAM|unix.SOCK_CLOEXEC,
207 0,
208 )
209 if err != nil {
210 return 0, err
211 }
212
213 defer unix.Close(fd)
214
215 var ifr [ifReqSize]byte
216 copy(ifr[:], name)
217 _, _, errno := unix.Syscall(
218 unix.SYS_IOCTL,
219 uintptr(fd),
220 uintptr(unix.SIOCGIFINDEX),
221 uintptr(unsafe.Pointer(&ifr[0])),
222 )
223
224 if errno != 0 {
225 return 0, errno
226 }
227
228 return *(*int32)(unsafe.Pointer(&ifr[unix.IFNAMSIZ])), nil
229}
230
231func (tun *NativeTun) setMTU(n int) error {
232 name, err := tun.Name()

Callers 1

CreateTUNFromFileFunction · 0.85

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected