printf("Select returns error (%s)\n",
strerror(errno));
} else {
- if (status == 0)
- printf("Select timed out");
- else
- printf("Select returned a descriptor");
- if (selectable_fd == -1)
- printf("\n");
- else {
+ if (selectable_fd == -1) {
+ if (status != 0)
+ printf("Select returned a descriptor\n");
+ } else {
+ if (status == 0)
+ printf("Select timed out: ");
+ else
+ printf("Select returned a descriptor: ");
if (FD_ISSET(selectable_fd, &setread))
- printf(": readable, ");
+ printf("readable, ");
else
- printf(": not readable, ");
+ printf("not readable, ");
if (FD_ISSET(selectable_fd, &setexcept))
printf("exceptional condition\n");
else
(u_char *)&packet_count);
if (status < 0)
break;
- printf("%d packets seen, %d packets counted after select returns\n",
- status, packet_count);
+ /*
+ * Don't report this if we're using a
+ * required timeout and we got no packets,
+ * because that could be a very short timeout,
+ * and we don't want to spam the user with
+ * a ton of "no packets" reports.
+ */
+ if (status != 0 || packet_count != 0 ||
+ selectable_fd != -1) {
+ printf("%d packets seen, %d packets counted after select returns\n",
+ status, packet_count);
+ }
}
}
} else if (dopoll) {
printf("Poll returns error (%s)\n",
strerror(errno));
} else {
- if (status == 0)
- printf("Poll timed out\n");
- else {
- printf("Poll returned a descriptor: ");
- if (fd.revents & POLLIN)
- printf("readable, ");
- else
- printf("not readable, ");
- if (fd.revents & POLLERR)
- printf("exceptional condition, ");
- else
- printf("no exceptional condition, ");
- if (fd.revents & POLLHUP)
- printf("disconnect, ");
- else
- printf("no disconnect, ");
- if (fd.revents & POLLNVAL)
- printf("invalid\n");
- else
- printf("not invalid\n");
+ if (selectable_fd == -1) {
+ if (status != 0)
+ printf("Poll returned a descriptor\n");
+ } else {
+ if (status == 0)
+ printf("Poll timed out\n");
+ else {
+ printf("Poll returned a descriptor: ");
+ if (fd.revents & POLLIN)
+ printf("readable, ");
+ else
+ printf("not readable, ");
+ if (fd.revents & POLLERR)
+ printf("exceptional condition, ");
+ else
+ printf("no exceptional condition, ");
+ if (fd.revents & POLLHUP)
+ printf("disconnect, ");
+ else
+ printf("no disconnect, ");
+ if (fd.revents & POLLNVAL)
+ printf("invalid\n");
+ else
+ printf("not invalid\n");
+ }
}
packet_count = 0;
status = pcap_dispatch(pd, -1, countme,
(u_char *)&packet_count);
if (status < 0)
break;
- printf("%d packets seen, %d packets counted after poll returns\n",
- status, packet_count);
+ /*
+ * Don't report this if we're using a
+ * required timeout and we got no packets,
+ * because that could be a very short timeout,
+ * and we don't want to spam the user with
+ * a ton of "no packets" reports.
+ */
+ if (status != 0 || packet_count != 0 ||
+ selectable_fd != -1) {
+ printf("%d packets seen, %d packets counted after poll returns\n",
+ status, packet_count);
+ }
}
}
} else {