diff options
author | /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org> | 2005-07-18 19:13:28 +0000 |
---|---|---|
committer | /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org> | 2005-07-18 19:13:28 +0000 |
commit | a0ca0df7c2acb455ca57be4c13704593b422dfd8 (patch) | |
tree | 1e5ed830a30fef146b97a975e81c343aa52c5b4a | |
parent | dc44aeeddc218d9ae45006b15fbcde751567a2ef (diff) |
- return error from underyling close() in nfnl_close()
- abord if -EBADF
- return 0 in case of NLMSG_DONE
- use new NLMSG_TAIL macro
- fix alignment (missing NLMSG_ALIGN)
(Pablo Neira)
-rw-r--r-- | libnfnetlink.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libnfnetlink.c b/libnfnetlink.c index 531fd0a..cff2fcf 100644 --- a/libnfnetlink.c +++ b/libnfnetlink.c @@ -108,10 +108,7 @@ int nfnl_open(struct nfnl_handle *nfnlh, u_int8_t subsys_id, */ int nfnl_close(struct nfnl_handle *nfnlh) { - if (nfnlh->fd) - close(nfnlh->fd); - - return 0; + return close(nfnlh->fd); } /** @@ -202,6 +199,9 @@ int nfnl_listen(struct nfnl_handle *nfnlh, if (remain < 0) { if (errno == EINTR) continue; + /* Bad file descriptor */ + if (errno == EBADF) + break; nfnl_error("recvmsg overrun"); continue; } @@ -231,7 +231,7 @@ int nfnl_listen(struct nfnl_handle *nfnlh, /* end of messages reached, let's return */ if (h->nlmsg_type == NLMSG_DONE) - return -100; + return 0; /* Break the loop if success is explicitely * reported via NLM_F_ACK flag set */ @@ -400,12 +400,11 @@ int nfnl_addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, return -1; } - nfa = (struct nfattr *)(((char *)n) + NLMSG_ALIGN(n->nlmsg_len)); + nfa = NLMSG_TAIL(n); nfa->nfa_type = type; nfa->nfa_len = len; memcpy(NFA_DATA(nfa), data, alen); - n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + len); - + n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + NFA_ALIGN(len)); return 0; } @@ -482,7 +481,7 @@ int nfnl_parse_attr(struct nfattr *tb[], int max, struct nfattr *nfa, int len) { while (NFA_OK(nfa, len)) { if (nfa->nfa_type <= max) - tb[nfa->nfa_type] = nfa; + tb[nfa->nfa_type-1] = nfa; nfa = NFA_NEXT(nfa,len); } if (len) |