On 10/13/2011 01:02 PM, Kurt Van Dijck wrote:
> On Thu, Oct 13, 2011 at 11:24:59AM +0200, Marc Kleine-Budde wrote:
>> On 10/12/2011 02:55 PM, Kurt Van Dijck wrote:
>>> Not sure where exactly to put this.
>>>
>>> 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.di...@eia.be>
>>> ---
>>> diff --git a/include/libsocketcan.h b/include/libsocketcan.h
>>> index 10c012c..6098d6a 100644
>>> --- a/include/libsocketcan.h
>>> +++ b/include/libsocketcan.h
>>> @@ -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_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);
>>>  
>>>  #endif
>>> diff --git a/src/libsocketcan.c b/src/libsocketcan.c
>>> index 2ac3f2a..34d3875 100644
>>> --- a/src/libsocketcan.c
>>> +++ b/src/libsocketcan.c
>>> @@ -53,6 +53,7 @@
>>>  #define GET_CLOCK 5
>>>  #define GET_BITTIMING_CONST 6
>>>  #define GET_BERR_COUNTER 7
>>> +#define GET_XSTATS 8
>>>  
>>>  struct get_req {
>>>     struct nlmsghdr n;
>>> @@ -386,6 +387,17 @@ static int do_get_nl_link(int fd, __u8 acquire, const 
>>> char *name, void *res)
>>>             else
>>>                     continue;
>>>  
>>> +           if (acquire == GET_XSTATS) {
>>> +                   if (!linkinfo[IFLA_INFO_XSTATS])
>>> +                           fprintf(stderr, "no can statistics found\n");

what about "return -1;" here?

>>> +                   else {
>>> +                           memcpy(res, 
>>> RTA_DATA(linkinfo[IFLA_INFO_XSTATS]),
>>> +                                           sizeof(struct 
>>> can_device_stats));
>>> +                           ret = 0;
>>> +                   }
>>> +                   continue;
>>> +           }
>>
>> is it possible to put GET_XSTATS to the bit switch statement below?
> That would cross the check on linkinfo[IFLA_INFO_DATA], which is
> irrelevant for GET_XSTATS, since you need linkinfo[IFLA_INFO_XSTATS] ...

I see, IMHO it doesn't make the code better if we squeeze the GET_XSTATS
into the swich/case.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Socketcan-core mailing list
Socketcan-core@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to