libsocketcan  v0.0.10+git20140721
libsocketcan.c File Reference

library code More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <libsocketcan.h>
Include dependency graph for libsocketcan.c:

Macros

#define parse_rtattr_nested(tb, max, rta)   (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
 
#define NLMSG_TAIL(nmsg)   ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
 
#define IFLA_CAN_MAX   (__IFLA_CAN_MAX - 1)
 
#define IF_UP   1
 
#define IF_DOWN   2
 
#define GET_STATE   1
 
#define GET_RESTART_MS   2
 
#define GET_BITTIMING   3
 
#define GET_CTRLMODE   4
 
#define GET_CLOCK   5
 
#define GET_BITTIMING_CONST   6
 
#define GET_BERR_COUNTER   7
 
#define GET_XSTATS   8
 

Functions

static void parse_rtattr (struct rtattr **tb, int max, struct rtattr *rta, int len)
 
static int addattr32 (struct nlmsghdr *n, size_t maxlen, int type, __u32 data)
 
static int addattr_l (struct nlmsghdr *n, size_t maxlen, int type, const void *data, int alen)
 
static int send_mod_request (int fd, struct nlmsghdr *n)
 send_mod_request - send a linkinfo modification request More...
 
static int send_dump_request (int fd, int family, int type)
 send_dump_request - send a dump linkinfo request More...
 
static int open_nl_sock ()
 open_nl_sock - open a netlink socket More...
 
static int do_get_nl_link (int fd, __u8 acquire, const char *name, void *res)
 do_get_nl_link - get linkinfo More...
 
static int get_link (const char *name, __u8 acquire, void *res)
 get_link - get linkinfo More...
 
static int do_set_nl_link (int fd, __u8 if_state, const char *name, struct req_info *req_info)
 do_set_nl_link - setup linkinfo More...
 
static int set_link (const char *name, __u8 if_state, struct req_info *req_info)
 set_link - open a netlink socket and setup linkinfo More...
 
int can_do_start (const char *name)
 can_do_start - start the can interface More...
 
int can_do_stop (const char *name)
 can_do_stop - stop the can interface More...
 
int can_do_restart (const char *name)
 can_do_restart - restart the can interface More...
 
int can_set_restart_ms (const char *name, __u32 restart_ms)
 can_set_restart_ms - set interval of auto restart. More...
 
int can_set_ctrlmode (const char *name, struct can_ctrlmode *cm)
 can_set_ctrlmode - setup the control mode. More...
 
int can_set_bittiming (const char *name, struct can_bittiming *bt)
 can_set_bittiming - setup the bittiming. More...
 
int can_set_bitrate (const char *name, __u32 bitrate)
 can_set_bitrate - setup the bitrate. More...
 
int can_set_bitrate_samplepoint (const char *name, __u32 bitrate, __u32 sample_point)
 can_set_bitrate_samplepoint - setup the bitrate. More...
 
int can_get_state (const char *name, int *state)
 can_get_state - get the current state of the device More...
 
int can_get_restart_ms (const char *name, __u32 *restart_ms)
 can_get_restart_ms - get the current interval of auto restarting. More...
 
int can_get_bittiming (const char *name, struct can_bittiming *bt)
 can_get_bittiming - get the current bittimnig configuration. More...
 
int can_get_ctrlmode (const char *name, struct can_ctrlmode *cm)
 can_get_ctrlmode - get the current control mode. More...
 
int can_get_clock (const char *name, struct can_clock *clock)
 can_get_clock - get the current clock struct. More...
 
int can_get_bittiming_const (const char *name, struct can_bittiming_const *btc)
 can_get_bittiming_const - get the current bittimnig constant. More...
 
int can_get_berr_counter (const char *name, struct can_berr_counter *bc)
 can_get_berr_counter - get the tx/rx error counter. More...
 
int can_get_device_stats (const char *name, struct can_device_stats *cds)
 can_get_device_stats - get the can_device_stats. More...
 

Detailed Description

library code