• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pcap_get_selectable_fd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: sniffer_thread

DWORD sniffer_thread(THREAD *thread)
{
	int fd;
	fd_set rfds;
	struct timeval tv;
	int count;

	CaptureJob *j = (CaptureJob *)(thread->parameter1);
	fd = pcap_get_selectable_fd(j->pcap);

	dprintf("pcap @ %p, selectable fd is %d", j->pcap, fd);

	while(event_poll(thread->sigterm, 0) == FALSE && j->active) {
		tv.tv_sec = 0;
		tv.tv_usec = 5000;

		FD_ZERO(&rfds);
		FD_SET(pcap_get_selectable_fd(j->pcap), &rfds);

		select(fd+1, &rfds, NULL, NULL, &tv);

		count = pcap_dispatch(j->pcap, 100, packet_handler, (u_char *)(j));
		if (-1 == count)
			dprintf("pcap error: %s", pcap_geterr(j->pcap));

		if(count <= 0) continue;
		if(count) dprintf("dispatched %d packets", count);
	}

	dprintf("and we're done");
	return 0;
}
开发者ID:Datacut,项目名称:metasploit-framework,代码行数:32,代码来源:sniffer.c


示例2: tc_pcap_socket_in_init

int
tc_pcap_socket_in_init(pcap_t **pd, char *device, 
        int snap_len, int buf_size, char *pcap_filter)
{
    int         fd;
    char        ebuf[PCAP_ERRBUF_SIZE]; 
    struct      bpf_program fp;
    bpf_u_int32 net, netmask;      

    if (device == NULL) {
        return TC_INVALID_SOCK;
    }

    tc_log_info(LOG_NOTICE, 0, "pcap open,device:%s", device);

    *ebuf = '\0';

    if (tc_pcap_open(pd, device, snap_len, buf_size) == TC_ERR) {
        return TC_INVALID_SOCK;
    }

    if (pcap_lookupnet(device, &net, &netmask, ebuf) < 0) {
        net = 0;
        netmask = 0;
        tc_log_info(LOG_WARN, 0, "lookupnet:%s", ebuf);
        return TC_INVALID_SOCK;
    }

    if (pcap_compile(*pd, &fp, pcap_filter, 0, netmask) == -1) {
        tc_log_info(LOG_ERR, 0, "couldn't parse filter %s: %s", 
                pcap_filter, pcap_geterr(*pd));
        return TC_INVALID_SOCK;
    }

    if (pcap_setfilter(*pd, &fp) == -1) {
        tc_log_info(LOG_ERR, 0, "couldn't install filter %s: %s",
                pcap_filter, pcap_geterr(*pd));
        pcap_freecode(&fp);
        return TC_INVALID_SOCK;
    }

    pcap_freecode(&fp);

    if (pcap_get_selectable_fd(*pd) == -1) {
        tc_log_info(LOG_ERR, 0, "pcap_get_selectable_fd fails"); 
        return TC_INVALID_SOCK;
    }

    if (pcap_setnonblock(*pd, 1, ebuf) == -1) {
        tc_log_info(LOG_ERR, 0, "pcap_setnonblock failed: %s", ebuf);
        return TC_INVALID_SOCK;
    }

    fd = pcap_get_selectable_fd(*pd);

    return fd;
}
开发者ID:343829084,项目名称:tcpcopy,代码行数:57,代码来源:tc_socket.c


示例3: tc_pcap_socket_in_init

