add can_get_device_stats()
When using libsocketcan on git://git.pengutronix.de/git/tools/libsocketcan.git, I kind of missed a method to fetch the can device statistics. This patch adds that functionality. I think this is the proper library to put such function. Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>pull/106/head^2
parent
42a3b65198
commit
6db5d772b4
|
|
@ -45,5 +45,6 @@ int can_get_state(const char *name, int *state);
|
||||||
int can_get_clock(const char *name, struct can_clock *clock);
|
int can_get_clock(const char *name, struct can_clock *clock);
|
||||||
int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc);
|
int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc);
|
||||||
int can_get_berr_counter(const char *name, struct can_berr_counter *bc);
|
int can_get_berr_counter(const char *name, struct can_berr_counter *bc);
|
||||||
|
int can_get_device_stats(const char *name, struct can_device_stats *cds);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
#define GET_CLOCK 5
|
#define GET_CLOCK 5
|
||||||
#define GET_BITTIMING_CONST 6
|
#define GET_BITTIMING_CONST 6
|
||||||
#define GET_BERR_COUNTER 7
|
#define GET_BERR_COUNTER 7
|
||||||
|
#define GET_XSTATS 8
|
||||||
|
|
||||||
struct get_req {
|
struct get_req {
|
||||||
struct nlmsghdr n;
|
struct nlmsghdr n;
|
||||||
|
|
@ -386,6 +387,17 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (acquire == GET_XSTATS) {
|
||||||
|
if (!linkinfo[IFLA_INFO_XSTATS])
|
||||||
|
fprintf(stderr, "no can statistics found\n");
|
||||||
|
else {
|
||||||
|
memcpy(res, RTA_DATA(linkinfo[IFLA_INFO_XSTATS]),
|
||||||
|
sizeof(struct can_device_stats));
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!linkinfo[IFLA_INFO_DATA]) {
|
if (!linkinfo[IFLA_INFO_DATA]) {
|
||||||
fprintf(stderr, "no link data found\n");
|
fprintf(stderr, "no link data found\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -1121,3 +1133,24 @@ int can_get_berr_counter(const char *name, struct can_berr_counter *bc)
|
||||||
{
|
{
|
||||||
return get_link(name, GET_BERR_COUNTER, bc);
|
return get_link(name, GET_BERR_COUNTER, bc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup extern
|
||||||
|
* can_get_device_stats - get the can_device_stats.
|
||||||
|
*
|
||||||
|
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
|
||||||
|
* in your system. usually it contains prefix "can" and the numer of the can
|
||||||
|
* line. e.g. "can0"
|
||||||
|
* @param bc pointer to the error counter struct..
|
||||||
|
*
|
||||||
|
* This one gets the current can_device_stats.
|
||||||
|
*
|
||||||
|
* Please see struct can_device_stats for more information.
|
||||||
|
*
|
||||||
|
* @return 0 if success
|
||||||
|
* @return -1 if failed
|
||||||
|
*/
|
||||||
|
int can_get_device_stats(const char *name, struct can_device_stats *cds)
|
||||||
|
{
|
||||||
|
return get_link(name, GET_XSTATS, cds);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue