All of lore.kernel.org
 help / color / mirror / Atom feed
* [libsocketcan] Add can_get_link_stats() - v2
@ 2012-03-06 19:04 Reuben Dowle
  2012-03-07  9:44 ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Reuben Dowle @ 2012-03-06 19:04 UTC (permalink / raw)
  To: linux-can@vger.kernel.org; +Cc: Marc Kleine-Budde

Add can_get_link_stats()

This function gets link_stats64 information for the can interface.
This structure can be for any interface (not just can), but it
seems logical to keep functions for getting any statistics relevant
to CAN in this library.

Signed-off-by: Reuben Dowle <reuben.dowle@navico.com>

diff --git a/include/libsocketcan.h b/include/libsocketcan.h
index dc52053..06b37d6 100644
--- a/include/libsocketcan.h
+++ b/include/libsocketcan.h
@@ -50,6 +50,7 @@ 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_berr_counter(const char *name, struct can_berr_counter *bc);
 int can_get_device_stats(const char *name, struct can_device_stats *cds);
+int can_get_link_stats(const char *name, struct rtnl_link_stats64 *ls);
 
 #ifdef __cplusplus
 }
diff --git a/src/libsocketcan.c b/src/libsocketcan.c
index 26da338..e460912 100644
--- a/src/libsocketcan.c
+++ b/src/libsocketcan.c
@@ -54,6 +54,7 @@
 #define GET_BITTIMING_CONST 6
 #define GET_BERR_COUNTER 7
 #define GET_XSTATS 8
+#define GET_LINK_STATS64 9
 
 struct get_req {
 	struct nlmsghdr n;
@@ -380,6 +381,18 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
 		    ((char *)RTA_DATA(tb[IFLA_IFNAME]), name,
 		     sizeof(name)) != 0)
 			continue;
+		
+		if (acquire == GET_LINK_STATS64) {
+			if (!tb[IFLA_STATS64]) {
+				fprintf(stderr, "no link_stats64 data found\n");
+			} else {
+				memcpy(res,
+				       RTA_DATA(tb[IFLA_STATS64]),
+				       sizeof(struct rtnl_link_stats64));
+				ret = 0;
+			}
+			continue;
+		}
 
 		if (tb[IFLA_LINKINFO])
 			parse_rtattr_nested(linkinfo,
@@ -1154,3 +1167,24 @@ int can_get_device_stats(const char *name, struct can_device_stats *cds)
 {
 	return get_link(name, GET_XSTATS, cds);
 }
+
+/**
+ * @ingroup extern
+ * can_get_link_stats - get the rtnl_link_stats64.
+ *
+ * @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 rtnl_link_stats64.
+ *
+ * Please see struct rtnl_link_stats64 for more information.
+ *
+ * @return 0 if success
+ * @return -1 if failed
+ */
+int can_get_link_stats(const char *name, struct rtnl_link_stats64 *ls)
+{
+	return get_link(name, GET_LINK_STATS64, ls);
+}




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-08  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-06 19:04 [libsocketcan] Add can_get_link_stats() - v2 Reuben Dowle
2012-03-07  9:44 ` Marc Kleine-Budde
2012-03-07 23:45   ` Reuben Dowle
2012-03-08  8:49     ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.