30
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NICのリンク速度を調べる

Posted at

ちょっと気になって調べたメモ

普通に思いつくのはethtool

# ethtool ens3
        Speed: 1000Mb/s

はい、特に問題ありません。簡単ですね。
※sakuraVPSの仮想なのでens3になってます。

ethtoolが使えなかったら・・・?

# dmesg | grep "Link is Up"
[    8.724177] e1000: ens3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

dmesgから読めばいいですね。

ethtoolは何を読んでるの?

$ rpm -qf `which ethtool`
ethtool-3.8-4.el7_0.x86_64
$ wget http://vault.centos.org/7.0.1406/os/Source/SPackages/ethtool-3.8-3.el7.src.rpm
$ rpm2cpio ../ethtool-3.8-3.el7.src.rpm | cpio -idv
$ tar xvf ethtool-3.8.tar.xz
$ cd ethtool-3.8
$ view ethtool.c
ethtool.c
static int dump_ecmd(struct ethtool_cmd *ep)

        fprintf(stdout, "       Speed: ");
        speed = ethtool_cmd_speed(ep);
        if (speed == 0 || speed == (u16)(-1) || speed == (u32)(-1))
                fprintf(stdout, "Unknown!\n");
        else
                fprintf(stdout, "%uMb/s\n", speed);

表示から探すとこの辺ですね

ethtool-copy.h
static __inline__ __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
{
        return (ep->speed_hi << 16) | ep->speed;
}

変換してるだけ。

ethtool.c
static int do_gset(struct cmd_context *ctx)
{

        err = send_ioctl(ctx, &ecmd);
        if (err == 0) {
                err = dump_ecmd(&ecmd);


int send_ioctl(struct cmd_context *ctx, void *cmd)
{
        ctx->ifr.ifr_data = cmd;
        return ioctl(ctx->fd, SIOCETHTOOL, &ctx->ifr);
}

ここですね。ioctlで取得してるのですね。

30
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?