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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pcap-linux.c

?? 用來監視網絡通信數據的源代碼和應用程序,方便網絡程序底層開發.
?? C
?? 第 1 頁 / 共 5 頁
字號:
		 * Some PPP code in the kernel supplies no link-layer
		 * header whatsoever to PF_PACKET sockets; other PPP
		 * code supplies PPP link-layer headers ("syncppp.c");
		 * some PPP code might supply random link-layer
		 * headers (PPP over ISDN - there's code in Ethereal,
		 * for example, to cope with PPP-over-ISDN captures
		 * with which the Ethereal developers have had to cope,
		 * heuristically trying to determine which of the
		 * oddball link-layer headers particular packets have).
		 *
		 * As such, we just punt, and run all PPP interfaces
		 * in cooked mode, if we can; otherwise, we just treat
		 * it as DLT_RAW, for now - if somebody needs to capture,
		 * on a 2.0[.x] kernel, on PPP devices that supply a
		 * link-layer header, they'll have to add code here to
		 * map to the appropriate DLT_ type (possibly adding a
		 * new DLT_ type, if necessary).
		 */
		if (cooked_ok)
			handle->linktype = DLT_LINUX_SLL;
		else {
			/*
			 * XXX - handle ISDN types here?  We can't fall
			 * back on cooked sockets, so we'd have to
			 * figure out from the device name what type of
			 * link-layer encapsulation it's using, and map
			 * that to an appropriate DLT_ value, meaning
			 * we'd map "isdnN" devices to DLT_RAW (they
			 * supply raw IP packets with no link-layer
			 * header) and "isdY" devices to a new DLT_I4L_IP
			 * type that has only an Ethernet packet type as
			 * a link-layer header.
			 *
			 * But sometimes we seem to get random crap
			 * in the link-layer header when capturing on
			 * ISDN devices....
			 */
			handle->linktype = DLT_RAW;
		}
		break;

#ifndef ARPHRD_HDLC
#define ARPHRD_HDLC 513	/* From Linux 2.2.13 */
#endif
	case ARPHRD_HDLC:
		handle->linktype = DLT_C_HDLC;
		break;

	/* Not sure if this is correct for all tunnels, but it
	 * works for CIPE */
	case ARPHRD_TUNNEL:
#ifndef ARPHRD_SIT
#define ARPHRD_SIT 776	/* From Linux 2.2.13 */
#endif
	case ARPHRD_SIT:
	case ARPHRD_CSLIP:
	case ARPHRD_SLIP6:
	case ARPHRD_CSLIP6:
	case ARPHRD_ADAPT:
	case ARPHRD_SLIP:
#ifndef ARPHRD_RAWHDLC
#define ARPHRD_RAWHDLC 518
#endif
	case ARPHRD_RAWHDLC:
		/*
		 * XXX - should some of those be mapped to DLT_LINUX_SLL
		 * instead?  Should we just map all of them to DLT_LINUX_SLL?
		 */
		handle->linktype = DLT_RAW;
		break;

	case ARPHRD_LOCALTLK:
		handle->linktype = DLT_LTALK;
		break;

#ifndef ARPHRD_FCPP
#define ARPHRD_FCPP	784
#endif
	case ARPHRD_FCPP:
#ifndef ARPHRD_FCAL
#define ARPHRD_FCAL	785
#endif
	case ARPHRD_FCAL:
#ifndef ARPHRD_FCPL
#define ARPHRD_FCPL	786
#endif
	case ARPHRD_FCPL:
#ifndef ARPHRD_FCFABRIC
#define ARPHRD_FCFABRIC	787
#endif
	case ARPHRD_FCFABRIC:
		/*
		 * We assume that those all mean RFC 2625 IP-over-
		 * Fibre Channel, with the RFC 2625 header at
		 * the beginning of the packet.
		 */
		handle->linktype = DLT_IP_OVER_FC;
		break;

	default:
		handle->linktype = -1;
		break;
	}
}

/* ===== Functions to interface to the newer kernels ================== */

/*
 *  Try to open a packet socket using the new kernel interface.
 *  Returns 0 on failure.
 *  FIXME: 0 uses to mean success (Sebastian)
 */
