当前位置: 首页>>代码示例>>C++>>正文


C++ pcap_fileno函数代码示例

本文整理汇总了C++中pcap_fileno函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_fileno函数的具体用法?C++ pcap_fileno怎么用?C++ pcap_fileno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pcap_fileno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: descriptor_set_tsmode

// FIXME this is kind of a mess, all options need to be double-check for
// backward compatibility
int
descriptor_set_tsmode(struct radclock *handle, pcap_t *p_handle, int kmode)
{
	u_int bd_tstamp;

	bd_tstamp = 0;

	switch (handle->kernel_version) {

	case 0:
	case 1:
		if (ioctl(pcap_fileno(p_handle), BIOCSRADCLOCKTSMODE, (caddr_t)&kmode) == -1) {
			logger(LOG_ERR, "Setting capture mode failed");
			return (1);
		}
		break;

	case 2:
	case 3:
		/* No more Faircompare mode in kernel version 2, it is identical to
		 * SYSCLOCK
		 */
		switch (kmode) {
			case RADCLOCK_TSMODE_SYSCLOCK:
			case RADCLOCK_TSMODE_FAIRCOMPARE:
				bd_tstamp = BPF_T_MICROTIME;
				break;
			case RADCLOCK_TSMODE_RADCLOCK:
				// TODO this is not very clean, need to do better management of
				// the format flag
				bd_tstamp = BPF_T_FFCOUNTER;
//				bd_tstamp = BPF_T_FFCOUNTER | BPF_T_FFCLOCK;
//				bd_tstamp = BPF_T_MICROTIME | BPF_T_FFCLOCK | BPF_T_MONOTONIC;
				break;
			default:
				logger(LOG_ERR, "descriptor_set_tsmode: Unknown timestamping mode.");
				return (1);
		}

		if (ioctl(pcap_fileno(p_handle), BIOCSTSTAMP, (caddr_t)&bd_tstamp) == -1) {
			logger(LOG_ERR, "Setting capture mode failed: %s", strerror(errno));
			return (1);
		}

		break;

	default:
		logger(LOG_ERR, "Unknown kernel version");
		return (1);

	}

	return (0);
}
开发者ID:ben51,项目名称:radclock,代码行数:56,代码来源:pcap-fbsd.c

示例2: pcap_ex_immediate

int
pcap_ex_immediate(pcap_t *pcap)
{
#ifdef _WIN32
    return pcap_setmintocopy(pcap, 1);
#elif defined BIOCIMMEDIATE
    int n = 1;
    return ioctl(pcap_fileno(pcap), BIOCIMMEDIATE, &n);
#else /* XXX On OSX Yosemite (10.10.3) BIOCIMMEDIATE is not defined) */
    int n = 1;
    return ioctl(pcap_fileno(pcap), _IOW('B',112, u_int), &n);
#endif
}
开发者ID:WilenceYao,项目名称:pypcap,代码行数:13,代码来源:pcap_ex.c

示例3: pcap_open

struct pcap_port *
pcap_open(struct pcap_port *pcap_port) {
    char errbuf[PCAP_ERRBUF_SIZE];
    struct pcap_drv *pcap_drv = pcap_port->drv;

    pcap_t *pcap = NULL;
    pcap = pcap_open_live(pcap_port->name, PCAP_SNAPLEN, true/*promisc*/, -1/*to_ms*/, errbuf);
    if (pcap == NULL) {
        logger_log(pcap_drv->logger, LOG_ERR, "Unable to open device %s: %s.", pcap_port->name, errbuf);
        return NULL;
    }

    if(pcap_setnonblock(pcap, true, errbuf) != 0) {
        logger_log(pcap_drv->logger, LOG_ERR, "Unable to set device to promisc %s: %s.", pcap_port->name, errbuf);
        return NULL;
    }

    if(pcap_setdirection(pcap, PCAP_D_IN) != 0) {
        logger_log(pcap_drv->logger, LOG_ERR, "Unable to set device direction %s: %s.", pcap_port->name, pcap_geterr(pcap));
        return NULL;
    }

    pcap_port->pcap    = pcap;
    pcap_port->fd      = pcap_fileno(pcap);

    pcap_port->watcher = malloc(sizeof(ev_io));
    pcap_port->watcher->data = pcap_port;
    ev_io_init(pcap_port->watcher, event_loop_packet_in_cb, pcap_port->fd, EV_READ);
    pcap_port_fill(pcap_port);

    return pcap_port;
}
开发者ID:elekjani,项目名称:ofss,代码行数:32,代码来源:pcap_port.c

