From: 6!tgraf <6!tgraf> Date: Tue, 18 Jan 2005 13:58:49 +0000 (+0000) Subject: Use NLMSG_TAIL and add addraw_l X-Git-Url: https://rtime.felk.cvut.cz/gitweb/lisovros/iproute2_canprio.git/commitdiff_plain/07f9436201eba2f75e6c480f5b16316b3bf977fc Use NLMSG_TAIL and add addraw_l (Logical change 1.128) --- diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 45f293d..57fa0c8 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -477,7 +477,7 @@ int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) fprintf(stderr,"addattr32: Error! max allowed bound %d exceeded\n",maxlen); return -1; } - rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); + rta = NLMSG_TAIL(n); rta->rta_type = type; rta->rta_len = len; memcpy(RTA_DATA(rta), &data, 4); @@ -495,7 +495,7 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen); return -1; } - rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); + rta = NLMSG_TAIL(n); rta->rta_type = type; rta->rta_len = len; memcpy(RTA_DATA(rta), data, alen); @@ -503,6 +503,19 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, return 0; } +int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len) +{ + if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) { + fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen); + return -1; + } + + memcpy(NLMSG_TAIL(n), data, len); + memset((void *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len); + n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len); + return 0; +} + int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data) { int len = RTA_LENGTH(4);