static int
live_open_new(pcap_t *handle, const char *device, int promisc,
	      int to_ms, char *ebuf)
{
#ifdef HAVE_PF_PACKET_SOCKETS
	int			sock_fd = -1, device_id, arptype;
	int			err;
	int			fatal_err = 0;
	struct packet_mreq	mr;

	/* One shot loop used for error handling - bail out with break */

	do {
		/*
		 * Open a socket with protocol family packet. If a device is
		 * given we try to open it in raw mode otherwise we use
		 * the cooked interface.
		 */
		sock_fd = device ?
			socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
		      : socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL));

		if (sock_fd == -1) {
			snprintf(ebuf, PCAP_ERRBUF_SIZE, "socket: %s",
				 pcap_strerror(errno) );
			break;
		}

		/* It seems the kernel supports the new interface. */
		handle->md.sock_packet = 0;

		/*
		 * Get the interface index of the loopback device.
		 * If the attempt fails, don't fail, just set the
		 * "md.lo_ifindex" to -1.
		 *
		 * XXX - can there be more than one device that loops
		 * packets back, i.e. devices other than "lo"?  If so,
		 * we'd need to find them all, and have an array of
		 * indices for them, and check all of them in
		 * "pcap_read_packet()".
		 */
		handle->md.lo_ifindex = iface_get_id(sock_fd, "lo", ebuf);

		/*
		 * Default value for offset to align link-layer payload
		 * on a 4-byte boundary.
		 */
		handle->offset	 = 0;

		/*
		 * What kind of frames do we have to deal with? Fall back
		 * to cooked mode if we have an unknown interface type.
		 */

		if (device) {
			/* Assume for now we don't need cooked mode. */
			handle->md.cooked = 0;

			arptype	= iface_get_arptype(sock_fd, device, ebuf);
			if (arptype == -1) {
				fatal_err = 1;
				break;
			}
			map_arphrd_to_dlt(handle, arptype, 1);
			if (handle->linktype == -1 ||
			    handle->linktype == DLT_LINUX_SLL ||
			    (handle->linktype == DLT_EN10MB &&
			     (strncmp("isdn", device, 4) == 0 ||
			      strncmp("isdY", device, 4) == 0))) {
				/*
				 * Unknown interface type (-1), or a
				 * device we explicitly chose to run
				 * in cooked mode (e.g., PPP devices),
				 * or an ISDN device (whose link-layer
				 * type we can only determine by using
				 * APIs that may be different on different
				 * kernels) - reopen in cooked mode.
				 */
				if (close(sock_fd) == -1) {
					snprintf(ebuf, PCAP_ERRBUF_SIZE,
						 "close: %s", pcap_strerror(errno));
					break;
				}
				sock_fd = socket(PF_PACKET, SOCK_DGRAM,
						 htons(ETH_P_ALL));
				if (sock_fd == -1) {
					snprintf(ebuf, PCAP_ERRBUF_SIZE,
						 "socket: %s", pcap_strerror(errno));
					break;
				}
				handle->md.cooked = 1;

				if (handle->linktype == -1) {
					/*
					 * Warn that we're falling back on
					 * cooked mode; we may want to
					 * update "map_arphrd_to_dlt()"
					 * to handle the new type.
					 */
					snprintf(ebuf, PCAP_ERRBUF_SIZE,
						"arptype %d not "
						"supported by libpcap - "
						"falling back to cooked "
						"socket",
						arptype);
				}
				handle->linktype = DLT_LINUX_SLL;
			}

			device_id = iface_get_id(sock_fd, device, ebuf);
			if (device_id == -1)
				break;

			if ((err = iface_bind(sock_fd, device_id, ebuf)) < 0) {
				if (err == -2)
					fatal_err = 1;
				break;
			}
		} else {
			/*
			 * This is cooked mode.
			 */
			handle->md.cooked = 1;
			handle->linktype = DLT_LINUX_SLL;

			/*
			 * XXX - squelch GCC complaints about
			 * uninitialized variables; if we can't
			 * select promiscuous mode on all interfaces,
			 * we should move the code below into the
			 * "if (device)" branch of the "if" and
			 * get rid of the next statement.
			 */
			device_id = -1;
		}

		/* Select promiscuous mode on/off */

		/*
		 * Hmm, how can we set promiscuous mode on all interfaces?
		 * I am not sure if that is possible at all.
		 */

		if (device) {
			memset(&mr, 0, sizeof(mr));
			mr.mr_ifindex = device_id;
			mr.mr_type    = promisc ?
				PACKET_MR_PROMISC : PACKET_MR_ALLMULTI;
			if (setsockopt(sock_fd, SOL_PACKET,
				PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == -1)
			{
				snprintf(ebuf, PCAP_ERRBUF_SIZE,
					"setsockopt: %s", pcap_strerror(errno));
				break;
			}
		}

		/* Save the socket FD in the pcap structure */

		handle->fd 	 = sock_fd;

		return 1;

	} while(0);

	if (sock_fd != -1)
		close(sock_fd);

	if (fatal_err)
		return -2;
	else
		return 0;
