8 #include <sys/socket.h>
9 #include <netinet/in.h>
11 #include <sys/ioctl.h>
13 int main(int argc, char *argv[])
18 fprintf(stderr, "usage: %s IFACE\n", argv[0]);
21 if (strlen(argv[1]) >= sizeof(ifr.ifr_name)) {
22 fprintf(stderr, "%s: interface name `%s' too long\n", argv[0], argv[1]);
25 if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
26 fprintf(stderr, "%s: socket: %s\n", argv[0], strerror(errno));
29 strcpy(ifr.ifr_name, argv[1]);
30 if (ioctl(fd, SIOCGIFMTU, &ifr)) {
31 fprintf(stderr, "%s: ioctl(SIOCGIFMTU): %s\n", argv[0], strerror(errno));
34 printf("%d\n", ifr.ifr_mtu);