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 spe= ed. I can use getifaddrs(3) to obtain a list of network interfaces in a str= uct ifaddrs, but none of the fields in this struct gives me information abo= ut the negotiated link speed. From the man page of getifaddrs(3): The ifaddrs structure contains at least the following entries: =C2=A0=C2=A0=C2=A0 =C2=A0struct=C2=A0=C2=A0=C2=A0 ifaddrs=C2=A0=C2=A0=C2=A0= *ifa_next;=C2=A0=C2=A0=C2=A0 =C2=A0 /* Pointer to next struct */ =C2=A0=C2=A0=C2=A0 =C2=A0char=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *ifa_name;=C2=A0=C2=A0=C2=A0 = =C2=A0 /* Interface name */ =C2=A0=C2=A0=C2=A0 =C2=A0u_int=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ifa_flags;=C2=A0=C2=A0=C2=A0 = =C2=A0 /* Interface flags=C2=A0=C2=A0=C2=A0 */ =C2=A0=C2=A0=C2=A0 =C2=A0struct=C2=A0=C2=A0=C2=A0 sockaddr=C2=A0 *ifa_addr;= =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 /* Interface address */ =C2=A0=C2=A0=C2=A0 =C2=A0struct=C2=A0=C2=A0=C2=A0 sockaddr=C2=A0 *ifa_netma= sk;=C2=A0=C2=A0=C2=A0 /* Interface netmask */ =C2=A0=C2=A0=C2=A0 =C2=A0struct=C2=A0=C2=A0=C2=A0 sockaddr=C2=A0 *ifa_broad= addr;=C2=A0 /* Interface broadcast address */ =C2=A0=C2=A0=C2=A0 =C2=A0struct=C2=A0=C2=A0=C2=A0 sockaddr=C2=A0 *ifa_dstad= dr;=C2=A0=C2=A0=C2=A0 /* P2P interface destination */ =C2=A0=C2=A0=C2=A0 =C2=A0void=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *ifa_data;=C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0 /* Address specific data */ Running truss on ifconfig(8) tells me that the ioctl SIOCGIFMEDIA can be us= ed, but it is not clear to me how. Is there an API in C which does this alr= eady? # truss ifconfig em0....<snipped>.... ioctl(3,SIOCGIFMAC,0xffffe210)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ERR#22 'Inv= alid argument' ioctl(3,SIOCGIFMEDIA,0xffffe1f0)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D 0 (0x0) ioctl(3,SIOCGIFMEDIA,0xffffe1f0)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D 0 (0x0) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 media: Ethernet autoselect (1000= baseT <full-duplex>) write(1,"\tmedia: Ethernet autoselect (10"...,54) =3D 54 (0x36) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 status: active write(1,"\tstatus: active\n",16)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D 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>