#else
	strncpy(ebuf,
		"New packet capturing interface not supported by build "
		"environment", PCAP_ERRBUF_SIZE);
	return 0;
#endif
}

#ifdef HAVE_PF_PACKET_SOCKETS
/*
 *  Return the index of the given device name. Fill ebuf and return
 *  -1 on failure.
 */
static int
iface_get_id(int fd, const char *device, char *ebuf)
{
	struct ifreq	ifr;

	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));

	if (ioctl(fd, SIOCGIFINDEX, &ifr) == -1) {
		snprintf(ebuf, PCAP_ERRBUF_SIZE,
			 "ioctl: %s", pcap_strerror(errno));
		return -1;
	}

	return ifr.ifr_ifindex;
}

/*
 *  Bind the socket associated with FD to the given device.
 */
static int
iface_bind(int fd, int ifindex, char *ebuf)
{
	struct sockaddr_ll	sll;
	int			err;
	socklen_t		errlen = sizeof(err);

	memset(&sll, 0, sizeof(sll));
	sll.sll_family		= AF_PACKET;
	sll.sll_ifindex		= ifindex;
	sll.sll_protocol	= htons(ETH_P_ALL);

	if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) == -1) {
		snprintf(ebuf, PCAP_ERRBUF_SIZE,
			 "bind: %s", pcap_strerror(errno));
		return -1;
	}

	/* Any pending errors, e.g., network is down? */

	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) {
		snprintf(ebuf, PCAP_ERRBUF_SIZE,
			"getsockopt: %s", pcap_strerror(errno));
		return -2;
	}

	if (err > 0) {
		snprintf(ebuf, PCAP_ERRBUF_SIZE,
			"bind: %s", pcap_strerror(err));
		return -2;
	}

	return 0;
}

#endif


/* ===== Functions to interface to the older kernels ================== */

/*
 * With older kernels promiscuous mode is kind of interesting because we
 * have to reset the interface before exiting. The problem can't really
 * be solved without some daemon taking care of managing usage counts.
 * If we put the interface into promiscuous mode, we set a flag indicating
 * that we must take it out of that mode when the interface is closed,
 * and, when closing the interface, if that flag is set we take it out
 * of promiscuous mode.
 */

/*
 * List of pcaps for which we turned promiscuous mode on by hand.
 * If there are any such pcaps, we arrange to call "pcap_close_all()"
 * when we exit, and have it close all of them to turn promiscuous mode
 * off.
 */
static struct pcap *pcaps_to_close;

/*
 * TRUE if we've already called "atexit()" to cause "pcap_close_all()" to
 * be called on exit.
 */
static int did_atexit;

static void	pcap_close_all(void)
{
	struct pcap *handle;

	while ((handle = pcaps_to_close) != NULL)
		pcap_close(handle);
}

