Пример #1
0
/**
* Configure, set up and allocate the TUN/TAP device.
*
* If the TUN/TAP device was allocated successfully the file descriptor is returned.
* Otherwise the application closes with an error.
* @note Currently only a TUN device with multi queue is used.
*
* @return The TUN/TAP device file descriptor
*/
int configureAndSetUpTunDevice() {

    std::string tunTapDevice = "tun_nrf24";
    strcpy(tunName, tunTapDevice.c_str());

    //int flags = IFF_TUN | IFF_NO_PI | IFF_MULTI_QUEUE;
	int flags = IFF_TAP | IFF_NO_PI;// | IFF_MULTI_QUEUE;
    tunFd = allocateTunDevice(tunName, flags);
    if (tunFd >= 0) {
        std::cout << "Successfully attached to tun/tap device " << tunTapDevice << std::endl;
    } else {
        std::cerr << "Error allocating tun/tap interface: " << tunFd << std::endl;
        exit(1);
    }

    return tunFd;
}
void TunTapComponent::start()
{
  //LOG(LDEBUG) << "start() called.";

  // Connect to the device
  strcpy(tunName_, tunTapDevice_x.c_str());
  int flags = strstr(tunName_, "tap") == NULL ? IFF_TUN | IFF_NO_PI : IFF_TAP | IFF_NO_PI;
  if ((tunFd_ = allocateTunDevice(tunName_, flags)) >= 0)
  {
    LOG(LINFO) << "Successfully attached to tun/tap device "
      << tunTapDevice_x;
  }
  else
  {
    LOG(LFATAL) << "Error allocating tun/tap interface.";
    return;
  }

  // start thread
  rxThread_.reset(new boost::thread(boost::bind( &TunTapComponent::rxThreadFunction, this)));
}
Пример #3
0
int RF24Gateway::configDevice(uint16_t address){

    std::string tunTapDevice = "tun_nrf24";
    strcpy(tunName, tunTapDevice.c_str());

	int flags;
	if(config_TUN){
      flags = IFF_TUN | IFF_NO_PI | IFF_MULTI_QUEUE;
	}else{
	  flags = IFF_TAP | IFF_NO_PI | IFF_MULTI_QUEUE;
    }
	tunFd = allocateTunDevice(tunName, flags, address);
	#if DEBUG >= 1
    if (tunFd >= 0) {
		std::cout << "RF24Gw: Successfully attached to tun/tap device " << tunTapDevice << std::endl;
    } else {
        std::cerr << "RF24Gw: Error allocating tun/tap interface: " << tunFd << std::endl;
        exit(1);
    }
	#endif
    return tunFd;
}