for (i = 0; i < iovlen; i++) {
h = iov[i].iov_base;
h->nlmsg_seq = seq = ++rtnl->seq; if (answer == NULL)
h->nlmsg_flags |= NLM_F_ACK;
}
status = sendmsg(rtnl->fd, &msg, 0); if (status < 0) {
perror("Cannot talk to rtnetlink"); return -1;
} /* change msg to use the response iov */
msg.msg_iov = &riov;
msg.msg_iovlen = 1;
i = 0; while (1) {
next:
status = rtnl_recvmsg(rtnl->fd, &msg, &buf);
++i; if (status < 0) return status; if (msg.msg_namelen != sizeof(nladdr)) {
fprintf(stderr, "Sender address length == %d!\n",
msg.msg_namelen); exit(1);
} for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) { int len = h->nlmsg_len; int l = len - sizeof(*h);
if (l < 0 || len > status) { if (msg.msg_flags & MSG_TRUNC) {
fprintf(stderr, "Truncated message!\n");
free(buf); return -1;
}
fprintf(stderr, "Malformed message: len=%d!\n",
len); exit(1);
} if (nladdr.nl_pid != 0 ||
h->nlmsg_pid != rtnl->local.nl_pid ||
h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) { /* Don't forget to skip that message. */
status -= NLMSG_ALIGN(len);
h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); continue;
} if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h); int error = err->error;
if (l < sizeof(struct nlmsgerr)) {
fprintf(stderr, "ERROR truncated\n");
free(buf); return -1;
} if (error) {
errno = -error; if (rtnl->proto != NETLINK_SOCK_DIAG &&
show_rtnl_err)
rtnl_talk_error(h, err, errfn);
} if (i < iovlen) {
free(buf); goto next;
} if (error) {
free(buf); return -i;
} if (answer)
*answer = (struct nlmsghdr *)buf; else
free(buf); return 0;
} if (answer) {
*answer = (struct nlmsghdr *)buf; return 0;
}
fprintf(stderr, "Unexpected reply!\n");
status -= NLMSG_ALIGN(len);
h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
}
free(buf); if (msg.msg_flags & MSG_TRUNC) {
fprintf(stderr, "Message truncated!\n"); continue;
} if (status) {
fprintf(stderr, "Remnant of size %d!\n", status); exit(1);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.