Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (9.5k points)

 I have a program that makes a system() call to ifconfig to show all the network configurations of the currently connected network devices. And I want to check for the iproute2 when it fails. 

 

Can anyone tell me how to programmatically implement it using C? 

1 Answer

0 votes
by (19.7k points)

Try to set the SIOCSIFMTU field in an ioctl call. Check the code implementation below: 

struct ifreq ifr; 

ifr.ifr_addr.sa_family = AF_INET;

strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));

ifr.ifr_mtu = 9100; //your MTU size here

if (ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr) < 0)

This code will set the MTU using the ifr_mtu field in the ifreq structure. For more details, refer here 

Interested in Linux? Check out this Linux Certification by Intellipaat.  

Browse Categories

...