int
tc_pcap_socket_in_init(pcap_t **pd, char *device, char *pcap_filter)
{
    int         fd;
    char        ebuf[PCAP_ERRBUF_SIZE]; 
    struct      bpf_program fp;
    bpf_u_int32 net, netmask;      

    if (device == NULL) {
        return TC_INVALID_SOCKET;
    }

    tc_log_info(LOG_NOTICE, 0, "pcap open,device:%s", device);

    *ebuf = '\0';
    *pd = pcap_open_live(device, PCAP_RECV_BUF_SIZE, 0, 1000, ebuf);
    if (*pd == NULL) {
        tc_log_info(LOG_ERR, 0, "pcap error:%s", ebuf);
        return TC_INVALID_SOCKET;
    } else if (*ebuf) {
        tc_log_info(LOG_WARN, 0, "pcap warn:%s", ebuf);
    }

    if (pcap_lookupnet(device, &net, &netmask, ebuf) < 0) {
        net = 0;
        netmask = 0;
        tc_log_info(LOG_WARN, 0, "lookupnet:%s", ebuf);
    }

    if (pcap_compile(*pd, &fp, pcap_filter, 0, netmask) == -1) {
        tc_log_info(LOG_ERR, 0, "couldn't parse filter %s: %s", 
                pcap_filter, pcap_geterr(*pd));
        return TC_INVALID_SOCKET;
    }

    if (pcap_setfilter(*pd, &fp) == -1) {
        tc_log_info(LOG_ERR, 0, "couldn't install filter %s: %s",
                pcap_filter, pcap_geterr(*pd));
        return TC_INVALID_SOCKET;
    }

    if (pcap_get_selectable_fd(*pd) == -1) {
        tc_log_info(LOG_ERR, 0, "pcap_get_selectable_fd fails"); 
        return TC_INVALID_SOCKET;
    }

    if (pcap_setnonblock(*pd, 1, ebuf) == -1) {
        tc_log_info(LOG_ERR, 0, "pcap_setnonblock failed: %s", ebuf);
        return TC_INVALID_SOCKET;
    }

    fd = pcap_get_selectable_fd(*pd);

    return fd;
}
开发者ID:changguanghua,项目名称:tcpcopy,代码行数:55,代码来源:tc_socket.c


示例4: pcap_get_selectable_fd

int BaseSniffer::get_fd() {
    #ifndef _WIN32
        return pcap_get_selectable_fd(handle);
    #else
        throw std::runtime_error("Method not supported in Windows platform");
    #endif // _WIN32
}
开发者ID:gtdsj,项目名称:libtins,代码行数:7,代码来源:sniffer.cpp


示例5: pcap_get_selectable_fd

int BaseSniffer::get_fd() {
    #ifndef _WIN32
        return pcap_get_selectable_fd(handle_);
    #else
        throw unsupported_function();
    #endif // _WIN32
}
开发者ID:Pflanzgurke,项目名称:libtins,代码行数:7,代码来源:sniffer.cpp


示例6: 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


示例7: set_raw_filter

int set_raw_filter(unsigned int loc_idx, char *filter) {

        struct bpf_program raw_filter;
        //uint16_t snaplen = 65535;
        int linktype;
        //struct pcap_t *aa;
        int fd = -1;
                
        LERR("APPLY FILTER [%d]\n", loc_idx);        
        if(loc_idx >= MAX_SOCKETS || sniffer_proto[loc_idx] == NULL) return 0;         

        fd = pcap_get_selectable_fd(sniffer_proto[loc_idx]);

        linktype  = profile_socket[loc_idx].link_type ? profile_socket[loc_idx].link_type : DLT_EN10MB;

        if (pcap_compile_nopcap(profile_socket[loc_idx].snap_len ? profile_socket[loc_idx].snap_len : 0xffff, linktype, &raw_filter, filter, 1, 0) == -1) {
                LERR("Failed to compile filter '%s'", filter);
                return -1;
        }

#if ( defined (OS_LINUX) || defined (OS_SOLARIS) )
        if(setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &raw_filter, sizeof(raw_filter)) < 0 ) {
                LERR(" setsockopt filter: [%s] [%d]", strerror(errno), errno);
                return -1;
        }
#endif

        //free(BPF_code);
        pcap_freecode( (struct bpf_program *) &raw_filter);

        return 1;

}
开发者ID:mslehto,项目名称:captagent,代码行数:33,代码来源:socket_pcap.c


示例8: tuntap_openmon_cb

