144d362409d5469aed47d19e7908d19bd194493aThomas Graf#include "../src/utils.h"
244d362409d5469aed47d19e7908d19bd194493aThomas Graf
344d362409d5469aed47d19e7908d19bd194493aThomas Grafint main(int argc, char *argv[])
444d362409d5469aed47d19e7908d19bd194493aThomas Graf{
5562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	struct nl_sock *sock;
644d362409d5469aed47d19e7908d19bd194493aThomas Graf	struct nl_msg *msg;
744d362409d5469aed47d19e7908d19bd194493aThomas Graf	void *hdr;
8562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	int err;
944d362409d5469aed47d19e7908d19bd194493aThomas Graf
10562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	sock = nlt_alloc_socket();
11562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	nlt_connect(sock, NETLINK_GENERIC);
1244d362409d5469aed47d19e7908d19bd194493aThomas Graf
1344d362409d5469aed47d19e7908d19bd194493aThomas Graf	msg = nlmsg_alloc();
14562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	if (msg == NULL)
15562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf		fatal(NLE_NOMEM, "Unable to allocate netlink message");
1644d362409d5469aed47d19e7908d19bd194493aThomas Graf
1744d362409d5469aed47d19e7908d19bd194493aThomas Graf	hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, GENL_ID_CTRL,
1844d362409d5469aed47d19e7908d19bd194493aThomas Graf			  0, 0, CTRL_CMD_GETFAMILY, 1);
19562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	if (hdr == NULL)
20562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf		fatal(ENOMEM, "Unable to write genl header");
2144d362409d5469aed47d19e7908d19bd194493aThomas Graf
22562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	if ((err = nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL)) < 0)
23562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf		fatal(err, "Unable to add attribute: %s", nl_geterror(err));
2444d362409d5469aed47d19e7908d19bd194493aThomas Graf
25562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	if ((err = nl_send_auto_complete(sock, msg)) < 0)
26562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf		fatal(err, "Unable to send message: %s", nl_geterror(err));
27562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf
28562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	if ((err = nl_recvmsgs_default(sock)) < 0)
29562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf		fatal(err, "Unable to receive message: %s", nl_geterror(err));
30562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf
31562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	nlmsg_free(msg);
32562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	nl_close(sock);
33562c5323af89b4386eabf90aaf47bb67dca0fb6eThomas Graf	nl_socket_free(sock);
3444d362409d5469aed47d19e7908d19bd194493aThomas Graf
3544d362409d5469aed47d19e7908d19bd194493aThomas Graf	return 0;
3644d362409d5469aed47d19e7908d19bd194493aThomas Graf}
37