Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
pull/106/head^2
Luotao Fu 2009-11-23 09:06:52 +01:00
parent 0e3319df98
commit 8c25d8d4b0
1 changed files with 24 additions and 22 deletions

View File

@ -91,8 +91,8 @@ static int addattr32(struct nlmsghdr *n, size_t maxlen, int type, __u32 data)
return 0; return 0;
} }
static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, const void *data, static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type,
int alen) const void *data, int alen)
{ {
int len = RTA_LENGTH(alen); int len = RTA_LENGTH(alen);
struct rtattr *rta; struct rtattr *rta;
@ -151,8 +151,7 @@ static int send_mod_request(int fd, struct nlmsghdr *n)
while (1) { while (1) {
iov.iov_len = sizeof(buf); iov.iov_len = sizeof(buf);
status = recvmsg(fd, &msg, 0); status = recvmsg(fd, &msg, 0);
for (h = (struct nlmsghdr *)buf; for (h = (struct nlmsghdr *)buf; (size_t) status >= sizeof(*h);) {
(size_t)status >= sizeof(*h);) {
int len = h->nlmsg_len; int len = h->nlmsg_len;
int l = len - sizeof(*h); int l = len - sizeof(*h);
if (l < 0 || len > status) { if (l < 0 || len > status) {
@ -294,7 +293,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
} }
for (nl_msg = (struct nlmsghdr *)nlbuf; for (nl_msg = (struct nlmsghdr *)nlbuf;
NLMSG_OK(nl_msg, u_msglen); nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { NLMSG_OK(nl_msg, u_msglen);
nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) {
int type = nl_msg->nlmsg_type; int type = nl_msg->nlmsg_type;
int len; int len;
if (type != RTM_NEWLINK) if (type != RTM_NEWLINK)
@ -327,9 +327,9 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
switch (acquire) { switch (acquire) {
case GET_STATE: case GET_STATE:
if (can_attr[IFLA_CAN_STATE]) { if (can_attr[IFLA_CAN_STATE]) {
*((int *)res) = *((int *)res) = *((__u32 *)
*((__u32 *) RTA_DATA(can_attr
RTA_DATA(can_attr[IFLA_CAN_STATE])); [IFLA_CAN_STATE]));
ret = 0; ret = 0;
} else { } else {
fprintf(stderr, "no state data found\n"); fprintf(stderr, "no state data found\n");
@ -338,9 +338,9 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
break; break;
case GET_RESTART_MS: case GET_RESTART_MS:
if (can_attr[IFLA_CAN_RESTART_MS]) { if (can_attr[IFLA_CAN_RESTART_MS]) {
*((__u32 *) res) = *((__u32 *) res) = *((__u32 *)
*((__u32 *) RTA_DATA(can_attr
RTA_DATA(can_attr[IFLA_CAN_RESTART_MS])); [IFLA_CAN_RESTART_MS]));
ret = 0; ret = 0;
} else } else
fprintf(stderr, "no restart_ms data found\n"); fprintf(stderr, "no restart_ms data found\n");
@ -348,7 +348,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
break; break;
case GET_BITTIMING: case GET_BITTIMING:
if (can_attr[IFLA_CAN_BITTIMING]) { if (can_attr[IFLA_CAN_BITTIMING]) {
memcpy(res, RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), memcpy(res,
RTA_DATA(can_attr[IFLA_CAN_BITTIMING]),
sizeof(struct can_bittiming)); sizeof(struct can_bittiming));
ret = 0; ret = 0;
} else } else
@ -362,7 +363,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
return ret; return ret;
} }
static int do_set_nl_link(int fd, __u8 if_state, const char* name, struct req_info *req_info) static int do_set_nl_link(int fd, __u8 if_state, const char *name,
struct req_info *req_info)
{ {
struct set_req req; struct set_req req;
@ -428,7 +430,8 @@ static int do_set_nl_link(int fd, __u8 if_state, const char* name, struct req_in
memset(&cm, 0, sizeof(cm)); memset(&cm, 0, sizeof(cm));
cm.mask = req_info->ctrlmode; cm.mask = req_info->ctrlmode;
cm.flags = req_info->flags; cm.flags = req_info->flags;
addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm,
sizeof(cm));
} }
/* mark end of data section */ /* mark end of data section */
@ -499,8 +502,7 @@ int set_restart(const char *name)
if (state != CAN_STATE_BUS_OFF) { if (state != CAN_STATE_BUS_OFF) {
fprintf(stderr, fprintf(stderr,
"Device %s is not in BUS_OFF," "Device %s is not in BUS_OFF,"
" no use to restart it\n", " no use to restart it\n", name);
name);
err = 0; err = 0;
goto err_out; goto err_out;
} }