/* Monitor, inject, and injmon are all the same method, open a new vap */
int tuntap_openmon_cb(lorcon_t *context) {
	char *parent;
	char pcaperr[PCAP_ERRBUF_SIZE];
	struct mac80211_lorcon *extras = (struct mac80211_lorcon *) context->auxptr;
	short flags;
	struct ifreq if_req;
	struct sockaddr_ll sa_ll;

	if (ifconfig_delta_flags(context->ifname, context->errstr,
							 (IFF_UP | IFF_RUNNING | IFF_PROMISC)) < 0) {
		return -1;
	}

	pcaperr[0] = '\0';

	if ((context->pcap = pcap_open_live(context->ifname, LORCON_MAX_PACKET_LEN, 
										1, 1000, pcaperr)) == NULL) {
		snprintf(context->errstr, LORCON_STATUS_MAX, "%s", pcaperr);
		return -1;
	}

	context->capture_fd = pcap_get_selectable_fd(context->pcap);

	context->dlt = pcap_datalink(context->pcap);

	context->inject_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

	if (context->inject_fd < 0) {
		snprintf(context->errstr, LORCON_STATUS_MAX, "failed to create injection "
				 "socket: %s", strerror(errno));
		pcap_close(context->pcap);
		return -1;
	}

	memset(&if_req, 0, sizeof(if_req));
	memcpy(if_req.ifr_name, context->ifname, IFNAMSIZ);
	if_req.ifr_name[IFNAMSIZ - 1] = 0;
	if (ioctl(context->inject_fd, SIOCGIFINDEX, &if_req) < 0) {
		snprintf(context->errstr, LORCON_STATUS_MAX, "failed to get interface idex: %s",
				 strerror(errno));
		close(context->inject_fd);
		pcap_close(context->pcap);
		return -1;
	}

	memset(&sa_ll, 0, sizeof(sa_ll));
	sa_ll.sll_family = AF_PACKET;
	sa_ll.sll_protocol = htons(ETH_P_80211_RAW);
	sa_ll.sll_ifindex = if_req.ifr_ifindex;
	if (bind(context->inject_fd, (struct sockaddr *) &sa_ll, sizeof(sa_ll)) != 0) {
		snprintf(context->errstr, LORCON_STATUS_MAX, "failed to bind injection "
				 "socket: %s", strerror(errno));
		close(context->inject_fd);
		pcap_close(context->pcap);
		return -1;
	}

	return 1;
}
开发者ID:0x0d,项目名称:lorcon,代码行数:60,代码来源:drv_tuntap.c


示例9: netfpga_init_port

