Set MTU to C programmatically

The client requested that the MTU limit be 1492.

Is there a way to do this in the source code (C program)?

Is there any other way to do this at all? (Ifconfig?)

Why does anyone need to modify MTU to a certain limit? What is the use? And most importantly: by changing the MTU, is there a risk of breaking the code?

+3
source share
4 answers

It is not about speed directly; By increasing the MTU, you reduce overhead, which is data that is responsible for the correct delivery of the packet, but cannot be used by the end user; This can lead to an increase in speed, but only for heavy traffic;

, MTU, ( ), resent, .. , ;

, , -, ; ifconfig Windows.

+2

C:

int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
struct ifreq ifr;
strcpy(ifr.ifr_name, "eth0");
if(!ioctl(sock, SIOCGIFMTU, &ifr)) {
  ifr.ifr_mtu // Contains current mtu value
}
ifr.ifr_mtu = ... // Change value if it needed
if(!ioctl(sock, SIOCSIFMTU, &ifr)) {
  // Mtu changed successfully
}

Ubuntu, man netdevice.

+3

MTU - , . , . , n / m, m , m*n .

, , MTU - (, ethernet 802.3). , .

ifconfig mtu, : ifconfig eth0 mtu 1492.

+2

- sysfs

sudo sh -c 'echo 1492 > /sys/class/net/tun/mtu'

C,

0

All Articles