xokwriter.cc

来自「COPE the first practical network coding 」· CC 代码 · 共 82 行

CC
82
字号
#include <click/config.h>#include "xokwriter.hh"#include <click/error.hh>#include <click/confparse.hh>#include <stdio.h>#include <unistd.h>extern "C" {#include <vos/net/fast_eth.h>#include <vos/net/ae_ether.h>extern int iptable_find_if_name(const char *);}#define dprintf if (0) printfxokWriter::xokWriter(int c)  : Element(1, 0), cardno(c){}xokWriter::xokWriter(const String &ifname)  : Element(1, 0){  const char *name = ifname.data();  cardno = iptable_find_if_name(name);  if (cardno < 0)    fprintf(stderr,"interface %s not found\n",name);}intxokWriter::configure(Vector<String> &conf, ErrorHandler *errh){  String _ifname;  int r = cp_va_parse(conf, this, errh, cpString, 	              "interface name", &_ifname, cpEnd);  if (r < 0) return r;  const char *name = _ifname.data();  dprintf("xokWriter: looking for interface .%s.\n", name);  cardno = iptable_find_if_name(name);  dprintf("it is at %d\n",cardno);  if (cardno < 0)  {    errh->error("interface not found");    return -1;  }  return 0;}voidxokWriter::push(int port, Packet *p){  assert(p->length() >= 14);  assert(cardno >= 0);  int r = ae_eth_send(p->data(), p->length(), cardno);  if (r < 0)    fprintf(stderr, "xokWriter: write to card %d failed, packet dropped\n", 	    cardno);    p->kill();}voidxokWriter::run_scheduled(){  while (Packet *p = input(0).pull())    push(0, p);}EXPORT_ELEMENT(xokWriter)

⌨️ 快捷键说明

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