static rofl_result_t netfpga_init_port(switch_port_t* port){




	struct ifreq interface;
	netfpga_port_t* nport = (netfpga_port_t*)malloc(sizeof(*nport));

	
	char *useless;

	
	
		//fprintf(stderr, "device=  %s  \n",dev);
	useless = pcap_lookupdev(port->name); //test if device exist// gives char pointer, why not pcap_if_t?
	if (useless == NULL) {
		ROFL_ERR( "Couldn't find device: error= %s; no permission to listen on interface or other failure  \n", port->name);
		return ROFL_FAILURE;	
	}
	ROFL_DEBUG("Device :%s  found\n", port->name);

		
	char errbuf[PCAP_ERRBUF_SIZE];

	
	nport->pcap_fd = pcap_open_live(port->name, BUFSIZ, 1, 0, errbuf);//wait until the packet arrive, NO TIMEOUT
	if (nport->pcap_fd == NULL) {
		 ROFL_ERR( "Couldn't open device %s : %s\n",port->name, errbuf);
		 return ROFL_FAILURE;
	}

	nport->fd = pcap_get_selectable_fd(nport->pcap_fd);
	nport->test=25;	
	ROFL_DEBUG("pcap_open_live: socket opened \n ");
	



	ROFL_DEBUG("Ports.c creating socket over %s inerface\n", port->name);
	strncpy(interface.ifr_ifrn.ifrn_name, port->name, IFNAMSIZ/*&SWITCH_PORT_MAX_LEN_NAME*/);
	

	int flags;

	/* Set non-blocking mode. */
	flags = fcntl(nport->fd, F_GETFL, 0);
	if(fcntl(nport->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
		return ROFL_FAILURE;
	}

	//Store in platform state and return
	port->platform_port_state = (platform_port_state_t*) nport;	

	return ROFL_SUCCESS;
} 
开发者ID:fp7-alien,项目名称:xDPd-Virtualization,代码行数:55,代码来源:ports.c


示例10: l2_packet_deinit

void l2_packet_deinit(struct l2_packet_data *l2)
{
	if (l2 != NULL) {
		if (l2->pcap) {
			eloop_unregister_read_sock(
				pcap_get_selectable_fd(l2->pcap));
			pcap_close(l2->pcap);
		}
		os_free(l2);
	}
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:11,代码来源:l2_packet.c


示例11: lpcap_getfd

static int lpcap_getfd(lua_State* L)
{
    pcap_t* cap = checkpcap(L);
    int fd = pcap_get_selectable_fd(cap);
    if(fd < 0) {
        lua_pushnil(L);
        lua_pushstring(L, "not selectable");
        return 2;
    }
    lua_pushnumber(L, fd);
    return 1;
}
开发者ID:mikegarts,项目名称:pcap-lua,代码行数:12,代码来源:pcap.c


示例12: main

int main(int argc, char *argv[])
{
	char *dev, errbuf[PCAP_ERRBUF_SIZE];
	pcap_t *handle;
	int selectable_fd;

	if (argc == 2) {
		dev = argv[1];
	} else {
		dev = pcap_lookupdev(errbuf);
	}

	if (dev == NULL) {
		fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
		return (2);
	}

	handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf);
	if (handle == NULL) {
		fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
		return (2);
	}

	if (pcap_datalink(handle) != DLT_EN10MB) {
		fprintf(stderr, "Device %s doesn't provide Ethernet headers - "
		                "not supported\n",
		        dev);
		return (2);
	}

	if (pcap_setnonblock(handle, 1, errbuf) != 0) {
		fprintf(stderr, "Non-blocking mode failed: %s\n", errbuf);
		return (2);
	}

	selectable_fd = pcap_get_selectable_fd(handle);
	if (-1 == selectable_fd) {
		fprintf(stderr, "pcap handle not selectable.\n");
		return (2);
	}

	init_curses();
	mvprintw(0, 0, "Device: %s\n", dev);

	grab_packets(selectable_fd, handle);

	/* And close the session */
	pcap_close(handle);
	return 0;
}
开发者ID:tcharding,项目名称:toptalk,代码行数:50,代码来源:main.c


示例13: pcap_open_live

// アダプタを開く (Pcap)
ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr)
{
	char errbuf[PCAP_ERRBUF_SIZE];
	ETH *e;
	pcap_t *p;
	CANCEL *c;

	// 引数チェック
	if (name == NULL || tapmode != false)
	{
		return NULL;
	}
	
	// エラーメッセージバッファの初期化
	errbuf[0] = 0;

	// キャプチャデバイスを開く
	p = pcap_open_live(name, 65535, (local == false), 1, errbuf);
	if(p==NULL)
	{
		return NULL;
	}

	// ノンブロックモードに設定
	// BSD系OSでは、BPFのselectが正常に動作しないのでブロックさせないとビジーループになる
	/*
	if(pcap_setnonblock(p, true, errbuf) == -1)
	{
		Debug("pcap_setnonblock:%s\n",errbuf);
		pcap_close(p);
		return NULL;
	}
	*/
	
	e = ZeroMalloc(sizeof(ETH));
	e->Name = CopyStr(name);
	e->Title = CopyStr(name);
	e->Queue = NewQueue();
	e->QueueSize = 0;
	e->Cancel = NewCancel();
	e->IfIndex = -1;
	e->Socket = pcap_get_selectable_fd(p);
	e->Pcap = p;
	
	e->CaptureThread = NewThread(PcapThread, e);
	WaitThreadInit(e->CaptureThread);

	return e;
}
开发者ID:falcon8823,项目名称:utvpn,代码行数:50,代码来源:BridgeUnix.c