示例4: l2_packet_init_libpcap

static int l2_packet_init_libpcap(struct l2_packet_data *l2,
				  unsigned short protocol)
{
	bpf_u_int32 pcap_maskp, pcap_netp;
	char pcap_filter[200], pcap_err[PCAP_ERRBUF_SIZE];
	struct bpf_program pcap_fp;

	pcap_lookupnet(l2->ifname, &pcap_netp, &pcap_maskp, pcap_err);
	l2->pcap = pcap_open_live(l2->ifname, 2500, 0, 10, pcap_err);
	if (l2->pcap == NULL) {
		fprintf(stderr, "pcap_open_live: %s\n", pcap_err);
		fprintf(stderr, "ifname='%s'\n", l2->ifname);
		return -1;
	}
	if (pcap_datalink(l2->pcap) != DLT_EN10MB &&
	    pcap_set_datalink(l2->pcap, DLT_EN10MB) < 0) {
		fprintf(stderr, "pcap_set_datalink(DLT_EN10MB): %s\n",
			pcap_geterr(l2->pcap));
		return -1;
	}
	os_snprintf(pcap_filter, sizeof(pcap_filter),
		    "not ether src " MACSTR " and "
		    "( ether dst " MACSTR " or ether dst " MACSTR " ) and "
		    "ether proto 0x%x",
		    MAC2STR(l2->own_addr), /* do not receive own packets */
		    MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
		    protocol);
	if (pcap_compile(l2->pcap, &pcap_fp, pcap_filter, 1, pcap_netp) < 0) {
		fprintf(stderr, "pcap_compile: %s\n", pcap_geterr(l2->pcap));
		return -1;
	}

	if (pcap_setfilter(l2->pcap, &pcap_fp) < 0) {
		fprintf(stderr, "pcap_setfilter: %s\n", pcap_geterr(l2->pcap));
		return -1;
	}

	pcap_freecode(&pcap_fp);
#ifndef __sun__
	/*
	 * When libpcap uses BPF we must enable "immediate mode" to
	 * receive frames right away; otherwise the system may
	 * buffer them for us.
	 */
	{
		unsigned int on = 1;
		if (ioctl(pcap_fileno(l2->pcap), BIOCIMMEDIATE, &on) < 0) {
			fprintf(stderr, "%s: cannot enable immediate mode on "
				"interface %s: %s\n",
				__func__, l2->ifname, strerror(errno));
			/* XXX should we fail? */
		}
	}
#endif /* __sun__ */

	eloop_register_read_sock(pcap_get_selectable_fd(l2->pcap),
				 l2_packet_receive, l2, l2->pcap);

	return 0;
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:60,代码来源:l2_packet.c

示例5: HpingRecvCloseHandler

static struct recv_handler *HpingRecvGetHandler(struct recv_handler *ra, int len, char *ifname, Tcl_Interp *interp)
{
	int i;
	#if (!defined OSTYPE_LINUX) && (!defined __sun__)
	int on = 1;
	#endif

	for (i = 0; i < len; i++) {
		if (!ra[i].rh_ifname[0])
			break;
		if (!strcmp(ra[i].rh_ifname, ifname))
			return ra+i;
	}
	/* Not found, need to open it */
	if (i == len) {
		/* XXX: with hping setfilter this is broken */
		/* All the slots are full, make space at the end */
		HpingRecvCloseHandler(ra+(len-1));
		i--;
	}
	/* Open a new handler */
	ra[i].rh_pcapfp = pcap_open_live(ifname, 99999, 0, 1, ra[i].rh_pcap_errbuf);
	if (ra[i].rh_pcapfp == NULL)
		return NULL;
	#if (!defined OSTYPE_LINUX) && (!defined __sun__)
	/* Return the packets to userspace as fast as possible */
	if (ioctl(pcap_fileno(ra[i].rh_pcapfp), BIOCIMMEDIATE, &on) == -1) {
		/* XXX non-critical error */
	}
	#endif
	strlcpy(ra[i].rh_ifname, ifname, HPING_IFNAME_LEN);
	ra[i].rh_interp = NULL;
	ra[i].rh_linkhdrsize = dltype_to_lhs(pcap_datalink(ra[i].rh_pcapfp));
	return ra+i;
}
开发者ID:savagejen,项目名称:hping,代码行数:35,代码来源:script.c

示例6: p_fileno

static PyObject * p_fileno (PyObject *self, PyObject *args)
{
  pcap_t * ppcap;
  if (!PyArg_ParseTuple(args, "l", (long int*)&ppcap)) return NULL;
  int rv = pcap_fileno(ppcap);
  return Py_BuildValue("i", rv);
}
开发者ID:14gr1010,项目名称:software,代码行数:7,代码来源:pxpcap.cpp

示例7: pcap_setdirection

/* Open an Ethernet interface using PCAP */
static pcap_t *nio_ethernet_open(char *device)
{
   char pcap_errbuf[PCAP_ERRBUF_SIZE];
   pcap_t *p;

#ifndef CYGWIN
   /* Timeout is 10ms */
   if (!(p = pcap_open_live(device, 65535, TRUE, 10, pcap_errbuf)))
      goto pcap_error;

   pcap_setdirection(p, PCAP_D_INOUT);
#ifdef BIOCFEEDBACK
   {
     int on = 1;
     ioctl(pcap_fileno(p), BIOCFEEDBACK, &on);
   }
#endif
#else
   p = pcap_open(device, 65535,
       PCAP_OPENFLAG_PROMISCUOUS |
       PCAP_OPENFLAG_NOCAPTURE_LOCAL |
	   PCAP_OPENFLAG_MAX_RESPONSIVENESS |
	   PCAP_OPENFLAG_NOCAPTURE_RPCAP,
	   10, NULL, pcap_errbuf);

   if (!p)
      goto pcap_error;
#endif

   return p;

 pcap_error:
   fprintf(stderr, "nio_ethernet_open: unable to open device '%s' ""with PCAP (%s)\n", device, pcap_errbuf);
   return NULL;
}
开发者ID:gcetusic,项目名称:ubridge,代码行数:36,代码来源:nio_ethernet.c

示例8: pcap_open

pcap_t *
pcap_open(char *device)
{
	char ebuf[PCAP_ERRBUF_SIZE];
	pcap_t *pcap;
	
	if (device == NULL) {
		if ((device = pcap_lookupdev(ebuf)) == NULL)
			return (NULL);
	}
	if ((pcap = pcap_open_live(device, 31337, 0, 10, ebuf)) == NULL)
		return (NULL);
	
#ifdef BSD
	{
		int n = 1;

		if (ioctl(pcap_fileno(pcap), BIOCIMMEDIATE, &n) < 0) {
			pcap_close(pcap);
			return (NULL);
		}
	}
#endif
	return (pcap);
}
开发者ID:ajkeeton,项目名称:fragroute,代码行数:25,代码来源:pcaputil.c

示例9: add_device

static void
add_device(orchids_t *ctx, mod_entry_t *mod, config_directive_t *dir)
{

  /*  dev: the network device to open
      capd: a packet capture descriptor
   */

  int fd;
  char* dev;
  char errbuf[PCAP_ERRBUF_SIZE]="";
  pcap_t* capd = NULL;

  dev = dir->args;
  DebugLog(DF_MOD, DS_INFO, "Add 802.11 listen device %s\n", dev);

  capd = pcap_open_live(dev, 65535, 1, 1, errbuf);

  if ( strlen(errbuf) != 0 ) {
    DebugLog(DF_MOD, DS_ERROR, "pcap_open_live error: %s\n", errbuf);
    return;
  }

  pcap_setnonblock(capd, 1, NULL);
  fd = pcap_fileno(capd);
  datalink_type = pcap_datalink(capd);

  add_input_descriptor(ctx, mod, wifi_callback, fd, capd);
}
开发者ID:triplekill,项目名称:orchids,代码行数:29,代码来源:mod_wifi.c

示例10: capture

static mrb_value
capture(mrb_state *mrb, mrb_value self)
{
  struct capture_object *cap;
  int nfd;

  cap = (struct capture_object *)mrb_get_datatype(mrb, self, &mrb_pcap_type);
  cap->mrb = mrb;

  if (pcap_file(cap->pcap) != NULL) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "pcap file not supported");
  } else {
    int fd = pcap_fileno(cap->pcap);
    fd_set rset;

    FD_ZERO(&rset);
    do {
      FD_SET(fd, &rset);
      nfd = select(fd+1, &rset, NULL, NULL, NULL);
      if (nfd != 0) {
        pcap_dispatch(cap->pcap, 1, handler, (u_char *)cap);
        break;
      } else {
        continue;
      }
    } while (1);
  }

  return cap->cap_data;
}
开发者ID:selman,项目名称:mruby-pcap,代码行数:30,代码来源:pcap.c

