summaryrefslogtreecommitdiff
path: root/lib/nl.c
diff options
context:
space:
mode:
authorКоренберг Марк (дома) <socketpair@gmail.com>2012-10-19 23:06:23 +0600
committerКоренберг Марк (дома) <socketpair@gmail.com>2012-10-19 23:49:30 +0600
commitda694e6c7b11d475d84ca6addeae34a6dac8c949 (patch)
tree43e4706a77475207b3703de4b6325c2f584105a7 /lib/nl.c
parent2249eaebd4bde07e33f265e7eaac5ad85b5f1253 (diff)
downloadlibnl-da694e6c7b11d475d84ca6addeae34a6dac8c949.tar.gz
nl_recv(): small code cleanups
1. memset around nla is unnecessary 2. calloc() is unnecessary. malloc() used instead.
Diffstat (limited to 'lib/nl.c')
-rw-r--r--lib/nl.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/nl.c b/lib/nl.c
index 7f47223b..284d23c8 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -405,8 +405,8 @@ errout:
/**
* Receive data from netlink socket
* @arg sk Netlink socket.
- * @arg nla Destination pointer for peer's netlink address.
- * @arg buf Destination pointer for message content.
+ * @arg nla Destination pointer for peer's netlink address. (required)
+ * @arg buf Destination pointer for message content. (required)
* @arg creds Destination pointer for credentials.
*
* Receives a netlink message, allocates a buffer in \c *buf and
@@ -433,11 +433,7 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
.msg_namelen = sizeof(struct sockaddr_nl),
.msg_iov = &iov,
.msg_iovlen = 1,
- .msg_control = NULL,
- .msg_controllen = 0,
- .msg_flags = 0,
};
- memset(nla, 0, sizeof(*nla));
struct ucred* tmpcreds = NULL;
int retval = 0;
@@ -457,7 +453,7 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
if (sk->s_flags & NL_SOCK_PASSCRED) {
msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
- msg.msg_control = calloc(1, msg.msg_controllen);
+ msg.msg_control = malloc(msg.msg_controllen);
if (!msg.msg_control) {
retval = -NLE_NOMEM;
goto abort;
@@ -496,7 +492,7 @@ retry:
goto retry;
}
- if (iov.iov_len < n || msg.msg_flags & MSG_TRUNC) {
+ if (iov.iov_len < n || (msg.msg_flags & MSG_TRUNC)) {
void *tmp;
/* Provided buffer is not long enough, enlarge it
* to size of n (which should be total length of the message)