亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? pcap-linux.c

?? 用來監(jiān)視網(wǎng)絡(luò)通信數(shù)據(jù)的源代碼和應(yīng)用程序,方便網(wǎng)絡(luò)程序底層開發(fā).
?? C
?? 第 1 頁 / 共 5 頁
字號(hào):
		 *
		 * We count them here even if we can get the packet count
		 * from the kernel, as we can only determine at run time
		 * whether we'll be able to get it from the kernel (if
		 * HAVE_TPACKET_STATS isn't defined, we can't get it from
		 * the kernel, but if it is defined, the library might
		 * have been built with a 2.4 or later kernel, but we
		 * might be running on a 2.2[.x] kernel without Alexey
		 * Kuznetzov's turbopacket patches, and thus the kernel
		 * might not be able to supply those statistics).  We
		 * could, I guess, try, when opening the socket, to get
		 * the statistics, and if we can not increment the count
		 * here, but it's not clear that always incrementing
		 * the count is more expensive than always testing a flag
		 * in memory.
		 */
		handle->md.stat.ps_recv++;

		(*pkt_data)= bp;
		(*pkt_header)= &(handle->pcap_header);

		return 1;

	}	
	else
	{
		/* We are on an offline capture */
		struct bpf_insn *fcode = handle->fcode.bf_insns;
		int status;
		int n = 0;
		
		while (1)
		{
			status = sf_next_packet(handle, &handle->pcap_header, handle->buffer, handle->bufsize);
			if (status==1)
				/* EOF */
				return (-2);
			if (status==-1)
				/* Error */
				return (-1);
			
			if (fcode == NULL ||
				bpf_filter(fcode, handle->buffer, handle->pcap_header.len, handle->pcap_header.caplen)) 
			{
				*pkt_header = &handle->pcap_header;
				*pkt_data = handle->buffer;
				return (1);
			}			
			
		}
	}
}
#endif	/* HAVE_PCAPREADEX */



/*
 *  Get the statistics for the given packet capture handle.
 *  Reports the number of dropped packets iff the kernel supports
 *  the PACKET_STATISTICS "getsockopt()" argument (2.4 and later
 *  kernels, and 2.2[.x] kernels with Alexey Kuznetzov's turbopacket
 *  patches); otherwise, that information isn't available, and we lie
 *  and report 0 as the count of dropped packets.
 */
int
pcap_stats(pcap_t *handle, struct pcap_stat *stats)
{
#ifdef HAVE_TPACKET_STATS
	struct tpacket_stats kstats;
	socklen_t len = sizeof (struct tpacket_stats);
#endif


#ifdef REMOTE
	if (handle->rmt_clientside)
	{
		/* We are on an remote capture */
		return pcap_stats_remote(handle, stats);
	}
#endif


#ifdef HAVE_TPACKET_STATS
	/*
	 * Try to get the packet counts from the kernel.
	 */
	if (getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS,
			&kstats, &len) > -1) {
		/*
		 * In "linux/net/packet/af_packet.c", at least in the
		 * 2.4.9 kernel, "tp_packets" is incremented for every
		 * packet that passes the packet filter *and* is
		 * successfully queued on the socket; "tp_drops" is
		 * incremented for every packet dropped because there's
		 * not enough free space in the socket buffer.
		 *
		 * When the statistics are returned for a PACKET_STATISTICS
		 * "getsockopt()" call, "tp_drops" is added to "tp_packets",
		 * so that "tp_packets" counts all packets handed to
		 * the PF_PACKET socket, including packets dropped because
		 * there wasn't room on the socket buffer - but not
		 * including packets that didn't pass the filter.
		 *
		 * In the BSD BPF, the count of received packets is
		 * incremented for every packet handed to BPF, regardless
		 * of whether it passed the filter.
		 *
		 * We can't make "pcap_stats()" work the same on both
		 * platforms, but the best approximation is to return
		 * "tp_packets" as the count of packets and "tp_drops"
		 * as the count of drops.
		 */
		handle->md.stat.ps_recv = kstats.tp_packets;
		handle->md.stat.ps_drop = kstats.tp_drops;
	}
	else
	{
		/*
		 * If the error was EOPNOTSUPP, fall through, so that
		 * if you build the library on a system with
		 * "struct tpacket_stats" and run it on a system
		 * that doesn't, it works as it does if the library
		 * is built on a system without "struct tpacket_stats".
		 */
		if (errno != EOPNOTSUPP) {
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
			    "pcap_stats: %s", pcap_strerror(errno));
			return -1;
		}
	}
