summaryrefslogtreecommitdiff
path: root/misc/ss.c
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2019-11-09 00:38:37 +0000
committerDavid Ahern <dsahern@gmail.com>2019-11-09 00:38:37 +0000
commit081140bbc43df11da5cc3f520f8473468094b60b (patch)
tree8fb8788c2e129bdb4d7cd9bfa442e91e57ebf362 /misc/ss.c
parentfb2e033add073893dea71bb483353790fe8c5354 (diff)
parent0932814458eb386644c1248e5aabf8303c38d7bb (diff)
downloadiproute2-081140bbc43df11da5cc3f520f8473468094b60b.tar.gz
Merge branch 'master' into next
Signed-off-by: David Ahern <dsahern@gmail.com>
Diffstat (limited to 'misc/ss.c')
-rw-r--r--misc/ss.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/misc/ss.c b/misc/ss.c
index c93d72c3..f2a64941 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -3418,28 +3418,28 @@ static int tcp_show_netlink_file(struct filter *f)
}
while (1) {
- int status, err2;
+ int err2;
+ size_t status, nitems;
struct nlmsghdr *h = (struct nlmsghdr *)buf;
struct sockstat s = {};
status = fread(buf, 1, sizeof(*h), fp);
- if (status < 0) {
- perror("Reading header from $TCPDIAG_FILE");
- break;
- }
if (status != sizeof(*h)) {
- perror("Unexpected EOF reading $TCPDIAG_FILE");
+ if (ferror(fp))
+ perror("Reading header from $TCPDIAG_FILE");
+ if (feof(fp))
+ fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
break;
}
- status = fread(h+1, 1, NLMSG_ALIGN(h->nlmsg_len-sizeof(*h)), fp);
+ nitems = NLMSG_ALIGN(h->nlmsg_len - sizeof(*h));
+ status = fread(h+1, 1, nitems, fp);
- if (status < 0) {
- perror("Reading $TCPDIAG_FILE");
- break;
- }
- if (status + sizeof(*h) < h->nlmsg_len) {
- perror("Unexpected EOF reading $TCPDIAG_FILE");
+ if (status != nitems) {
+ if (ferror(fp))
+ perror("Reading $TCPDIAG_FILE");
+ if (feof(fp))
+ fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
break;
}