# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
# endif
+#define INIT_STRUCT(type, name, ...) \
+ do { \
+ type tmp = { __VA_ARGS__ }; \
+ memcpy(name, &tmp, sizeof(tmp)); \
+ } while (0)
static void
test_nlmsg_type(const int fd)
{
/* unspecified family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = 0;
/* unspecified family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = 0;
memcpy(family + 1, "1234", 4);
/* unspecified family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = 0;
/* unspecified family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = 0;
memcpy(family + 1, "1234", 4);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_UNIX;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_UNIX;
memcpy(family + 1, "1234", 4);
/* unix_diag_req */
nlh = nlh0 - sizeof(*req);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct unix_diag_req) {
.sdiag_family = AF_UNIX,
.udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", udiag_states=1<<TCP_ESTABLISHED|1<<TCP_LISTEN, udiag_ino=%u"
", udiag_show=UDIAG_SHOW_NAME, udiag_cookie=[%u, %u]}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len,
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
253, 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of unix_diag_req */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_UNIX;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_UNIX;
memcpy(family + 1, "1234", 4);
/* unix_diag_msg */
nlh = nlh0 - sizeof(*msg);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*msg),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
msg = NLMSG_DATA(nlh);
*msg = (struct unix_diag_msg) {
.udiag_family = AF_UNIX,
.udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}"
", udiag_state=TCP_FIN_WAIT1"
", udiag_ino=%u, udiag_cookie=[%u, %u]}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len,
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
0xfacefeed, 0xdeadbeef, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ sprintrc(rc));
/* short read of unix_diag_msg */
nlh = nlh0 - (sizeof(*msg) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_NETLINK;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_NETLINK;
memcpy(family + 1, "1234", 4);
/* netlink_diag_req */
nlh = nlh0 - sizeof(*req);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct netlink_diag_req) {
.sdiag_family = AF_NETLINK,
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", {sdiag_family=AF_NETLINK, sdiag_protocol=NDIAG_PROTO_ALL"
", ndiag_ino=%u, ndiag_show=NDIAG_SHOW_MEMINFO"
", ndiag_cookie=[%u, %u]}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xfacefeed, 0xdeadbeef,
- 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
req->sdiag_protocol = NETLINK_ROUTE;
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", {sdiag_family=AF_NETLINK, sdiag_protocol=NETLINK_ROUTE"
", ndiag_ino=%u, ndiag_show=NDIAG_SHOW_MEMINFO"
", ndiag_cookie=[%u, %u]}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xfacefeed, 0xdeadbeef,
- 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of netlink_diag_req */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_NETLINK;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_NETLINK;
memcpy(family + 1, "1234", 4);
/* netlink_diag_msg */
nlh = nlh0 - sizeof(*msg);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*msg),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
msg = NLMSG_DATA(nlh);
*msg = (struct netlink_diag_msg) {
.ndiag_family = AF_NETLINK,
.ndiag_cookie = { 0xbadc0ded, 0xdeadbeef }
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}, {ndiag_family=AF_NETLINK"
", ndiag_state=NETLINK_CONNECTED, ndiag_portid=%u"
", ndiag_dst_portid=%u, ndiag_dst_group=%u, ndiag_ino=%u"
", ndiag_cookie=[%u, %u]}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xbadc0ded, 0xdeadbeef, 0xfacefeed,
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ 0xbadc0ded, 0xdeadbeef, 0xfacefeed,
0xdaeefacd, 0xbadc0ded, 0xdeadbeef,
- nlh->nlmsg_len, sprintrc(rc));
+ NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ sprintrc(rc));
/* short read of netlink_diag_msg */
nlh = nlh0 - (sizeof(*msg) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_PACKET;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_PACKET;
memcpy(family + 1, "1234", 4);
/* packet_diag_req */
nlh = nlh0 - sizeof(*req);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct packet_diag_req) {
.sdiag_family = AF_PACKET,
.pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", pdiag_ino=%u, pdiag_show=PACKET_SHOW_INFO"
", pdiag_cookie=[%u, %u]}}, %u"
", MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of packet_diag_req */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_PACKET;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_PACKET;
memcpy(family + 1, "1234", 4);
/* packet_diag_msg */
nlh = nlh0 - sizeof(*msg);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*msg),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
msg = NLMSG_DATA(nlh);
*msg = (struct packet_diag_msg) {
.pdiag_family = AF_PACKET,
.pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
};
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}"
", {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM"
", pdiag_num=%u, pdiag_ino=%u, pdiag_cookie=[%u, %u]}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xbadc, 0xfacefeed,
- 0xdeadbeef, 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ 0xbadc, 0xfacefeed, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ sprintrc(rc));
/* short read of packet_diag_msg */
nlh = nlh0 - (sizeof(*msg) - 1);
nlh = nlh0 - sizeof(*req);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct inet_diag_req_v2) {
if (!inet_pton(AF_INET, address, &req->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", idiag_dport=htons(%u), inet_pton(AF_INET, \"%s\", &idiag_src)"
", inet_pton(AF_INET, \"%s\", &idiag_dst), idiag_if=%u"
", idiag_cookie=[%u, %u]}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, ntohs(0xfacd), ntohs(0xdead),
- address, address, 0xadcdfafc, 0xdeadbeef,
- 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ ntohs(0xfacd), ntohs(0xdead), address, address,
+ 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
req->sdiag_family = AF_INET6;
if (!inet_pton(AF_INET6, address6, &req->id.idiag_src))
if (!inet_pton(AF_INET6, address6, &req->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", idiag_dport=htons(%u), inet_pton(AF_INET6, \"%s\", &idiag_src)"
", inet_pton(AF_INET6, \"%s\", &idiag_dst), idiag_if=%u"
", idiag_cookie=[%u, %u]}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, ntohs(0xfacd), ntohs(0xdead),
- address6, address6, 0xadcdfafc, 0xdeadbeef,
- 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ ntohs(0xfacd), ntohs(0xdead), address6, address6,
+ 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
}
static void
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = TCPDIAG_GETSOCK,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* family and string */
nlh = nlh0 - (sizeof(*family) + 4);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = TCPDIAG_GETSOCK,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* inet_diag_req */
nlh = nlh0 - sizeof(*req);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = TCPDIAG_GETSOCK,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct inet_diag_req) {
if (!inet_pton(AF_INET, address, &req->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=TCPDIAG_GETSOCK"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", idiag_if=%u, idiag_cookie=[%u, %u]}"
", idiag_states=1<<TCP_LAST_ACK, idiag_dbs=%u}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xde, 0xba, ntohs(0xdead),
- ntohs(0xadcd), address, address, 0xadcdfafc,
- 0xdeadbeef, 0xbadc0ded, 0xfacefeed,
- nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ 0xde, 0xba, ntohs(0xdead), ntohs(0xadcd), address, address,
+ 0xadcdfafc, 0xdeadbeef, 0xbadc0ded, 0xfacefeed,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of inet_diag_req */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* family and string */
nlh = nlh0 - sizeof(*family) - 4;
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* inet_diag_req_v2 */
nlh = nlh0 - sizeof(*req);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct inet_diag_req_v2) {
if (!inet_pton(AF_INET, address, &req->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}"
", idiag_dport=htons(%u), inet_pton(AF_INET, \"%s\", &idiag_src)"
", inet_pton(AF_INET, \"%s\", &idiag_dst), idiag_if=%u"
", idiag_cookie=[%u, %u]}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, ntohs(0xfacd), ntohs(0xdead),
- address, address, 0xadcdfafc, 0xdeadbeef,
- 0xbadc0ded, nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ ntohs(0xfacd), ntohs(0xdead), address, address,
+ 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of inet_diag_req_v2 */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* family and string */
nlh = nlh0 - sizeof(*family) - 4;
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_INET;
/* inet_diag_msg */
nlh = nlh0 - sizeof(*msg);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*msg),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
msg = NLMSG_DATA(nlh);
*msg = (struct inet_diag_msg) {
if (!inet_pton(AF_INET, address, &msg->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}"
", idiag_expires=%u, idiag_rqueue=%u, idiag_wqueue=%u"
", idiag_uid=%u, idiag_inode=%u}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xfa, 0xde, ntohs(0xfacf), ntohs(0xdead),
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ 0xfa, 0xde, ntohs(0xfacf), ntohs(0xdead),
address, address, 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
0xfacefeed, 0xdeadbeef, 0xadcdfafc, 0xdecefaeb, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ sprintrc(rc));
/* short read of inet_diag_msg */
nlh = nlh0 - (sizeof(*msg) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_SMC;
/* family and string */
nlh = nlh0 - sizeof(*family) - 4;
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
family = NLMSG_DATA(nlh);
*family = AF_SMC;
/* smc_diag_req */
nlh = nlh0 - sizeof(*req);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_REQUEST,
- };
+ .nlmsg_flags = NLM_F_REQUEST
+ );
req = NLMSG_DATA(nlh);
*req = (struct smc_diag_req) {
if (!inet_pton(AF_INET, address, &req->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_REQUEST, seq=0, pid=0}, {diag_family=AF_SMC"
", inet_pton(AF_INET, \"%s\", &idiag_dst)"
", idiag_if=%u, idiag_cookie=[%u, %u]}}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, htons(0xdead), htons(0xadcd),
- address, address, 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ htons(0xdead), htons(0xadcd), address, address,
+ 0xadcdfafc, 0xdeadbeef, 0xbadc0ded,
+ NLMSG_HDRLEN + (unsigned int) sizeof(*req),
+ sprintrc(rc));
/* short read of smc_diag_req */
nlh = nlh0 - (sizeof(*req) - 1);
/* family only */
nlh = nlh0 - sizeof(*family);
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_SMC;
/* family and string */
nlh = nlh0 - sizeof(*family) - 4;
/* beware of unaligned access to nlh members */
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*family) + 4,
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
family = NLMSG_DATA(nlh);
*family = AF_SMC;
/* smc_diag_msg */
nlh = nlh0 - sizeof(*msg);
- *nlh = (struct nlmsghdr) {
+ INIT_STRUCT(struct nlmsghdr, nlh,
.nlmsg_len = NLMSG_HDRLEN + sizeof(*msg),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
- .nlmsg_flags = NLM_F_DUMP,
- };
+ .nlmsg_flags = NLM_F_DUMP
+ );
msg = NLMSG_DATA(nlh);
*msg = (struct smc_diag_msg) {
if (!inet_pton(AF_INET, address, &msg->id.idiag_dst))
perror_msg_and_skip("sendto");
- rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+ NULL, 0);
printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}, {diag_family=AF_SMC"
", idiag_if=%u, idiag_cookie=[%u, %u]}"
", diag_uid=%u, diag_inode=%u}}, %u"
", MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh->nlmsg_len, 0xde, 0xba,
- htons(0xdead), htons(0xadcd), address, address,
+ fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ 0xde, 0xba, htons(0xdead), htons(0xadcd), address, address,
0xadcdfafc, 0xdeadbeef, 0xbadc0ded, 0xadcdfafc, 0xbadc0ded,
- nlh->nlmsg_len, sprintrc(rc));
+ NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+ sprintrc(rc));
/* short read of smc_diag_msg */
nlh = nlh0 - (sizeof(*msg) - 1);