取得MTU (最大传输单元)

http://www.geekpage.jp/programming/linux-network/book/04/4-21.php

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

int
main()
{
  int fd;
  struct ifreq ifr;

  fd = socket(AF_INET, SOCK_DGRAM, 0);

  strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);
  if (ioctl(fd, SIOCGIFMTU, &ifr) != 0) {
    perror("ioctl");
    return 1;
  }

  close(fd);

  /* 結果を表示 */
  printf("%d\n", ifr.ifr_mtu);

  return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/mingzhanghui/p/9341473.html
MTU