void	pcap_close_linux( pcap_t *handle )
{
	struct pcap	*p, *prevp;
	struct ifreq	ifr;

	if (handle->md.clear_promisc) {
		/*
		 * We put the interface into promiscuous mode; take
		 * it out of promiscuous mode.
		 *
		 * XXX - if somebody else wants it in promiscuous mode,
		 * this code cannot know that, so it'll take it out
		 * of promiscuous mode.  That's not fixable in 2.0[.x]
		 * kernels.
		 */
		memset(&ifr, 0, sizeof(ifr));
		strncpy(ifr.ifr_name, handle->md.device, sizeof(ifr.ifr_name));
		if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
			fprintf(stderr,
			    "Can't restore interface flags (SIOCGIFFLAGS failed: %s).\n"
			    "Please adjust manually.\n"
			    "Hint: This can't happen with Linux >= 2.2.0.\n",
			    strerror(errno));
		} else {
			if (ifr.ifr_flags & IFF_PROMISC) {
				/*
				 * Promiscuous mode is currently on; turn it
				 * off.
				 */
				ifr.ifr_flags &= ~IFF_PROMISC;
				if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1) {
					fprintf(stderr,
					    "Can't restore interface flags (SIOCSIFFLAGS failed: %s).\n"
					    "Please adjust manually.\n"
					    "Hint: This can't happen with Linux >= 2.2.0.\n",
					    strerror(errno));
				}
			}
		}

		/*
		 * Take this pcap out of the list of pcaps for which we
		 * have to take the interface out of promiscuous mode.
		 */
		for (p = pcaps_to_close, prevp = NULL; p != NULL;
		    prevp = p, p = p->md.next) {
			if (p == handle) {
				/*
				 * Found it.  Remove it from the list.
				 */
				if (prevp == NULL) {
					/*
					 * It was at the head of the list.
					 */
					pcaps_to_close = p->md.next;
				} else {
					/*
					 * It was in the middle of the list.
					 */
					prevp->md.next = p->md.next;
				}
				break;
			}
		}
	}

	if (handle->md.device != NULL)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美综合一区二区| 亚洲 欧美综合在线网络| 91精品在线一区二区| 91在线丨porny丨国产| 国产一区二区三区国产| 麻豆成人久久精品二区三区红| 亚洲自拍偷拍九九九| 亚洲欧美自拍偷拍色图| 国产精品国产三级国产普通话99 | 色视频欧美一区二区三区| 国产91精品在线观看| 国产一区啦啦啦在线观看| 久久精品国产精品青草| 久久av老司机精品网站导航| 久久99精品视频| 美女爽到高潮91| 亚洲精品成人a在线观看| 国产精品激情偷乱一区二区∴| 色综合久久久久久久久久久| 一本大道av一区二区在线播放| 91丝袜美腿高跟国产极品老师| 99久久精品国产麻豆演员表| 97久久精品人人做人人爽50路| 91在线精品一区二区| 欧美亚洲图片小说| 91精品在线观看入口| 精品国内二区三区| 国产精品丝袜久久久久久app| 自拍偷拍欧美精品| 亚洲成av人片在线观看无码| 日韩福利视频网| 国内成人自拍视频| 不卡一区中文字幕| 欧美在线视频全部完| 欧美一区二区三区性视频| 精品国产在天天线2019| 国产日韩欧美高清在线| 亚洲人xxxx| 免费视频最近日韩| 国产91在线观看丝袜| 在线观看亚洲一区| 欧美v日韩v国产v| 日韩美女视频一区二区| 石原莉奈一区二区三区在线观看| 黑人精品欧美一区二区蜜桃| 97久久精品人人爽人人爽蜜臀| 欧美三级在线看| 久久久99久久| 亚洲成人资源在线| 国产精品一区二区在线观看不卡 | 亚洲国产成人porn| 国产精品系列在线观看| 欧美亚洲高清一区二区三区不卡| 日韩一级高清毛片| 亚洲人成7777| 国产精品一区一区| 3d动漫精品啪啪| 亚洲免费在线看| 国精产品一区一区三区mba桃花| 色网综合在线观看| 国产校园另类小说区| 视频一区二区国产| 色老汉一区二区三区| 国产视频亚洲色图| 免费看日韩精品| 亚洲精品在线观看视频| 一区二区在线电影| 成人免费高清视频| 亚洲精品在线观看网站| 肉色丝袜一区二区| 欧美又粗又大又爽| 国产精品高潮久久久久无| 麻豆成人综合网| 欧美顶级少妇做爰| 91.xcao| 色综合色综合色综合| 亚洲日本一区二区| 精品少妇一区二区三区| 在线观看欧美日本| 五月天一区二区三区| 国产日产精品1区| 精品污污网站免费看| 激情文学综合插| 亚洲资源中文字幕| 亚洲国产精品激情在线观看| 欧美日韩一级片在线观看| 日本系列欧美系列| 一区在线观看免费| 久久综合九色综合97婷婷| 欧美性感一类影片在线播放| 99在线视频精品| 免费人成黄页网站在线一区二区| 中文字幕制服丝袜一区二区三区 | 国产欧美日韩视频一区二区| 国模无码大尺度一区二区三区| 午夜精彩视频在线观看不卡| 欧美视频一二三区| 99久久精品免费看国产| 国产一区二区电影| 亚洲综合成人在线| 精品国内片67194| 日本不卡一二三| 亚洲精品国产成人久久av盗摄| 久久亚洲一区二区三区明星换脸| 天堂蜜桃91精品| 国产精品色噜噜| 国产成人日日夜夜| 在线观看亚洲a| 亚洲成人中文在线| 欧美一区二区三区在线观看视频| 日韩精品电影在线| 精品国产亚洲在线| 国产69精品久久久久毛片 | 亚洲国产裸拍裸体视频在线观看乱了| 日本一区二区在线不卡| 国产欧美日韩不卡免费| 亚洲精品伦理在线| 蜜桃av一区二区在线观看| 久久国产精品第一页| 91精品福利在线| 日韩一区二区电影网| 国产亚洲1区2区3区| 亚洲激情中文1区| 另类成人小视频在线| jizz一区二区| 亚洲精品一区二区三区精华液| 久久精品视频一区二区三区| 一区二区不卡在线视频 午夜欧美不卡在| 亚洲国产精品一区二区www在线| 成人动漫精品一区二区| 色婷婷综合久久久| 日本一区二区三区高清不卡| 视频一区欧美日韩| 欧美色综合网站| 国产精品电影一区二区三区| 日韩不卡免费视频| 岛国精品在线观看| 日韩视频免费直播| 国产在线不卡视频| 欧美精品一级二级| 日韩欧美123| 久久久综合网站| 美腿丝袜在线亚洲一区| 99国产精品视频免费观看| 精品一区二区三区免费视频| 国产一区视频网站| 国产成人午夜精品影院观看视频| 欧美精品aⅴ在线视频| 成人激情午夜影院| 奇米色一区二区| 亚洲精品国久久99热| 欧美极品少妇xxxxⅹ高跟鞋 | 国产精品乡下勾搭老头1| 午夜私人影院久久久久| 亚洲一区二区三区爽爽爽爽爽| 久久久久一区二区三区四区| 欧美另类高清zo欧美| 色综合久久综合中文综合网| 福利一区二区在线| 久久精品国产77777蜜臀| 亚洲国产精品久久久男人的天堂| 中文字幕在线免费不卡| 久久女同互慰一区二区三区| 91精品国产一区二区三区| 91福利国产成人精品照片| hitomi一区二区三区精品| 国产自产v一区二区三区c| 美女免费视频一区| 免费人成黄页网站在线一区二区| 亚洲国产一区二区在线播放| 亚洲美女在线一区| 亚洲精品综合在线| 国产精品久久久久精k8| 日本一区二区三区电影| 国产色爱av资源综合区| 国产情人综合久久777777| 久久久久9999亚洲精品| 久久久亚洲综合| 国产女人18毛片水真多成人如厕 | 欧美少妇bbb| 欧美剧情片在线观看| 欧美日韩国产高清一区二区| 欧美日韩免费视频| 欧美一卡2卡3卡4卡| 日韩视频在线一区二区| 精品成人一区二区三区四区| 久久久久久久免费视频了| 欧美高清在线精品一区| 中文字幕色av一区二区三区| 亚洲欧美一区二区不卡| 亚洲制服丝袜av| 奇米888四色在线精品| 国内精品自线一区二区三区视频| 国产福利视频一区二区三区| 成人app软件下载大全免费| 97久久精品人人澡人人爽| 欧洲一区在线观看| 欧美一区二区三区在线观看视频| 久久久www成人免费毛片麻豆| 国产精品国产精品国产专区不蜜|