示例14: pcap_open_live

// Open Ethernet adapter (Pcap)
ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr)
{
	char errbuf[PCAP_ERRBUF_SIZE];
	ETH *e;
	pcap_t *p;
	CANCEL *c;

	// Validate arguments
	if (name == NULL || tapmode != false)
	{
		return NULL;
	}
	
	// Initialize error message buffer
	errbuf[0] = 0;

	// Open capturing device
	p = pcap_open_live(name, 65535, (local == false), 1, errbuf);
	if(p==NULL)
	{
		return NULL;
	}

	// Set to non-block mode
	// (In old BSD OSs, 'select(2)' don't block normally for BPF device. To prevent busy loop)
	/*
	if(pcap_setnonblock(p, true, errbuf) == -1)
	{
		Debug("pcap_setnonblock:%s\n",errbuf);
		pcap_close(p);
		return NULL;
	}
	*/
	
	e = ZeroMalloc(sizeof(ETH));
	e->Name = CopyStr(name);
	e->Title = CopyStr(name);
	e->Queue = NewQueue();
	e->QueueSize = 0;
	e->Cancel = NewCancel();
	e->IfIndex = -1;
	e->Socket = pcap_get_selectable_fd(p);
	e->Pcap = p;
	
	e->CaptureThread = NewThread(PcapThread, e);
	WaitThreadInit(e->CaptureThread);

	return e;
}
开发者ID:455475876github,项目名称:SoftEtherVPN,代码行数:50,代码来源:BridgeUnix.c


示例15: l2_packet_deinit

void l2_packet_deinit(struct l2_packet_data *l2)
{
	if (l2 == NULL)
		return;

#ifdef CONFIG_WINPCAP
	eloop_cancel_timeout(l2_packet_receive_timeout, l2, l2->pcap);
#else /* CONFIG_WINPCAP */
	if (l2->eth)
		eth_close(l2->eth);
	eloop_unregister_read_sock(pcap_get_selectable_fd(l2->pcap));
#endif /* CONFIG_WINPCAP */
	if (l2->pcap)
		pcap_close(l2->pcap);
	os_free(l2);
}
开发者ID:qwerty1023,项目名称:wive-rtnl-firmware,代码行数:16,代码来源:l2_packet_pcap.c


示例16: p_get_selectable_fd

static PyObject * p_get_selectable_fd (PyObject *self, PyObject *args)
{
#ifdef HAVE_PCAP_GET_SELECTABLE_FD
  pcap_t * ppcap;
  int rv;
  if (!PyArg_ParseTuple(args, "l", &ppcap)) return NULL;

  rv = pcap_get_selectable_fd(ppcap);

  return Py_BuildValue("i", rv);
#else
  PyErr_SetString(PyExc_RuntimeError, "Selectable FD not supported");
  return NULL;
  //return Py_BuildValue("i", -1);
#endif
}
开发者ID:14gr1010,项目名称:software,代码行数:16,代码来源:pxpcap.cpp


示例17: pcap_inject

/**
 * Substitute for pcap_inject(), if this version of libpcap doesn't
 * have it.  Will almost certainly only work under Linux.
 *
 */
int pcap_inject ( pcap_t *pcap, const void *data, size_t len ) {
    int fd;
    char *errbuf = pcap_geterr ( pcap );

    fd = pcap_get_selectable_fd ( pcap );
    if ( fd < 0 ) {
        snprintf ( errbuf, PCAP_ERRBUF_SIZE,
                   "could not get file descriptor" );
        return -1;
    }
    if ( write ( fd, data, len ) != len ) {
        snprintf ( errbuf, PCAP_ERRBUF_SIZE,
                   "could not write data: %s", strerror ( errno ) );
        return -1;
    }
    return len;
}
开发者ID:B-Rich,项目名称:serialice,代码行数:22,代码来源:hijack.c