#endif
	/*
	 * On systems where the PACKET_STATISTICS "getsockopt()" argument
	 * is supported on PF_PACKET sockets:
	 *
	 *	"ps_recv" counts only packets that *passed* the filter,
	 *	not packets that didn't pass the filter.  This includes
	 *	packets later dropped because we ran out of buffer space.
	 *
	 *	"ps_drop" counts packets dropped because we ran out of
	 *	buffer space.  It doesn't count packets dropped by the
	 *	interface driver.  It counts only packets that passed
	 *	the filter.
	 *
	 *	Both statistics include packets not yet read from the
	 *	kernel by libpcap, and thus not yet seen by the application.
	 *
	 * On systems where the PACKET_STATISTICS "getsockopt()" argument
	 * is not supported on PF_PACKET sockets:
	 *
	 *	"ps_recv" counts only packets that *passed* the filter,
	 *	not packets that didn't pass the filter.  It does not
	 *	count packets dropped because we ran out of buffer
	 *	space.
	 *
	 *	"ps_drop" is not supported.
	 *
	 *	"ps_recv" doesn't include packets not yet read from
	 *	the kernel by libpcap.
	 */
	*stats = handle->md.stat;
	return 0;
}

/*
 * Description string for the "any" device.
 */
static const char any_descr[] = "Pseudo-device that captures on all interfaces";

int
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
{
	if (pcap_add_if(alldevsp, "any", 0, any_descr, errbuf) < 0)
		return (-1);

	return (0);
}

/*
 *  Attach the given BPF code to the packet capture device.
 */
int
pcap_setfilter(pcap_t *handle, struct bpf_program *filter)
{
#ifdef SO_ATTACH_FILTER
	struct sock_fprog	fcode;
	int			can_filter_in_kernel;
	int			err = 0;
#endif

	if (!handle)
		return -1;
	if (!filter) {
	        strncpy(handle->errbuf, "setfilter: No filter specified",
			sizeof(handle->errbuf));
		return -1;
	}

#ifdef REMOTE
	if (handle->rmt_clientside)
	{
		/* We are on an remote capture */
		return pcap_setfilter_remote(handle, filter);
	}
#endif

	/* Make our private copy of the filter */

	if (install_bpf_program(handle, filter) < 0)
		/* install_bpf_program() filled in errbuf */
		return -1;

	/*
	 * Run user level packet filter by default. Will be overriden if
	 * installing a kernel filter succeeds.
	 */
	handle->md.use_bpf = 0;

	/*
	 * If we're reading from a savefile, don't try to install
	 * a kernel filter.
	 */
	if (handle->sf.rfile != NULL)
		return 0;

	/* Install kernel level filter if possible */

#ifdef SO_ATTACH_FILTER
#ifdef USHRT_MAX
	if (handle->fcode.bf_len > USHRT_MAX) {
		/*
		 * fcode.len is an unsigned short for current kernel.
		 * I have yet to see BPF-Code with that much
		 * instructions but still it is possible. So for the
		 * sake of correctness I added this check.
		 */
		fprintf(stderr, "Warning: Filter too complex for kernel\n");
		fcode.filter = NULL;
		can_filter_in_kernel = 0;
	} else
#endif /* USHRT_MAX */
	{
		/*
		 * Oh joy, the Linux kernel uses struct sock_fprog instead
		 * of struct bpf_program and of course the length field is
		 * of different size. Pointed out by Sebastian
		 *
		 * Oh, and we also need to fix it up so that all "ret"
		 * instructions with non-zero operands have 65535 as the
		 * operand, and so that, if we're in cooked mode, all
		 * memory-reference instructions use special magic offsets
		 * in references to the link-layer header and assume that
		 * the link-layer payload begins at 0; "fix_program()"
		 * will do that.
		 */
		switch (fix_program(handle, &fcode)) {

		case -1:
		default:
			/*
			 * Fatal error; just quit.
			 * (The "default" case shouldn't happen; we
			 * return -1 for that reason.)
			 */
			return -1;

		case 0:
			/*
			 * The program performed checks that we can't make
			 * work in the kernel.
			 */
			can_filter_in_kernel = 0;
			break;

		case 1:
			/*
			 * We have a filter that'll work in the kernel.
			 */
			can_filter_in_kernel = 1;
			break;
		}
	}

	if (can_filter_in_kernel) {
		if ((err = set_kernel_filter(handle, &fcode)) == 0)
		{
			/* Installation succeded - using kernel filter. */
			handle->md.use_bpf = 1;
		}
		else if (err == -1)	/* Non-fatal error */
		{
			/*
			 * Print a warning if we weren't able to install
			 * the filter for a reason other than "this kernel
			 * isn't configured to support socket filters.
			 */
			if (errno != ENOPROTOOPT && errno != EOPNOTSUPP) {
				fprintf(stderr,
				    "Warning: Kernel filter failed: %s\n",
					pcap_strerror(errno));
			}
		}
	}

	/*
	 * If we're not using the kernel filter, get rid of any kernel
	 * filter that might've been there before, e.g. because the
	 * previous filter could work in the kernel, or because some other
	 * code attached a filter to the socket by some means other than
	 * calling "pcap_setfilter()".  Otherwise, the kernel filter may
	 * filter out packets that would pass the new userland filter.
	 */
	if (!handle->md.use_bpf)
		reset_kernel_filter(handle);

	/*
	 * Free up the copy of the filter that was made by "fix_program()".
	 */
	if (fcode.filter != NULL)
		free(fcode.filter);

	if (err == -2)
		/* Fatal error */
		return -1;
#endif /* SO_ATTACH_FILTER */

	return 0;
}

