Linux – Getting interface MTU under Linux with PCAP

linuxmtupcap

I am interested in storing packets I sniff using PCAP.

As I preallocate the memory I need – i.e. a multiple of the MTU of the interface I am sniffing from, I would like to discover how much memory I need before opening the live session.

Is it possible to query PCAP for getting the MTU of the sniffed interface ?

How can I get this information otherwise (possibly using system libraries) ?

Thanks

Best Answer

One option on linux would be the sysfs file mtu in /sys/class/net/devicename

$ cat /sys/class/net/eth0/mtu /sys/class/net/lo/mtu
1500
16436