Lines 92-103
Link Here
|
92 |
*/ |
92 |
*/ |
93 |
struct rtattr *tb[CTRL_ATTR_MAX + 1]; |
93 |
struct rtattr *tb[CTRL_ATTR_MAX + 1]; |
94 |
/* pointer to the generic netlink header in the incoming message */ |
94 |
/* pointer to the generic netlink header in the incoming message */ |
95 |
struct genlmsghdr *ghdr = NLMSG_DATA(n); |
95 |
struct genlmsghdr ghdr; |
96 |
/* length of the attribute and payload */ |
96 |
/* length of the attribute and payload */ |
97 |
int len = n->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN); |
97 |
int len = n->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN); |
98 |
/* Pointer to the attribute portion of the message */ |
98 |
/* Pointer to the attribute portion of the message */ |
99 |
struct rtattr *attrs; |
99 |
struct rtattr *attrs; |
100 |
|
100 |
|
|
|
101 |
memcpy(&ghdr, NLMSG_DATA(n), sizeof(ghdr)); |
101 |
if (len < 0) { |
102 |
if (len < 0) { |
102 |
fprintf(stderr, "%s: netlink CTRL_CMD_GETFAMILY response, " |
103 |
fprintf(stderr, "%s: netlink CTRL_CMD_GETFAMILY response, " |
103 |
"wrong controller message len: %d\n", progname, len); |
104 |
"wrong controller message len: %d\n", progname, len); |
Lines 111-128
Link Here
|
111 |
return 0; |
112 |
return 0; |
112 |
} |
113 |
} |
113 |
|
114 |
|
114 |
if (ghdr->cmd != CTRL_CMD_GETFAMILY && |
115 |
if (ghdr.cmd != CTRL_CMD_GETFAMILY && |
115 |
ghdr->cmd != CTRL_CMD_DELFAMILY && |
116 |
ghdr.cmd != CTRL_CMD_DELFAMILY && |
116 |
ghdr->cmd != CTRL_CMD_NEWFAMILY && |
117 |
ghdr.cmd != CTRL_CMD_NEWFAMILY && |
117 |
ghdr->cmd != CTRL_CMD_NEWMCAST_GRP && |
118 |
ghdr.cmd != CTRL_CMD_NEWMCAST_GRP && |
118 |
ghdr->cmd != CTRL_CMD_DELMCAST_GRP) { |
119 |
ghdr.cmd != CTRL_CMD_DELMCAST_GRP) { |
119 |
fprintf(stderr, "%s: unknown netlink controller command %d\n", |
120 |
fprintf(stderr, "%s: unknown netlink controller command %d\n", |
120 |
progname, ghdr->cmd); |
121 |
progname, ghdr.cmd); |
121 |
return 0; |
122 |
return 0; |
122 |
} |
123 |
} |
123 |
|
124 |
|
124 |
/* set attrs to point to the attribute */ |
125 |
/* set attrs to point to the attribute */ |
125 |
attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN); |
126 |
attrs = (struct rtattr *)((char *)NLMSG_DATA(n) + GENL_HDRLEN); |
126 |
/* Read the table from the message into "tb". This actually just */ |
127 |
/* Read the table from the message into "tb". This actually just */ |
127 |
/* places pointers into the message into tb[]. */ |
128 |
/* places pointers into the message into tb[]. */ |
128 |
parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); |
129 |
parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); |
Lines 168-174
Link Here
|
168 |
/* pointer to the nlmsghdr in req */ |
169 |
/* pointer to the nlmsghdr in req */ |
169 |
struct nlmsghdr *nlh; |
170 |
struct nlmsghdr *nlh; |
170 |
/* pointer to the generic netlink header in req */ |
171 |
/* pointer to the generic netlink header in req */ |
171 |
struct genlmsghdr *ghdr; |
172 |
struct genlmsghdr ghdr; |
172 |
/* return value */ |
173 |
/* return value */ |
173 |
int ret = -1; |
174 |
int ret = -1; |
174 |
|
175 |
|
Lines 183-191
Link Here
|
183 |
nlh->nlmsg_type = GENL_ID_CTRL; |
184 |
nlh->nlmsg_type = GENL_ID_CTRL; |
184 |
|
185 |
|
185 |
/* set up ghdr to point to the generic netlink header */ |
186 |
/* set up ghdr to point to the generic netlink header */ |
186 |
ghdr = NLMSG_DATA(&req.n); |
|
|
187 |
/* set the command we want to run: "GETFAMILY" */ |
187 |
/* set the command we want to run: "GETFAMILY" */ |
188 |
ghdr->cmd = CTRL_CMD_GETFAMILY; |
188 |
ghdr.cmd = CTRL_CMD_GETFAMILY; |
|
|
189 |
memcpy(NLMSG_DATA(&req.n), &ghdr, sizeof(ghdr)); |
189 |
|
190 |
|
190 |
/* the message payload is the family name */ |
191 |
/* the message payload is the family name */ |
191 |
addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, |
192 |
addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, |