]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Use NLMSG_TAIL and add addraw_l
author6!tgraf <6!tgraf>
Tue, 18 Jan 2005 13:58:49 +0000 (13:58 +0000)
committer6!tgraf <6!tgraf>
Tue, 18 Jan 2005 13:58:49 +0000 (13:58 +0000)
(Logical change 1.128)

lib/libnetlink.c

index 45f293db512bea3145c2a985c48365144c6ab458..57fa0c8097af8b1978fcf491275ad8f12a420ed0 100644 (file)
@@ -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);