} req;
struct nlmsghdr *nh;
struct nlmsgerr *err;
+ socklen_t addrlen;
memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
goto cleanup;
}
+ addrlen = sizeof(sa);
+ if (getsockname(sock, (struct sockaddr *)&sa, &addrlen) < 0) {
+ fprintf(stderr, "bpf: get sock name of netlink: %s\n", strerror(errno));
+ goto cleanup;
+ }
+
+ if (addrlen != sizeof(sa)) {
+ fprintf(stderr, "bpf: wrong netlink address length: %d\n", addrlen);
+ goto cleanup;
+ }
+
memset(&req, 0, sizeof(req));
req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);
nh = NLMSG_NEXT(nh, len)) {
- if (nh->nlmsg_pid != getpid()) {
+ if (nh->nlmsg_pid != sa.nl_pid) {
fprintf(stderr, "bpf: Wrong pid %d, expected %d\n",
- nh->nlmsg_pid, getpid());
+ nh->nlmsg_pid, sa.nl_pid);
errno = EBADMSG;
goto cleanup;
}