>Date: Tue, 9 Feb 2016 22:51:27 +0000 (UTC)
>From: Pallav Bose <pallav_b...@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.ya...@mail.yahoo.com>
>Content-Type: text/plain; charset=UTF-8
>
>Hi,
>I'm writing a C program to list all available interfaces and their link speed. 
>...
>
>...
>
>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?
>
>...
>
>Thanks,Pallav

Hi Pallav,

Take a look at sbin/ifconfig/ifmedia.c::media_status(). Basically, you call 
ioctl(SIOCGIFMEDIA) once to get the number of media types for the NIC, allocate 
local memory to hold the list, then call ioctl(SIOCGIFMEDIA) again to copy the 
list into that local buffer. Then print_media_word() parses it and emits 
(amongst other things) the speed.

Alas, print_media_word () and several of the helper functions it calls are (a) 
not part of a library, so you have to re-implement them yourself in your own 
sources and (b) are copy/pasted between ifconfig and etherswitch. That screams 
for refactoring, and if/when that happens, it should have a public interface.

Hope that helps,

Ravi (rpokala@)

_______________________________________________
freebsd-net@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

Reply via email to