示例11: regen_pfds

static u32 regen_pfds(struct pollfd* pfds, struct api_client** ctable) {
    u32 i, count = 2;

    pfds[0].fd     = pcap_fileno(pt);
    pfds[0].events = (POLLIN | POLLERR | POLLHUP);

    DEBUG("[#] Recomputing pollfd data, pcap_fd = %d.\n", pfds[0].fd);

    if (!api_sock) return 1;

    pfds[1].fd     = api_fd;
    pfds[1].events = (POLLIN | POLLERR | POLLHUP);

    for (i = 0; i < api_max_conn; i++) {

        if (api_cl[i].fd == -1) continue;

        ctable[count] = api_cl + i;

        /* If we haven't received a complete query yet, wait for POLLIN.
           Otherwise, we want to write stuff. */

        if (api_cl[i].in_off < sizeof(struct p0f_api_query))
            pfds[count].events = (POLLIN | POLLERR | POLLHUP);
        else
            pfds[count].events = (POLLOUT | POLLERR | POLLHUP);

        pfds[count++].fd   = api_cl[i].fd;

    }

    return count;

}
开发者ID:vivekchand,项目名称:p0fPythonWrapper,代码行数:34,代码来源:p0fmod.c

示例12: parse_dhcp_replies

static int parse_dhcp_replies(pcap_t *pc, int max_timeout, uint32_t dhcp_xid)
{
	struct pcap_pkthdr pc_hdr;
	fd_set read_set;
	int status, pcap_fd, timed_out;
	struct timeval timeout;
	uint8_t *packet;
	struct libnet_ethernet_hdr *eth_hdr;
	struct libnet_ipv4_hdr *ip_hdr;
	struct libnet_udp_hdr *udp_hdr;
	struct libnet_dhcpv4_hdr *dhcp_hdr;

	timeout.tv_sec = max_timeout;
	timeout.tv_usec = 0;
	pcap_fd = pcap_fileno(pc);
	FD_ZERO(&read_set);
	FD_SET(pcap_fd, &read_set);

	for (timed_out = 0; !timed_out;) {
		status = select(pcap_fd + 1, &read_set, 0, 0, &timeout);
		switch (status) {
		case -1:
			fprintf(stderr, "select() %s\n", strerror(errno));
			exit(EXIT_FAILURE);

		case 0:
			timed_out = 1;
			continue;

		default:
			if (FD_ISSET(pcap_fd, &read_set) == 0) {
				timed_out = 1;
				continue;
			}
		}
		packet = (uint8_t *) pcap_next(pc, &pc_hdr);
		if (packet == NULL) {
			continue;
		}
		eth_hdr = (struct libnet_ethernet_hdr *)(packet);
		ip_hdr = (struct libnet_ipv4_hdr *)(packet +
			sizeof(struct libnet_ethernet_hdr));
		udp_hdr = (struct libnet_udp_hdr *)(packet +
			sizeof(struct libnet_ethernet_hdr) +
			sizeof(struct libnet_ipv4_hdr));
		dhcp_hdr = (struct libnet_dhcpv4_hdr *)(packet +
			sizeof(struct libnet_ethernet_hdr) +
			sizeof(struct libnet_ipv4_hdr) +
			sizeof(struct libnet_udp_hdr));

		if (ntohl(dhcp_hdr->dhcp_xid) != dhcp_xid) {
			continue;
		}

		printf("\n");

		dump_dhcp_packet(dhcp_hdr);
	}
}
开发者ID:saxofon,项目名称:dhcp-discover,代码行数:59,代码来源:dhcp-discover.c

