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

📄 checkxorheader.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * checkxorheader.{cc,hh} -- element checks xor header for correctness * (checksums, lengths) * * Wenjun Hu * * adapted from checksrheader.{cc,hh} by John Bicket * adapted from checkwifiheader.{cc,hh} by Douglas S. J. De Couto * from checkipheader.{cc,hh} by Robert Morris * * Copyright (c) 1999-2000 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/etheraddress.hh>#include <click/glue.hh>#include <clicknet/ether.h>#include <clicknet/ip.h>#include "encodedheader.hh"#include "checkxorheader.hh"CLICK_DECLSCheckXorHeader::CheckXorHeader()  : _drops(0){  add_input();  add_output();}CheckXorHeader::~CheckXorHeader(){}voidCheckXorHeader::notify_noutputs(int n){  set_noutputs(n < 2 ? 1 : 2);}voidCheckXorHeader::drop_it(Packet *p){  if (_drops == 0)    click_chatter("CheckXorHeader %s: first drop", id().cc());  _drops++;    if (noutputs() == 2)    output(1).push(p);  else    p->kill();}Packet *CheckXorHeader::simple_action(Packet *p){  //debugging  click_chatter("\n entering CheckXorHeader::simple_action\n");  click_ether *eh = (click_ether *) p->data();  struct click_xored *xorh = (struct click_xored *) (eh+1);  if (!xorh) {  //debugging  click_chatter("\n in CheckXorHeader::simple_action - no encoded header, packet for drop\n");    drop_it(p);    return 0;  }  if (p->length() < sizeof(struct click_xored)) {     click_chatter("%s: packet truncated", id().cc());    drop_it(p);    return 0;  }  unsigned int tlen = xorh->hlen_with_data();  if (tlen > p->length()) {     /* can only check inequality, as short packets are padded to a       minimum frame size for wavelan and ethernet */    click_chatter("%s: bad packet size, wanted %d, only got %d", id().cc(),		  tlen + sizeof(click_ether), p->length());    drop_it(p);    return 0;  }  if (click_in_cksum((unsigned char *) xorh, tlen) != 0) {    click_chatter("%s: bad xored packet checksum", id().cc());    click_chatter("%s: length: %d, cksum: 0x%.4x", id().cc(), (unsigned long) ntohs(xorh->_cksum));    drop_it(p);    return 0;  }  //debugging  click_chatter("\n leaving CheckXorHeader::simple_action - checks completed\n");  return(p);  }static String CheckXorHeader_read_param(Element *e, void *){  CheckXorHeader *td = (CheckXorHeader *)e;  return "packets dropped: " + String(td->drops()) + "\n";}      voidCheckXorHeader::add_handlers(){  add_read_handler("drops", CheckXorHeader_read_param, 0);}EXPORT_ELEMENT(CheckXorHeader)CLICK_ENDDECLS

⌨️ 快捷键说明

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