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; }
/* * Class: disy_jnipcap_Pcap * Method: setTstampType * Signature: (JI)I */ JNIEXPORT jint JNICALL Java_disy_jnipcap_Pcap_setTstampType (JNIEnv *env, jclass jcls, jlong jptr, jint jtype) { pcap_t *p = (pcap_t *) jptr; if (p == NULL) return -1; return (jint) pcap_set_tstamp_type (p, (int) jtype); }
static void prep_pcap_handle(pcap_t *handle) { int err; err = pcap_set_rfmon(handle, options.rfmon); if(err) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); err = pcap_set_promisc(handle, options.promisc); if(err) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); err = pcap_set_snaplen(handle, options.snaplen); if(err) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); err = pcap_set_timeout(handle, options.read_timeout); if(err) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); if(options.buffer_size > 0) { err = pcap_set_buffer_size(handle, options.buffer_size); if(err) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); } if(options.tstamp_type != PCAP_ERROR) { err = pcap_set_tstamp_type(handle, options.tstamp_type); if(err == PCAP_ERROR_ACTIVATED) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); else if(err == PCAP_ERROR_CANTSET_TSTAMP_TYPE) die(0, "pcap_set_tstamp_type(): Device does not support setting the timestamp"); else if(err == PCAP_WARNING_TSTAMP_TYPE_NOTSUP) plog(0, "pcap_set_tstamp_type(): Device does not support specified tstamp type"); } if(options.tstamp_nano) { err = pcap_set_tstamp_precision(handle, PCAP_TSTAMP_PRECISION_NANO); if(err == PCAP_ERROR_ACTIVATED) die(0, "DEBUG: pcap handle should not be activated at %s:%d", __FILE__, __LINE__); else if(err == PCAP_ERROR_TSTAMP_PRECISION_NOTSUP) die(0, "pcap_set_tstamp_precision(): Device does not support nanosecond precision"); } if(options.linktype != PCAP_ERROR) { err = pcap_set_datalink(handle, options.linktype); if(err) die(0, "pcap_set_datalink(): %s", pcap_geterr(handle)); } }
inline int set_timestamp_type(pcap_t *source, const timestamp_t &tstamp) { const auto ts_type = static_cast<int>(tstamp); return pcap_set_tstamp_type(source, ts_type); }