Date: Tue, 9 Feb 2016 22:51:27 +0000 (UTC) From: Pallav Bose <pallav_bose@yahoo.com> To: "freebsd-net@freebsd.org" <freebsd-net@freebsd.org> Subject: C program API to determine negotiated link speed of a network interface? Message-ID: <249322925.1631277.1455058288002.JavaMail.yahoo@mail.yahoo.com> References: <249322925.1631277.1455058288002.JavaMail.yahoo.ref@mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, I'm writing a C program to list all available interfaces and their link speed. I can use getifaddrs(3) to obtain a list of network interfaces in a struct ifaddrs, but none of the fields in this struct gives me information about the negotiated link speed. From the man page of getifaddrs(3): The ifaddrs structure contains at least the following entries: struct ifaddrs *ifa_next; /* Pointer to next struct */ char *ifa_name; /* Interface name */ u_int ifa_flags; /* Interface flags */ struct sockaddr *ifa_addr; /* Interface address */ struct sockaddr *ifa_netmask; /* Interface netmask */ struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ struct sockaddr *ifa_dstaddr; /* P2P interface destination */ void *ifa_data; /* Address specific data */ Running truss on ifconfig(8) tells me that the ioctl SIOCGIFMEDIA can be used, but it is not clear to me how. Is there an API in C which does this already? # truss ifconfig em0....<snipped>.... ioctl(3,SIOCGIFMAC,0xffffe210) ERR#22 'Invalid argument' ioctl(3,SIOCGIFMEDIA,0xffffe1f0) = 0 (0x0) ioctl(3,SIOCGIFMEDIA,0xffffe1f0) = 0 (0x0) media: Ethernet autoselect (1000baseT <full-duplex>) write(1,"\tmedia: Ethernet autoselect (10"...,54) = 54 (0x36) status: active write(1,"\tstatus: active\n",16) = 16 (0x10) Thanks,Pallav
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?249322925.1631277.1455058288002.JavaMail.yahoo>