示例18: net_loop

static void net_loop(void)
{
  unsigned i;
  struct cap cap;
  signed fds[IFACE_MAX];
  signed fdmax = INT_MIN;
  struct timeval tv;
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  memset(&cap, 0, sizeof cap);
  for (i = 0; i < Iface_Cnt; i++) {
    fds[i] = pcap_get_selectable_fd(Pcap[i]);
    if (fds[i] > fdmax)
      fdmax = fds[i];
  }
  while (!Shutdown) {
    fd_set rd;
    signed sel;
    FD_ZERO(&rd);
    if (Reload_Config) { /* reload config file if requested */
      Reload_Config = 0;
      printf("Clearing existing rules...\n");
      rules_clear();
      printf("Reloading config file...\n");
      parse_config();
    }
    for (i = 0; i < Iface_Cnt; i++)
      FD_SET(fds[i], &rd);
    sel = select(fdmax + 1, &rd, NULL, NULL, NULL);
    if (-1 == sel) {
      perror("select");
      continue;
    } else if (0 == sel) {
      continue;
    }
    for (i = 0; i < Iface_Cnt; i++) {
      if (!FD_ISSET(fds[i], &rd))
        continue;
      if (1 != pcap_next_ex(Pcap[i], &cap.pkt[0].data.logic.header, (const unsigned char **)&cap.raw))
        continue;
      cap.len = (unsigned)cap.pkt[0].data.logic.header->len;
      process_packet(i, &cap);
    }
  }
}
开发者ID:rflynn,项目名称:lanassert,代码行数:45,代码来源:LANassert.c


示例19: pcap_findalldevs

ebbrt::RawSocket::RawSocket()
{
  char errbuf[PCAP_ERRBUF_SIZE];
  pcap_if_t* alldevs;

  int ret = pcap_findalldevs(&alldevs, errbuf);
  assert(ret != -1);

  while (alldevs != NULL) {
    if (strcmp(alldevs->name, dev) == 0) {
      break;
    }
    alldevs = alldevs->next;
  }

  assert(alldevs != NULL);

  auto addr = alldevs->addresses;
  while (addr != NULL) {
    if (addr->addr->sa_family == AF_PACKET) {
      break;
    }
    addr = addr->next;
  }
  assert(addr != NULL);

  auto packet_addr = reinterpret_cast<struct sockaddr_ll*>(addr->addr);
  std::copy(&packet_addr->sll_addr[0], &packet_addr->sll_addr[5], mac_addr_);

  pdev_ = pcap_open_live(dev, 65535, 0, 0, errbuf);
  assert(dev != NULL);

  ret = pcap_setnonblock(pdev_, 1, errbuf);
  assert(ret != -1);

  int fd = pcap_get_selectable_fd(pdev_);
  assert(fd != -1);

  uint8_t interrupt = event_manager->AllocateInterrupt([]() {
      ethernet->Receive();
    });
  event_manager->RegisterFD(fd, EPOLLIN, interrupt);
}
开发者ID:B-Rich,项目名称:EbbRT,代码行数:43,代码来源:RawSocket.cpp


示例20: pcap_init

int pcap_init(void *interface)
{
	char errbuf[PCAP_ERRBUF_SIZE];

	pcap = pcap_open_live(interface,65536,1,0,errbuf);

	if (!pcap) {
		Log(LOG_CRIT, "can't sniff the interface: %s",errbuf);
		return 1;
	}

	pcap_fdcb.fd=pcap_get_selectable_fd(pcap);
	pcap_fdcb.flags=EV_READ;
	pcap_fdcb.callback=pcap_cb;

	add_event(&pcap_fdcb);
	

	return 0;
}
开发者ID:isomer,项目名称:dhcparpd,代码行数:20,代码来源:dhcparpd.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pcap_geterr函数代码示例发布时间:2022-05-30
下一篇:
C++ pcap_freecode函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap