⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settxrate.cc

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 CC
字号:
/* * settxrate.{cc,hh} -- sets wifi txrate annotation on a packet * John Bicket * * Copyright (c) 2003 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/packet_anno.hh>#include "settxrate.hh"#include <clicknet/ether.h>#include <click/etheraddress.hh>#include <clicknet/wifi.h>CLICK_DECLSSetTXRate::SetTXRate(){}SetTXRate::~SetTXRate(){}intSetTXRate::configure(Vector<String> &conf, ErrorHandler *errh){  _rate = 0;  _et = 0;  _offset = 0;  _tries = WIFI_MAX_RETRIES+1;  if (cp_va_kparse(conf, this, errh,		   "RATE", cpkP, cpUnsigned, &_rate,		   "TRIES", 0, cpUnsigned, &_tries,		   "ETHTYPE", 0, cpUnsignedShort, &_et,		   "OFFSET", 0, cpUnsigned, &_offset,		   cpEnd) < 0) {    return -1;  }  if (_rate < 0) {	  return errh->error("RATE must be >= 0");  }  if (_tries < 1) {	  return errh->error("TRIES must be >= 0");  }  return 0;}Packet *SetTXRate::simple_action(Packet *p_in){  uint8_t *dst_ptr = (uint8_t *) p_in->data() + _offset;  click_ether *eh = (click_ether *) dst_ptr;  if (_et && eh->ether_type != htons(_et)) {    return p_in;  }  struct click_wifi_extra *ceh = WIFI_EXTRA_ANNO(p_in);  ceh->magic = WIFI_EXTRA_MAGIC;  ceh->rate = _rate ? _rate : 2;  ceh->max_tries = _tries;  return p_in;}enum {H_RATE, H_TRIES};StringSetTXRate::read_handler(Element *e, void *thunk){  SetTXRate *foo = (SetTXRate *)e;  switch((uintptr_t) thunk) {  case H_RATE: return String(foo->_rate) + "\n";  case H_TRIES: return String(foo->_tries) + "\n";  default:   return "\n";  }}intSetTXRate::write_handler(const String &arg, Element *e,			 void *vparam, ErrorHandler *errh){  SetTXRate *f = (SetTXRate *) e;  String s = cp_uncomment(arg);  switch((intptr_t)vparam) {  case H_RATE: {    unsigned m;    if (!cp_unsigned(s, &m))      return errh->error("rate parameter must be unsigned");    f->_rate = m;    break;  }  case H_TRIES: {    unsigned m;    if (!cp_unsigned(s, &m))      return errh->error("tries parameter must be unsigned");    f->_tries = m;    break;  }  }  return 0;}voidSetTXRate::add_handlers(){  add_read_handler("rate", read_handler, (void *) H_RATE);  add_read_handler("tries", read_handler, (void *) H_TRIES);  add_write_handler("rate", write_handler, (void *) H_RATE);  add_write_handler("tries", write_handler, (void *) H_TRIES);}CLICK_ENDDECLSEXPORT_ELEMENT(SetTXRate)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -