From 3245b5835170e226877cd9abaa4aa2e78991ff0e Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 5 Jun 2017 12:16:01 +0000 Subject: [PATCH] tests: use const and designated initializers in create_nl_socket.c * tests/create_nl_socket.c: Stop including . (create_nl_socket): Use const and designated initializers. --- tests/create_nl_socket.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/create_nl_socket.c b/tests/create_nl_socket.c index c43669f6..aeac907f 100644 --- a/tests/create_nl_socket.c +++ b/tests/create_nl_socket.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016 Dmitry V. Levin + * Copyright (c) 2015-2017 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,24 +26,20 @@ */ #include "tests.h" -#include #include #include int -create_nl_socket(int proto) +create_nl_socket(const int proto) { - struct sockaddr_nl addr; - socklen_t len = sizeof(addr); - int fd; - - memset(&addr, 0, sizeof(addr)); - addr.nl_family = AF_NETLINK; - - if ((fd = socket(AF_NETLINK, SOCK_RAW, proto)) == -1) + const int fd = socket(AF_NETLINK, SOCK_RAW, proto); + if (fd < 0) perror_msg_and_skip("socket AF_NETLINK"); - if (bind(fd, (struct sockaddr *) &addr, len)) + const struct sockaddr_nl addr = { .nl_family = AF_NETLINK }; + const socklen_t len = sizeof(addr); + + if (bind(fd, (const struct sockaddr *) &addr, len)) perror_msg_and_skip("bind"); return fd; -- 2.40.0