本文整理汇总了C++中pcap_create函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_create函数的具体用法?C++ pcap_create怎么用?C++ pcap_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcap_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
char errbuf[PCAP_ERRBUF_SIZE];
struct pcap_pkthdr *pkthdr;
const u_char *pkt_data;
Options options;
parse_args(argc, argv, &options);
if(options.list_devices) {
show_devices();
exit(0);
}
// Create Handles for in and out
pcap_t *in_handle = pcap_create(argv[1], errbuf);
pcap_t *out_handle = pcap_create(argv[1], errbuf);
if(!in_handle | !out_handle )
exit_error(errbuf, -1);
int result = 0;
// Set timeout
result = pcap_set_timeout(in_handle, 1); // Header size up to window size
result = pcap_set_timeout(out_handle, 1); // Header size up to window size
handle_pcap_errors(in_handle, result, "set_timeout");
handle_pcap_errors(out_handle, result, "set_timeout");
// Activate!
result = pcap_activate(out_handle);
result = pcap_activate(in_handle);
handle_pcap_errors(out_handle, result, "pcap_activate");
handle_pcap_errors(in_handle, result, "pcap_activate");
// Set Filter
filter_on_port(out_handle, "src port ", options.port_str);
filter_on_port(in_handle, "dst port ", options.port_str);
// Count packet lenghts on port
int out_byte_count = 0;
int in_byte_count = 0;
for(int i = 0; i < 100; i++) {
pcap_next_ex(out_handle, &pkthdr, &pkt_data);
out_byte_count += pkthdr->len;
pcap_next_ex(in_handle, &pkthdr, &pkt_data);
in_byte_count += pkthdr->len;
}
printf("In Bytes: %d\n", in_byte_count);
printf("Out Bytes: %d\n", out_byte_count);
return 0;
}
开发者ID:cwgreene,项目名称:pcap-tests,代码行数:58,代码来源:filter_on.cpp
示例2: fork
/* Initializes pcap capture settings and returns a pcap handle on success, NULL on error */
pcap_t *capture_init(char *capture_source) {
pcap_t *handle = NULL;
char errbuf[PCAP_ERRBUF_SIZE] = {0};
#ifdef __APPLE__
// must disassociate from any current AP. This is the only way.
pid_t pid = fork();
if (!pid) {
char* argv[] = {"/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", "-z", NULL};
execve("/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", argv, NULL);
}
int status;
waitpid(pid, &status, 0);
handle = pcap_create(capture_source, errbuf);
if (handle) {
pcap_set_snaplen(handle, BUFSIZ);
pcap_set_timeout(handle, 50);
pcap_set_rfmon(handle, 1);
pcap_set_promisc(handle, 1);
int status = pcap_activate(handle);
if (status)
cprintf(CRITICAL, "pcap_activate status %d\n", status);
}
#else
handle = pcap_open_live(capture_source, BUFSIZ, 1, 0, errbuf);
#endif
if (!handle) {
handle = pcap_open_offline(capture_source, errbuf);
}
return handle;
}
开发者ID:vk496,项目名称:reaver-wps-fork-t6x,代码行数:35,代码来源:init.c
示例3: pcap_create
Sniffer::Sniffer(const string& device,
promisc_type promisc,
const string& filter,
bool rfmon) {
SnifferConfiguration configuration;
configuration.set_promisc_mode(promisc == PROMISC);
configuration.set_filter(filter);
configuration.set_rfmon(rfmon);
char error[PCAP_ERRBUF_SIZE];
pcap_t* phandle = pcap_create(TINS_PREFIX_INTERFACE(device).c_str(), error);
if (!phandle) {
throw runtime_error(error);
}
set_pcap_handle(phandle);
// Set the netmask if we are able to find it.
bpf_u_int32 ip, if_mask;
if (pcap_lookupnet(TINS_PREFIX_INTERFACE(device).c_str(), &ip, &if_mask, error) == 0) {
set_if_mask(if_mask);
}
// Configure the sniffer's attributes prior to activation.
configuration.configure_sniffer_pre_activation(*this);
// Finally, activate the pcap. In case of error throw runtime_error
if (pcap_activate(get_pcap_handle()) < 0) {
throw pcap_error(pcap_geterr(get_pcap_handle()));
}
// Configure the sniffer's attributes after activation.
configuration.configure_sniffer_post_activation(*this);
}
开发者ID:Pflanzgurke,项目名称:libtins,代码行数:33,代码来源:sniffer.cpp
示例4: main
int main (void)
{
int fd;
/* Create PCAP file */
assert((fd = pcap_create(test_path, LINKTYPE_EN10MB)) > 0);
/* Write payload */
assert(test_pcap_write(fd, icmp_dns, sizeof(icmp_dns)) == 0);
assert(pcap_close(fd) == 0);
assert((fd = pcap_open(test_path, O_RDONLY)) > 0);
assert(pcap_has_packets(fd));
assert(pcap_close(fd) == 0);
assert((fd = pcap_open(test_path, O_RDWR | O_APPEND)) > 0);
/* Write payload */
assert(test_pcap_write(fd, icmp_dns, sizeof(icmp_dns)) == 0);
assert(pcap_close(fd) == 0);
pcap_destroy(fd, test_path);
return (EXIT_SUCCESS);
}
开发者ID:eroullit,项目名称:net-toolbox,代码行数:29,代码来源:test_pcap.c
示例5: print_timestamp_types
static void print_timestamp_types(const char *dev) {
int i, ntstypes;
char junk[PCAP_ERRBUF_SIZE];
int *tstypes;
pcap_t *handle;
handle = pcap_create(dev, junk);
if(!handle)
return;
ntstypes = pcap_list_tstamp_types(handle, &tstypes);
if(ntstypes > 0)
printf(" Timestamp types:%s", options.verbose > 1 ? "\n" : " ");
if(options.verbose > 1)
for(i = 0; i < ntstypes; ++i)
printf(" %-20s %s\n", pcap_tstamp_type_val_to_name(tstypes[i]),
pcap_tstamp_type_val_to_description(tstypes[i]));
else
for(i = 0; i < ntstypes; ++i)
printf("%s%s", pcap_tstamp_type_val_to_name(tstypes[i])
, i + 1 > ntstypes ? ", " : "\n");
pcap_free_tstamp_types(tstypes);
pcap_close(handle);
}
开发者ID:protoben,项目名称:protodump,代码行数:25,代码来源:capture.c
示例6: open_pcap_dev
static pcap_t* open_pcap_dev(const char* ifname, int frameSize, char* errbuf)
{
pcap_t* handle = pcap_create(ifname, errbuf);
if (handle) {
int err;
err = pcap_set_snaplen(handle, frameSize);
if (err) AVB_LOGF_WARNING("Cannot set snap len %d", err);
err = pcap_set_promisc(handle, 1);
if (err) AVB_LOGF_WARNING("Cannot set promisc %d", err);
err = pcap_set_immediate_mode(handle, 1);
if (err) AVB_LOGF_WARNING("Cannot set immediate mode %d", err);
// we need timeout (here 100ms) otherwise we could block for ever
err = pcap_set_timeout(handle, 100);
if (err) AVB_LOGF_WARNING("Cannot set timeout %d", err);
err = pcap_set_tstamp_precision(handle, PCAP_TSTAMP_PRECISION_NANO);
if (err) AVB_LOGF_WARNING("Cannot set tstamp nano precision %d", err);
err = pcap_set_tstamp_type(handle, PCAP_TSTAMP_ADAPTER_UNSYNCED);
if (err) AVB_LOGF_WARNING("Cannot set tstamp adapter unsynced %d", err);
err = pcap_activate(handle);
if (err) AVB_LOGF_WARNING("Cannot activate pcap %d", err);
}
return handle;
}
开发者ID:AVnu,项目名称:Open-AVB,代码行数:29,代码来源:pcap_rawsock.c
示例7: check_promisc
static bool check_promisc(const char *dev) {
char junk[PCAP_ERRBUF_SIZE];
int err;
pcap_t *handle;
handle = pcap_create(dev, junk);
if(!handle)
goto fail;
err = pcap_set_promisc(handle, 1);
if(err)
/* Should never error: pcap_set_promisc() only errors if handle is active. */
die(0, "DEBUG: Reached unreachable condition at %s:%lu\n", __FILE__, __LINE__);
err = pcap_activate(handle);
if(err && err != PCAP_WARNING)
goto fail;
pcap_close(handle);
return true;
fail:
pcap_close(handle);
return false;
}
开发者ID:protoben,项目名称:protodump,代码行数:25,代码来源:capture.c
示例8: pcap_open_live_extended
pcap_t *
pcap_open_live_extended(const char *source, int snaplen, int promisc, int to_ms, int rfmon, char *errbuf)
{
pcap_t *p;
int status;
p = pcap_create(source, errbuf);
if (p == NULL)
return (NULL);
status = pcap_set_snaplen(p, snaplen);
if (status < 0)
goto fail;
status = pcap_set_promisc(p, promisc);
if (status < 0)
goto fail;
status = pcap_set_timeout(p, to_ms);
if (status < 0)
goto fail;
if(pcap_can_set_rfmon(p) == 1) {
status = pcap_set_rfmon(p, rfmon);
if (status < 0)
goto fail;
}
status = pcap_activate(p);
if (status < 0)
goto fail;
return (p);
fail:
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source, pcap_geterr(p));
pcap_close(p);
return (NULL);
}
开发者ID:jedahan,项目名称:libtins,代码行数:33,代码来源:sniffer.cpp
示例9: capture
void capture(char *dev) {
pcap_t *pcap;
char errbuf[PCAP_ERRBUF_SIZE];
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */
if(NULL == dev) {
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
exit(1);
}
}
pcap = pcap_create(dev, errbuf);
pcap_set_rfmon(pcap, 1);
pcap_set_promisc(pcap, 1);
pcap_set_buffer_size(pcap, 1 * 1024 * 1024);
pcap_set_timeout(pcap, 1);
pcap_set_snaplen(pcap, 16384);
pcap_activate(pcap);
if(DLT_IEEE802_11_RADIO == pcap_datalink(pcap)) {
pcap_loop(pcap, 0, got_packet, 0);
} else {
fprintf(stderr, "Could not initialize a IEEE802_11_RADIO packet capture for interface %s\n", dev);
}
}
开发者ID:ayourtch,项目名称:beacondump,代码行数:27,代码来源:beacondump.c
示例10: print_datalinks
static void print_datalinks(const char *dev) {
int *linktypes;
int err, i, nlinktypes;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle;
handle = pcap_create(dev, errbuf);
if(!handle)
return;
err = pcap_activate(handle);
if(err)
return;
nlinktypes = pcap_list_datalinks(handle, &linktypes);
if(nlinktypes > 0)
printf(" Linktypes:%s", options.verbose > 1 ? "\n" : " ");
if(options.verbose > 1)
for(i = 0; i < nlinktypes; ++i)
printf(" %-20s %s\n"
, pcap_datalink_val_to_name(linktypes[i])
, pcap_datalink_val_to_description(linktypes[i]));
else
for(i = 0; i < nlinktypes; ++i)
printf("%s%s", pcap_datalink_val_to_name(linktypes[i])
, i + 1 > nlinktypes ? ", " : "\n");
pcap_free_datalinks(linktypes);
pcap_close(handle);
}
开发者ID:protoben,项目名称:protodump,代码行数:30,代码来源:capture.c
示例11: create
inline unique_pcap_t create(const std::string &device_name) {
auto buf = error_buffer{};
auto device = pcap_create(device_name.data(), buf.data());
if (!device) {
throw error{"Couldn't create device " + device_name + "\n" +
error_string(buf)};
}
return unique_pcap_t{device, &pcap_close};
}
开发者ID:jshrake,项目名称:pcapp,代码行数:9,代码来源:pcapp.hpp
示例12: tc_pcap_open
static int
tc_pcap_open(pcap_t **pd, char *device, int snap_len, int buf_size)
{
int status;
char ebuf[PCAP_ERRBUF_SIZE];
*ebuf = '\0';
*pd = pcap_create(device, ebuf);
if (*pd == NULL) {
tc_log_info(LOG_ERR, 0, "pcap create error:%s", ebuf);
return TC_ERROR;
}
status = pcap_set_snaplen(*pd, snap_len);
if (status != 0) {
tc_log_info(LOG_ERR, 0, "pcap_set_snaplen error:%s",
pcap_statustostr(status));
return TC_ERROR;
}
status = pcap_set_promisc(*pd, 0);
if (status != 0) {
tc_log_info(LOG_ERR, 0, "pcap_set_promisc error:%s",
pcap_statustostr(status));
return TC_ERROR;
}
status = pcap_set_timeout(*pd, 1000);
if (status != 0) {
tc_log_info(LOG_ERR, 0, "pcap_set_timeout error:%s",
pcap_statustostr(status));
return TC_ERROR;
}
status = pcap_set_buffer_size(*pd, buf_size);
if (status != 0) {
tc_log_info(LOG_ERR, 0, "pcap_set_buffer_size error:%s",
pcap_statustostr(status));
return TC_ERROR;
}
tc_log_info(LOG_NOTICE, 0, "pcap_set_buffer_size:%d", buf_size);
status = pcap_activate(*pd);
if (status < 0) {
tc_log_info(LOG_ERR, 0, "pcap_activate error:%s",
pcap_statustostr(status));
return TC_ERROR;
} else if (status > 0) {
tc_log_info(LOG_WARN, 0, "pcap activate warn:%s",
pcap_statustostr(status));
}
return TC_OK;
}
开发者ID:justzx2011,项目名称:tcpcopy,代码行数:57,代码来源:tc_socket.c
示例13: m_pHandler
NetworkInterface::NetworkInterface(const std::string& interface)
: m_pHandler(NULL), m_pFilter(NULL), m_pThread(NULL), m_sInterface(interface)
{
m_pHandler = pcap_create(interface.c_str(), m_sLastError);
if(!m_pHandler) {
std::cerr << "Can't create pcap handler on " << interface <<
" interface! Details: " << m_sLastError << std::endl;
}
}
开发者ID:ziminas1990,项目名称:FunVPN,代码行数:9,代码来源:InterfaceIO.cpp
示例14: pcap_main_loop
void pcap_main_loop(const char* dev) {
char errbuf[PCAP_ERRBUF_SIZE];
/* open device for reading in promiscuous mode */
int promisc = 1;
bpf_u_int32 maskp; /* subnet mask */
bpf_u_int32 netp; /* ip */
logger<< log4cpp::Priority::INFO<<"Start listening on "<<dev;
/* Get the network address and mask */
pcap_lookupnet(dev, &netp, &maskp, errbuf);
descr = pcap_create(dev, errbuf);
if (descr == NULL) {
logger<< log4cpp::Priority::ERROR<<"pcap_create was failed with error: "<<errbuf;
exit(0);
}
// Setting up 1MB buffer
int set_buffer_size_res = pcap_set_buffer_size(descr, pcap_buffer_size_mbytes * 1024 * 1024);
if (set_buffer_size_res != 0 ) {
if (set_buffer_size_res == PCAP_ERROR_ACTIVATED) {
logger<< log4cpp::Priority::ERROR<<"Can't set buffer size because pcap already activated\n";
exit(1);
} else {
logger<< log4cpp::Priority::ERROR<<"Can't set buffer size due to error: "<<set_buffer_size_res;
exit(1);
}
}
if (pcap_set_promisc(descr, promisc) != 0) {
logger<< log4cpp::Priority::ERROR<<"Can't activate promisc mode for interface: "<<dev;
exit(1);
}
if (pcap_activate(descr) != 0) {
logger<< log4cpp::Priority::ERROR<<"Call pcap_activate was failed: "<<pcap_geterr(descr);
exit(1);
}
// man pcap-linktype
int link_layer_header_type = pcap_datalink(descr);
if (link_layer_header_type == DLT_EN10MB) {
DATA_SHIFT_VALUE = 14;
} else if (link_layer_header_type == DLT_LINUX_SLL) {
DATA_SHIFT_VALUE = 16;
} else {
logger<< log4cpp::Priority::INFO<<"We did not support link type:"<<link_layer_header_type;
exit(0);
}
pcap_loop(descr, -1, (pcap_handler)parse_packet, NULL);
}
开发者ID:bozhenka,项目名称:fastnetmon,代码行数:56,代码来源:pcap_collector.cpp
示例15: myPcapCatchAndAnaly
int myPcapCatchAndAnaly() {
int status=0;
int header_type;
char errbuf[PCAP_ERRBUF_SIZE];
/* openwrt && linux */
char *dev=(char *)"wlan0";
/* mac os */
//test
// char* dev=(char *)"en0";
handle=pcap_create(dev,errbuf); //为抓取器打开一个句柄
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return 0;
}
// 由于在该路由器测试时,发现在该openwrt系统上不支持libpcap设置monitor模式,在激活的时候会产生错误
// 将采用手动设置并检测网卡是否为monitor模式
// if(pcap_can_set_rfmon(handle)) {
// //查看是否能设置为监控模式
// printf("Device %s can be opened in monitor mode\n",dev);
// }
// else {
// printf("Device %s can't be opened in monitor mode!!!\n",dev);
// }
// 若是mac os系统,则可以支持
// test
if(pcap_set_rfmon(handle,1)!=0) {
fprintf(stderr, "Device %s couldn't be opened in monitor mode\n", dev);
return 0;
} else {
printf("Device %s has been opened in monitor mode\n", dev);
}
pcap_set_promisc(handle,0); //不设置混杂模式
pcap_set_snaplen(handle,65535); //设置最大捕获包的长度
status=pcap_activate(handle); //激活
if(status!=0) {
pcap_perror(handle,(char*)"pcap error: ");
return 0;
}
header_type=pcap_datalink(handle); //返回链路层的类型
if(header_type!=DLT_IEEE802_11_RADIO) {
printf("Error: incorrect header type - %d\n",header_type);
return 0;
}
int id = 0;
pcap_loop(handle, -1, getPacket, (u_char*)&id);
return 1;
}
开发者ID:1057437122,项目名称:hello-openwrt,代码行数:56,代码来源:parser.c
示例16: na_pcap_open
NAPCapHandle *
na_pcap_open (const char *iface,
GError **error)
{
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *pcap_handle = pcap_create (iface, errbuf);
if (pcap_handle == NULL)
{
g_set_error (error,
NA_PCAP_ERROR,
NA_PCAP_ERROR_OPEN,
"pcap failed to create handle for iface: %s", errbuf);
return NULL;
}
pcap_set_snaplen (pcap_handle, PCAP_SNAPLEN);
pcap_set_timeout (pcap_handle, 100);
if (pcap_activate (pcap_handle) != 0)
{
g_set_error (error,
NA_PCAP_ERROR,
NA_PCAP_ERROR_OPEN,
"pcap failed to activate handle for iface");
return NULL;
}
NAPCapHandle *handle = g_new0 (NAPCapHandle, 1);
handle->pcap_handle = pcap_handle;
handle->iface = iface;
handle->linktype = pcap_datalink (pcap_handle);
switch (handle->linktype)
{
case (DLT_EN10MB):
g_debug ("Ethernet link detected");
break;
case (DLT_PPP):
g_debug ("PPP link detected");
break;
case (DLT_LINUX_SLL):
g_debug ("Linux Cooked Socket link detected");
break;
default:
g_debug ("No PPP or Ethernet link: %d", handle->linktype);
break;
}
return handle;
}
开发者ID:stfacc,项目名称:gnome-usage,代码行数:53,代码来源:na-pcap.c
示例17: pcap_open_live
pcap_t *
pcap_open_live(const char *source, int snaplen, int promisc, int to_ms,
char *errbuf)
{
pcap_t *p;
int status;
p = pcap_create(source, errbuf);
if (p == NULL)
return (NULL);
status = pcap_set_snaplen(p, snaplen);
if (status < 0)
goto fail;
status = pcap_set_promisc(p, promisc);
if (status < 0)
goto fail;
status = pcap_set_timeout(p, to_ms);
if (status < 0)
goto fail;
/*
* Mark this as opened with pcap_open_live(), so that, for
* example, we show the full list of DLT_ values, rather
* than just the ones that are compatible with capturing
* when not in monitor mode. That allows existing applications
* to work the way they used to work, but allows new applications
* that know about the new open API to, for example, find out the
* DLT_ values that they can select without changing whether
* the adapter is in monitor mode or not.
*/
p->oldstyle = 1;
status = pcap_activate(p);
if (status < 0)
goto fail;
return (p);
fail:
if (status == PCAP_ERROR)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
p->errbuf);
else if (status == PCAP_ERROR_NO_SUCH_DEVICE ||
status == PCAP_ERROR_PERM_DENIED ||
status == PCAP_ERROR_PROMISC_PERM_DENIED)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", source,
pcap_statustostr(status), p->errbuf);
else
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
pcap_statustostr(status));
pcap_close(p);
return (NULL);
}
开发者ID:enukane,项目名称:openbsd-work,代码行数:49,代码来源:pcap-bpf.c
示例18: stub_pcap_create
CAMLprim value
stub_pcap_create (value p_device)
{
char errbuf[PCAP_ERRBUF_SIZE];
char *device;
pcap_t *ret;
device = String_val (p_device);
ret = pcap_create (device, errbuf);
if (ret == NULL) {
raise_error (errbuf);
}
return (value) ret;
}
开发者ID:johnlepikhin,项目名称:mpcap,代码行数:16,代码来源:mpcap_stubs.c
示例19: tcpeek_init_pcap
static void
tcpeek_init_pcap(void) {
char *ifname, errmsg[PCAP_ERRBUF_SIZE], expression[] = "tcp or icmp";
struct bpf_program bpf;
if(strisempty(g.option.ifname)) {
ifname = pcap_lookupdev(errmsg);
if(!ifname) {
error_abort("%s", errmsg);
}
strncpy(g.option.ifname, ifname, sizeof(g.option.ifname) - 1);
}
g.pcap.pcap = pcap_create(g.option.ifname, errmsg);
if(!g.pcap.pcap) {
error_abort("%s", errmsg);
}
if(pcap_set_buffer_size(g.pcap.pcap, g.option.buffer * 1024 * 1024) != 0) {
error_abort("%s", "can not set buffer size");
}
if(pcap_set_snaplen(g.pcap.pcap, DEFAULT_PCAP_SNAPLEN) != 0) {
error_abort("%s", "can not set snaplen");
}
if(pcap_set_promisc(g.pcap.pcap, g.option.promisc) != 0) {
error_abort("%s", "can not set promiscuous mode");
}
if(pcap_set_timeout(g.pcap.pcap, 1) != 0) {
error_abort("%s", "can not set timeout");
}
if(pcap_activate(g.pcap.pcap) != 0) {
error_abort("%s", pcap_geterr(g.pcap.pcap));
}
if(pcap_compile(g.pcap.pcap, &bpf, expression, 0, 0) == -1) {
error_abort("%s '%s'", pcap_geterr(g.pcap.pcap), expression);
}
if(pcap_setfilter(g.pcap.pcap, &bpf) == -1){
error_abort("%s", pcap_geterr(g.pcap.pcap));
}
pcap_freecode(&bpf);
g.pcap.snapshot = pcap_snapshot(g.pcap.pcap);
g.pcap.datalink = pcap_datalink(g.pcap.pcap);
if(g.pcap.datalink != DLT_EN10MB && g.pcap.datalink != DLT_LINUX_SLL) {
error_abort("not support datalink %s (%s)",
pcap_datalink_val_to_name(g.pcap.datalink),
pcap_datalink_val_to_description(g.pcap.datalink)
);
}
}
开发者ID:fchiba,项目名称:tcpeek,代码行数:47,代码来源:init.c
示例20: epcap_open
static int
epcap_open(EPCAP_STATE *ep)
{
char errbuf[PCAP_ERRBUF_SIZE];
if (ep->file) {
PCAP_ERRBUF(ep->p = pcap_open_offline(ep->file, errbuf));
} else {
if (ep->dev == NULL)
PCAP_ERRBUF(ep->dev = pcap_lookupdev(errbuf));
#ifdef HAVE_PCAP_CREATE
PCAP_ERRBUF(ep->p = pcap_create(ep->dev, errbuf));
(void)pcap_set_snaplen(ep->p, ep->snaplen);
(void)pcap_set_promisc(ep->p, ep->opt & EPCAP_OPT_PROMISC);
(void)pcap_set_timeout(ep->p, ep->timeout);
if (ep->bufsz > 0)
(void)pcap_set_buffer_size(ep->p, ep->bufsz);
switch (pcap_activate(ep->p)) {
case 0:
break;
case PCAP_WARNING:
case PCAP_ERROR:
case PCAP_WARNING_PROMISC_NOTSUP:
case PCAP_ERROR_NO_SUCH_DEVICE:
case PCAP_ERROR_PERM_DENIED:
pcap_perror(ep->p, "pcap_activate: ");
exit(EXIT_FAILURE);
default:
exit(EXIT_FAILURE);
}
#else
PCAP_ERRBUF(ep->p = pcap_open_live(ep->dev, ep->snaplen,
ep->opt & EPCAP_OPT_PROMISC, ep->timeout, errbuf));
#endif
/* monitor mode */
#ifdef PCAP_ERROR_RFMON_NOTSUP
if (pcap_can_set_rfmon(ep->p) == 1)
(void)pcap_set_rfmon(ep->p, ep->opt & EPCAP_OPT_RFMON);
#endif
}
ep->datalink = pcap_datalink(ep->p);
return 0;
}
开发者ID:kostyushkin,项目名称:epcap,代码行数:47,代码来源:epcap.c
注:本文中的pcap_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论