示例13: setup_packet_capture

/*
 * Open either interface specified by "dev" or pcap file specified by
 * "capfile". Optionally apply filter "bpf_prog"
 */
static void
  setup_packet_capture(struct pcap **pcap, char *dev,
		       char *capfile, char *bpf_prog)
{
   char ebuf[PCAP_ERRBUF_SIZE];
   struct bpf_program prog_c;

	/* Open pcap */
   if (dev != NULL)
     {
	if ((*pcap = pcap_open_live(dev, LIBPCAP_SNAPLEN,
				    1, 0, ebuf)) == NULL)
	  {
	     fprintf(stderr, "pcap_open_live: %s\n", ebuf);
	     exit(1);
	  }
     }
   else
     {
	if ((*pcap = pcap_open_offline(capfile, ebuf)) == NULL)
	  {
	     fprintf(stderr, "pcap_open_offline(%s): %s\n",
		     capfile, ebuf);
	     exit(1);
	  }
     }
	/* XXX - check datalink */
	/* Attach BPF filter, if specified */
   if (bpf_prog != NULL)
     {
	if (pcap_compile(*pcap, &prog_c, bpf_prog, 1, 0) == -1)
	  {
	     fprintf(stderr, "pcap_compile(\"%s\"): %s\n",
		     bpf_prog, pcap_geterr(*pcap));
	     exit(1);
	  }
	if (pcap_setfilter(*pcap, &prog_c) == -1)
	  {
	     fprintf(stderr, "pcap_setfilter: %s\n",
		     pcap_geterr(*pcap));
	     exit(1);
	  }
     }
#ifdef BIOCLOCK
	/*
	 * If we are reading from an device (not a file), then
	 * lock the underlying BPF device to prevent changes in the
	 * unprivileged child
	 */
   if (dev != NULL && ioctl(pcap_fileno(*pcap), BIOCLOCK) < 0)
     {
	fprintf(stderr, "ioctl(BIOCLOCK) failed: %s\n",
		strerror(errno));
	exit(1);
     }
#endif
}
开发者ID:Klaws--,项目名称:pfsense-tools,代码行数:61,代码来源:pfflowd.c

