Lines Matching +full:device +full:- +full:select
31 * Tests how select() and poll() behave on the selectable file descriptor
47 #include <sys/select.h>
71 register char *cp, *cmdbuf, *device; in main() local
77 int selectable_fd = -1; in main()
82 device = NULL; in main()
95 while ((op = getopt(argc, argv, "i:sptnq")) != -1) { in main()
99 device = optarg; in main()
104 mechanism = "select() and pcap_dispatch()"; in main()
131 fprintf(stderr, "selpolltest: choose select (-s) or poll (-p), but not both\n"); in main()
135 fprintf(stderr, "selpolltest: timeout (-t) requires select (-s) or poll (-p)\n"); in main()
138 if (device == NULL) { in main()
139 if (pcap_findalldevs(&devlist, ebuf) == -1) in main()
143 device = strdup(devlist->name); in main()
147 pd = pcap_open_live(device, 65535, 0, 1000, ebuf); in main()
152 if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) { in main()
166 * We need either an FD on which to do select()/poll() in main()
167 * or, if there isn't one, a timeout to use in select()/ in main()
171 if (selectable_fd == -1) { in main()
173 device, mechanism); in main()
176 error("select()/poll() isn't supported on %s, even with a timeout", in main()
177 device); in main()
180 * As we won't be notified by select() or poll() in main()
182 * try reading from the device every time the required in main()
185 * so we want to force non-blocking mode. in main()
189 printf("Listening on %s, using %s\n", device, in main()
194 printf("Listening on %s, using pcap_dispatch()\n", device); in main()
197 if (pcap_setnonblock(pd, 1, ebuf) == -1) in main()
207 if (selectable_fd != -1) { in main()
216 required_timeout->tv_usec < 1000) in main()
217 seltimeout.tv_usec = required_timeout->tv_usec; in main()
227 status = select((selectable_fd == -1) ? in main()
230 if (status == -1) { in main()
231 printf("Select returns error (%s)\n", in main()
236 printf("Select timed out: "); in main()
238 printf("Select returned a descriptor: "); in main()
250 status = pcap_dispatch(pd, -1, countme, in main()
263 printf("%d packets seen, %d packets counted after select returns\n", in main()
279 required_timeout->tv_usec >= 1000) in main()
280 polltimeout = (int)(required_timeout->tv_usec/1000); in main()
282 polltimeout = -1; in main()
283 status = poll(&fd, (selectable_fd == -1) ? 0 : 1, polltimeout); in main()
284 if (status == -1) { in main()
312 status = pcap_dispatch(pd, -1, countme, in main()
333 status = pcap_dispatch(pd, -1, countme, in main()
341 if (status == -2) { in main()
350 if (status == -1) { in main()
358 exit(status == -1 ? 1 : 0); in main()
372 (void)fprintf(stderr, "Usage: %s [ -sptnq ] [ -i interface ] [expression]\n", in usage()
389 if (fmt[-1] != '\n') in error()
408 if (fmt[-1] != '\n') in warning()
440 dst[-1] = ' '; in copy_argv()
442 dst[-1] = '\0'; in copy_argv()