Lines Matching refs:handle

215 int usb_mmap(pcap_t* handle)
217 struct pcap_usb_linux *handlep = handle->priv;
218 int len = ioctl(handle->fd, MON_IOCQ_RING_SIZE);
224 MAP_SHARED, handle->fd, 0);
341 usb_activate(pcap_t* handle)
343 struct pcap_usb_linux *handlep = handle->priv;
347 handle->bufsize = handle->snapshot;
348 handle->offset = 0;
349 handle->linktype = DLT_USB_LINUX;
351 handle->inject_op = usb_inject_linux;
352 handle->setfilter_op = install_bpf_program; /* no kernel filtering */
353 handle->setdirection_op = usb_setdirection_linux;
354 handle->set_datalink_op = NULL; /* can't change data link type */
355 handle->getnonblock_op = pcap_getnonblock_fd;
356 handle->setnonblock_op = pcap_setnonblock_fd;
359 if (sscanf(handle->opt.source, USB_IFACE"%d", &handlep->bus_index) != 1)
361 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
362 "Can't get USB bus index from %s", handle->opt.source);
368 handle->fd = open(full_path, O_RDONLY, 0);
369 if (handle->fd >= 0)
371 if (handle->opt.rfmon) {
375 close(handle->fd);
380 if (usb_mmap(handle)) {
381 handle->linktype = DLT_USB_LINUX_MMAPPED;
382 handle->stats_op = usb_stats_linux_bin;
383 handle->read_op = usb_read_linux_mmap;
384 handle->cleanup_op = usb_cleanup_linux_mmap;
388 * "handle->fd" is a real file, so "select()" and
391 handle->selectable_fd = handle->fd;
396 handle->stats_op = usb_stats_linux_bin;
397 handle->read_op = usb_read_linux_bin;
403 handle->fd = open(full_path, O_RDONLY, 0);
404 if (handle->fd < 0)
413 handle->fd = open(full_path, O_RDONLY, 0);
415 if (handle->fd < 0) {
417 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
423 if (handle->opt.rfmon) {
427 close(handle->fd);
431 handle->stats_op = usb_stats_linux;
432 handle->read_op = usb_read_linux;
436 * "handle->fd" is a real file, so "select()" and "poll()"
439 handle->selectable_fd = handle->fd;
443 handle->buffer = malloc(handle->bufsize);
444 if (!handle->buffer) {
445 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
447 close(handle->fd);
465 usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
471 struct pcap_usb_linux *handlep = handle->priv;
476 u_char * rawdata = handle->buffer;
478 pcap_usb_header* uhdr = (pcap_usb_header*)handle->buffer;
484 ret = read(handle->fd, line, USB_LINE_LEN - 1);
485 if (handle->break_loop)
487 handle->break_loop = 0;
496 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
497 "Can't read from fd %d: %s", handle->fd, strerror(errno));
509 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
523 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
550 if (handle->direction == PCAP_D_OUT)
554 if (handle->direction == PCAP_D_IN)
575 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
599 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
617 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
636 while ((string[0] != 0) && (string[1] != 0) && (pkth.caplen < handle->snapshot))
649 if (pkth.caplen > handle->snapshot)
650 pkth.caplen = handle->snapshot;
652 if (handle->fcode.bf_insns == NULL ||
653 bpf_filter(handle->fcode.bf_insns, handle->buffer,
656 callback(user, &pkth, handle->buffer);
663 usb_inject_linux(pcap_t *handle, const void *buf, size_t size)
665 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on "
671 usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
673 struct pcap_usb_linux *handlep = handle->priv;
694 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
709 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
755 usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
757 struct pcap_usb_linux *handlep = handle->priv;
760 ret = ioctl(handle->fd, MON_IOCG_STATS, &st);
763 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
764 "Can't read stats from fd %d:%s ", handle->fd, strerror(errno));
779 usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
781 struct pcap_usb_linux *handlep = handle->priv;
785 int clen = handle->snapshot - sizeof(pcap_usb_header);
788 info.hdr = (pcap_usb_header*) handle->buffer;
789 info.data = handle->buffer + sizeof(pcap_usb_header);
794 ret = ioctl(handle->fd, MON_IOCX_GET, &info);
795 if (handle->break_loop)
797 handle->break_loop = 0;
806 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
807 "Can't read from fd %d: %s", handle->fd, strerror(errno));
821 if (handle->fcode.bf_insns == NULL ||
822 bpf_filter(handle->fcode.bf_insns, handle->buffer,
825 callback(user, &pkth, handle->buffer);
838 usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
840 struct pcap_usb_linux *handlep = handle->priv;
849 max_clen = handle->snapshot - sizeof(pcap_usb_header);
865 ret = ioctl(handle->fd, MON_IOCX_MFETCH, &fetch);
866 if (handle->break_loop)
868 handle->break_loop = 0;
877 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
878 "Can't mfetch fd %d: %s", handle->fd, strerror(errno));
902 if (handle->fcode.bf_insns == NULL ||
903 bpf_filter(handle->fcode.bf_insns, (u_char*) hdr,
917 ioctl(handle->fd, MON_IOCH_MFLUSH, nflush);
922 usb_cleanup_linux_mmap(pcap_t* handle)
924 struct pcap_usb_linux *handlep = handle->priv;
931 pcap_cleanup_live_common(handle);