File tree Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -269,21 +269,15 @@ func (tun *NativeTun) setMTU(n int) error {
269
269
270
270
defer unix .Close (fd )
271
271
272
- // do ioctl call
273
- var ifr [ifReqSize ]byte
274
- copy (ifr [:], name )
275
- * (* uint32 )(unsafe .Pointer (& ifr [unix .IFNAMSIZ ])) = uint32 (n )
276
- _ , _ , errno := unix .Syscall (
277
- unix .SYS_IOCTL ,
278
- uintptr (fd ),
279
- uintptr (unix .SIOCSIFMTU ),
280
- uintptr (unsafe .Pointer (& ifr [0 ])),
281
- )
282
-
283
- if errno != 0 {
284
- return fmt .Errorf ("failed to set MTU of TUN device: %w" , errno )
272
+ req , err := unix .NewIfreq (name )
273
+ if err != nil {
274
+ return fmt .Errorf ("unix.NewIfreq(%q): %w" , name , err )
275
+ }
276
+ req .SetUint32 (uint32 (n ))
277
+ err = unix .IoctlIfreq (fd , unix .SIOCSIFMTU , req )
278
+ if err != nil {
279
+ return fmt .Errorf ("failed to set MTU of TUN device %q: %w" , name , err )
285
280
}
286
-
287
281
return nil
288
282
}
289
283
You can’t perform that action at this time.
0 commit comments