示例14: arpd_init

static void
arpd_init(char *dev, int naddresses, char **addresses)
{
	struct bpf_program fcode;
	char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst;
	intf_t *intf;
	
	dst = arpd_expandips(naddresses, addresses);

	if ((arpd_arp = arp_open()) == NULL)
		err(1, "arp_open");

	if ((intf = intf_open()) == NULL)
		err(1, "intf_open");

	if (dev == NULL) {
		if ((dev = pcap_lookupdev(ebuf)) == NULL)
			errx(1, "pcap_lookupdev: %s", ebuf);
	}
	arpd_ifent.intf_len = sizeof(arpd_ifent);
	strncpy(arpd_ifent.intf_name, dev, sizeof(arpd_ifent.intf_name) - 1);
	arpd_ifent.intf_name[sizeof(arpd_ifent.intf_name) - 1] = '\0';
	
	if (intf_get(intf, &arpd_ifent) < 0)
		err(1, "intf_get");

	if (arpd_ifent.intf_addr.addr_type != ADDR_TYPE_IP ||
	    arpd_ifent.intf_link_addr.addr_type != ADDR_TYPE_ETH)
		errx(1, "bad interface configuration: not IP or Ethernet");
	arpd_ifent.intf_addr.addr_bits = IP_ADDR_BITS;
	
	snprintf(filter, sizeof(filter), "arp %s%s%s and not ether src %s",
	    dst ? "and (" : "", dst ? dst : "", dst ? ")" : "",
	    addr_ntoa(&arpd_ifent.intf_link_addr));
	
	if ((arpd_pcap = pcap_open_live(dev, 128, 0, 500, ebuf)) == NULL)
		errx(1, "pcap_open_live: %s", ebuf);
	
	if (pcap_compile(arpd_pcap, &fcode, filter, 1, 0) < 0 ||
	    pcap_setfilter(arpd_pcap, &fcode) < 0)
		errx(1, "bad pcap filter: %s", pcap_geterr(arpd_pcap));
#if defined(BSD) && defined(BIOCIMMEDIATE)
	{
		int on = 1;
		if (ioctl(pcap_fileno(arpd_pcap), BIOCIMMEDIATE, &on) < 0)
			err(1, "BIOCIMMEDIATE");
	}
#endif
	if ((arpd_eth = eth_open(dev)) == NULL)
		errx(1, "eth_open");

#ifndef LOG_PERROR
#define LOG_PERROR	0
#endif
	openlog("arpd", LOG_PERROR|LOG_PID|LOG_CONS, LOG_DAEMON);
	syslog(LOG_INFO, "listening on %s: %s", dev, filter);
}
开发者ID:MagicalTux,项目名称:farpd,代码行数:57,代码来源:arpd.c

示例15: pcap_ex_immediate

int pcap_ex_immediate(pcap_t *pcap)
{
#ifdef BIOCIMMEDIATE
	int n = 1;

	return ioctl(pcap_fileno(pcap), BIOCIMMEDIATE, &n);
#else
	return (0);
#endif
}
开发者ID:ChristosKon,项目名称:honeyd-ipv6,代码行数:10,代码来源:pcap_ex.c


注:本文中的pcap_fileno函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。