- timeout.tv_sec = 0;
- timeout.tv_usec = 1000;
- select(selectable_fd + 1, &setread, NULL,
- &setexcept, &timeout);
- } else
- select(selectable_fd + 1, &setread, NULL,
- &setexcept, NULL);
- if (FD_ISSET(selectable_fd, &setread))
- printf("Select says descriptor is readable\n");
- else
- printf("Select doesn't say descriptor is readable\n");
- if (FD_ISSET(selectable_fd, &setexcept))
- printf("Select says descriptor has exceptional condition\n");
+ seltimeout.tv_sec = 0;
+ seltimeout.tv_usec = 1000;
+ status = select(selectable_fd + 1, &setread,
+ NULL, &setexcept, &seltimeout);
+ } else {
+ status = select(selectable_fd + 1, &setread,
+ NULL, &setexcept, NULL);
+ }
+ if (status == -1) {
+ printf("Select returns error (%s)\n",
+ strerror(errno));
+ } else {
+ if (status == 0)
+ printf("Select timed out: ");
+ else
+ printf("Select returned a descriptor: ");
+ if (FD_ISSET(selectable_fd, &setread))
+ printf("readable, ");
+ else
+ printf("not readable, ");
+ if (FD_ISSET(selectable_fd, &setexcept))
+ printf("exceptional condition\n");
+ else
+ printf("no exceptional condition\n");
+ packet_count = 0;
+ status = pcap_dispatch(pd, -1, printme,
+ (u_char *)&packet_count);
+ if (status < 0)
+ break;
+ printf("\n%d packets seen, %d packets counted after select returns\n",
+ status, packet_count);
+ }
+ }
+ } else if (dopoll) {
+ for (;;) {
+ struct pollfd fd;
+ int polltimeout;
+
+ fd.fd = selectable_fd;
+ fd.events = POLLIN;
+ if (dotimeout)
+ polltimeout = 1;