summaryrefslogtreecommitdiffstats
path: root/tests/test-genl.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@plip.localdomain>2008-08-20 10:01:50 (GMT)
committerThomas Graf <tgr@plip.localdomain>2008-08-20 10:01:50 (GMT)
commit562c5323af89b4386eabf90aaf47bb67dca0fb6e (patch)
tree2817ecf39a42bf4d2e5685c86d4477297232e83e /tests/test-genl.c
parent7211a835258a3c8ce1b7f98bbddd89d5b972158a (diff)
downloadlibnl-562c5323af89b4386eabf90aaf47bb67dca0fb6e.zip
libnl-562c5323af89b4386eabf90aaf47bb67dca0fb6e.tar.gz
libnl-562c5323af89b4386eabf90aaf47bb67dca0fb6e.tar.bz2
test updates
Diffstat (limited to 'tests/test-genl.c')
-rw-r--r--tests/test-genl.c58
1 files changed, 19 insertions, 39 deletions
diff --git a/tests/test-genl.c b/tests/test-genl.c
index e44b3fb..8bf60c5 100644
--- a/tests/test-genl.c
+++ b/tests/test-genl.c
@@ -2,55 +2,35 @@
int main(int argc, char *argv[])
{
- struct nl_handle *h;
+ struct nl_sock *sock;
struct nl_msg *msg;
void *hdr;
+ int err;
- if (nltool_init(argc, argv) < 0)
- return -1;
-
- h = nltool_alloc_handle();
- if (!h) {
- nl_perror("nl_handle_alloc");
- return -1;
- }
-
- if (genl_connect(h) < 0) {
- nl_perror("genl_connect");
- return -1;
- }
+ sock = nlt_alloc_socket();
+ nlt_connect(sock, NETLINK_GENERIC);
msg = nlmsg_alloc();
- if (msg == NULL) {
- nl_perror("nlmsg_alloc");
- return -1;
- }
+ if (msg == NULL)
+ fatal(NLE_NOMEM, "Unable to allocate netlink message");
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, GENL_ID_CTRL,
0, 0, CTRL_CMD_GETFAMILY, 1);
- if (hdr == NULL) {
- nl_perror("genlmsg_put");
- return -1;
- }
-
- if (nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL) < 0) {
- nl_perror("nla_put_u32(CTRL_ATTR_FAMILY_ID)");
- return -1;
- }
-
- if (nl_send_auto_complete(h, msg) < 0) {
- nl_perror("nl_send_auto_complete");
- return -1;
- }
-
- if (nl_recvmsgs_default(h) < 0) {
- nl_perror("nl_recvmsgs_def");
- return -1;
- }
+ if (hdr == NULL)
+ fatal(ENOMEM, "Unable to write genl header");
- nlmsg_free(msg);
+ if ((err = nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL)) < 0)
+ fatal(err, "Unable to add attribute: %s", nl_geterror(err));
- nl_close(h);
+ if ((err = nl_send_auto_complete(sock, msg)) < 0)
+ fatal(err, "Unable to send message: %s", nl_geterror(err));
+
+ if ((err = nl_recvmsgs_default(sock)) < 0)
+ fatal(err, "Unable to receive message: %s", nl_geterror(err));
+
+ nlmsg_free(msg);
+ nl_close(sock);
+ nl_socket_free(sock);
return 0;
}