/*
 *  Linux uses the ARP hardware type to identify the type of an
 *  interface. pcap uses the DLT_xxx constants for this. This
 *  function takes a pointer to a "pcap_t", and an ARPHRD_xxx
 *  constant, as arguments, and sets "handle->linktype" to the
 *  appropriate DLT_XXX constant and sets "handle->offset" to
 *  the appropriate value (to make "handle->offset" plus link-layer
 *  header length be a multiple of 4, so that the link-layer payload
 *  will be aligned on a 4-byte boundary when capturing packets).
 *  (If the offset isn't set here, it'll be 0; add code as appropriate
 *  for cases where it shouldn't be 0.)
 *
 *  If "cooked_ok" is non-zero, we can use DLT_LINUX_SLL and capture
 *  in cooked mode; otherwise, we can't use cooked mode, so we have
 *  to pick some type that works in raw mode, or fail.
 *
 *  Sets the link type to -1 if unable to map the type.
 */
static void map_arphrd_to_dlt(pcap_t *handle, int arptype, int cooked_ok)
{
	switch (arptype) {

	case ARPHRD_ETHER:
	case ARPHRD_METRICOM:
	case ARPHRD_LOOPBACK:
		handle->linktype = DLT_EN10MB;
		handle->offset = 2;
		break;

	case ARPHRD_EETHER:
		handle->linktype = DLT_EN3MB;
		break;

	case ARPHRD_AX25:
		handle->linktype = DLT_AX25;
		break;

	case ARPHRD_PRONET:
		handle->linktype = DLT_PRONET;
		break;

	case ARPHRD_CHAOS:
		handle->linktype = DLT_CHAOS;
		break;

#ifndef ARPHRD_IEEE802_TR
#define ARPHRD_IEEE802_TR 800	/* From Linux 2.4 */
#endif
	case ARPHRD_IEEE802_TR:
	case ARPHRD_IEEE802:
		handle->linktype = DLT_IEEE802;
		handle->offset = 2;
		break;

	case ARPHRD_ARCNET:
		handle->linktype = DLT_ARCNET_LINUX;
		break;

#ifndef ARPHRD_FDDI	/* From Linux 2.2.13 */
#define ARPHRD_FDDI	774
#endif
	case ARPHRD_FDDI:
		handle->linktype = DLT_FDDI;
		handle->offset = 3;
		break;

#ifndef ARPHRD_ATM  /* FIXME: How to #include this? */
#define ARPHRD_ATM 19
#endif
	case ARPHRD_ATM:
		/*
		 * The Classical IP implementation in ATM for Linux
		 * supports both what RFC 1483 calls "LLC Encapsulation",
		 * in which each packet has an LLC header, possibly
		 * with a SNAP header as well, prepended to it, and
		 * what RFC 1483 calls "VC Based Multiplexing", in which
		 * different virtual circuits carry different network
		 * layer protocols, and no header is prepended to packets.
		 *
		 * They both have an ARPHRD_ type of ARPHRD_ATM, so
		 * you can't use the ARPHRD_ type to find out whether
		 * captured packets will have an LLC header, and,
		 * while there's a socket ioctl to *set* the encapsulation
		 * type, there's no ioctl to *get* the encapsulation type.
		 *
		 * This means that
		 *
		 *	programs that dissect Linux Classical IP frames
		 *	would have to check for an LLC header and,
		 *	depending on whether they see one or not, dissect
		 *	the frame as LLC-encapsulated or as raw IP (I
		 *	don't know whether there's any traffic other than
		 *	IP that would show up on the socket, or whether
		 *	there's any support for IPv6 in the Linux
		 *	Classical IP code);
		 *
		 *	filter expressions would have to compile into
		 *	code that checks for an LLC header and does
		 *	the right thing.
		 *
		 * Both of those are a nuisance - and, at least on systems
		 * that support PF_PACKET sockets, we don't have to put
		 * up with those nuisances; instead, we can just capture
		 * in cooked mode.  That's what we'll do, if we can.
		 * Otherwise, we'll just fail.
		 */
		if (cooked_ok)
			handle->linktype = DLT_LINUX_SLL;
		else
			handle->linktype = -1;
		break;

#ifndef ARPHRD_IEEE80211  /* From Linux 2.4.6 */
#define ARPHRD_IEEE80211 801
#endif
	case ARPHRD_IEEE80211:
		handle->linktype = DLT_IEEE802_11;
		break;

#ifndef ARPHRD_IEEE80211_PRISM  /* From Linux 2.4.18 */
#define ARPHRD_IEEE80211_PRISM 802
#endif
	case ARPHRD_IEEE80211_PRISM:
		handle->linktype = DLT_PRISM_HEADER;
		break;

	case ARPHRD_PPP:
		/*

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产午夜精品久久久久久久| 秋霞影院一区二区| 国产在线国偷精品免费看| 欧美一区二区视频在线观看2022 | 欧美高清在线视频| 国产激情91久久精品导航| 久久精品视频一区二区| 欧美日韩视频在线一区二区| 日本一区中文字幕| 精品美女一区二区三区| 韩国理伦片一区二区三区在线播放| 国产婷婷精品av在线| 欧美精选一区二区| 国产激情视频一区二区在线观看| 亚洲午夜久久久久久久久电影网| 欧美区一区二区三区| 精品午夜一区二区三区在线观看| 久久久美女毛片| 一本到不卡精品视频在线观看| 亚洲不卡一区二区三区| 久久综合九色综合欧美就去吻| 岛国精品在线播放| 99精品热视频| 亚洲欧美韩国综合色| 欧美福利视频导航| 91黄色免费看| 国产精品白丝jk黑袜喷水| 一二三区精品福利视频| 日韩欧美色电影| 91欧美激情一区二区三区成人| 日本伊人精品一区二区三区观看方式| 亚洲精品日韩综合观看成人91| 91精品国产欧美日韩| 欧美日韩在线一区二区| 欧美日韩午夜在线| 欧美三级蜜桃2在线观看| 色狠狠桃花综合| 色婷婷av一区二区三区软件| 色乱码一区二区三区88| 一本色道**综合亚洲精品蜜桃冫| 91免费在线看| 欧洲av在线精品| 国产成人精品免费看| 国产成人av资源| 福利一区二区在线观看| 蜜臀a∨国产成人精品| 亚洲男人的天堂在线观看| 18成人在线观看| 国产三级精品在线| 欧美丰满嫩嫩电影| 91精品福利在线一区二区三区| 666欧美在线视频| 91麻豆自制传媒国产之光| 一本大道久久a久久精品综合| 91小视频在线| 欧美日韩在线免费视频| 亚洲蜜臀av乱码久久精品蜜桃| 日韩美女精品在线| 久久精品夜色噜噜亚洲aⅴ| 国产欧美精品一区二区三区四区| 国产精品美女久久久久aⅴ| 久久一区二区三区国产精品| 欧美国产精品一区| 亚洲色图色小说| 午夜日韩在线电影| 亚洲激情在线播放| 日韩激情视频在线观看| 亚洲一区二区在线观看视频 | 一区二区三区在线视频观看58| 亚洲人成在线播放网站岛国| 亚洲午夜久久久久久久久电影院| 日本视频免费一区| 国产麻豆视频精品| 色先锋资源久久综合| 日韩一级大片在线观看| 欧美日韩精品是欧美日韩精品| 91精品婷婷国产综合久久性色 | 欧美一区二区三区日韩| 久久精品一区二区三区av| 亚洲视频精选在线| 麻豆国产精品777777在线| 成人国产精品免费观看视频| 国产成人av在线影院| 欧美这里有精品| 亚洲精品一线二线三线无人区| 精品欧美一区二区久久| 亚洲视频在线一区二区| 麻豆精品一二三| 色综合色综合色综合色综合色综合| 欧美精品在线观看播放| 国产精品午夜久久| 欧美麻豆精品久久久久久| 久久精品欧美一区二区三区麻豆 | 中文字幕第一页久久| 亚洲一区在线看| 成人综合婷婷国产精品久久| 欧美日韩一级视频| 亚洲欧洲日韩女同| 国产一区在线视频| 欧美精品亚洲一区二区在线播放| 国产精品色呦呦| 精品一区二区精品| 欧美日韩免费电影| 成人欧美一区二区三区黑人麻豆 | 91美女福利视频| 精品久久久久一区二区国产| 韩国女主播一区| 欧美电影一区二区三区| 26uuu亚洲| 日韩精品乱码免费| 色婷婷久久久亚洲一区二区三区| 日韩一区二区精品| 亚洲麻豆国产自偷在线| 国产一区美女在线| 日韩欧美亚洲国产精品字幕久久久| 一二三四区精品视频| 97成人超碰视| 欧美国产日韩在线观看| 狠狠色丁香婷综合久久| 日韩午夜小视频| 日韩国产欧美一区二区三区| 欧美日韩中文精品| 亚洲在线观看免费视频| 一本色道久久综合亚洲aⅴ蜜桃 | 国产亚洲综合色| 美美哒免费高清在线观看视频一区二区| 在线观看欧美黄色| 国产精品久久久久婷婷二区次| 一色桃子久久精品亚洲| 成人免费看片app下载| 国产视频一区二区在线观看| 国产在线精品一区二区三区不卡 | 久久久影院官网| 欧美a一区二区| 欧美一区二区三区不卡| 日本v片在线高清不卡在线观看| 欧美三级电影一区| 亚洲国产中文字幕在线视频综合| 日本国产一区二区| 亚洲国产精品人人做人人爽| 精品视频123区在线观看| 亚洲综合在线视频| 欧美手机在线视频| 国产精品网站在线| www.色综合.com| 精品国产1区2区3区| 久久国内精品自在自线400部| 色综合久久中文综合久久97| 亚洲免费观看高清完整版在线观看 | 欧美在线免费观看亚洲| 一区二区三区不卡在线观看| 在线亚洲免费视频| 视频一区国产视频| 日韩精品专区在线影院观看| 国产一区二区剧情av在线| 国产精品美女久久久久aⅴ| 99视频精品在线| 亚洲成人免费电影| 日韩视频一区在线观看| 国产成人免费av在线| 日韩美女精品在线| 日韩一区在线看| 欧美精品aⅴ在线视频| 极品少妇xxxx精品少妇偷拍 | 久久天天做天天爱综合色| 国产成人午夜精品影院观看视频| 亚洲欧美自拍偷拍色图| 欧美日韩一区二区不卡| 精品在线亚洲视频| 中文字幕一区二区三区精华液 | 欧美一级艳片视频免费观看| 国产一区二区三区四区五区入口 | 亚洲自拍偷拍欧美| 91精品国产综合久久香蕉麻豆| 极品美女销魂一区二区三区| 国产精品国产精品国产专区不片| 欧美三级三级三级| 国产成人综合自拍| 亚洲成a人片综合在线| 久久夜色精品国产欧美乱极品| 91网址在线看| 久久99国产精品成人| 中文字幕一区av| 日韩欧美中文字幕制服| 91在线一区二区三区| 毛片av中文字幕一区二区| 亚洲欧洲精品一区二区精品久久久| 欧美另类久久久品| 懂色av一区二区三区免费观看| 亚洲一区二区视频在线| 国产欧美一区二区三区在线老狼| 欧美午夜宅男影院| 成人美女视频在线观看| 免费视频最近日韩| 一区二区三区在线观看视频| 久久久久久9999| 91精品国产综合久久久蜜臀粉嫩| 99re视频这里只有精品| 激情六月婷婷久久| 日韩成人精品在线|