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

📄 ipencap2.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * ipencap2.{cc,hh} -- element encapsulates packet in IP header * Alexander Yip * Based on IPEncap. * * Copyright (c) 2001 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 following * conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Further elaboration of this license, including a DISCLAIMER OF ANY * WARRANTY, EXPRESS OR IMPLIED, is provided in the LICENSE file, which is * also accessible at http://www.pdos.lcs.mit.edu/click/license.html */#include <click/config.h>#include "ipencap2.hh"#include <click/ipaddress.hh>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/standard/alignmentinfo.hh>IPEncap2::IPEncap2()  : Element(1, 1), _ip_p(-1){}IPEncap2::~IPEncap2(){}intIPEncap2::configure(Vector<String> &conf, ErrorHandler *errh){  unsigned char ip_p_uc;  if (cp_va_parse(conf, this, errh,		  cpByte, "IP encapsulation protocol", &ip_p_uc,		  cpIPAddress, "source IP address", &_ip_src,		  cpEnd) < 0)    return -1;  _ip_p = ip_p_uc;#ifdef __KERNEL__  // check alignment  {    int ans, c, o;    ans = AlignmentInfo::query(this, 0, c, o);    _aligned = (ans && c == 4 && o == 0);    if (!_aligned)      errh->warning("IP header unaligned, cannot use fast IP checksum");    if (!ans)      errh->message("(Try passing the configuration through `click-align'.)");  }#endif    return 0;}intIPEncap2::initialize(ErrorHandler *){  _id = 0;  return 0;}Packet *IPEncap2::simple_action(Packet *p_in){  WritablePacket *p = p_in->push(sizeof(click_ip));  click_ip *ip = reinterpret_cast<click_ip *>(p->data());    ip->ip_v = 4;  ip->ip_hl = sizeof(click_ip) >> 2;  ip->ip_len = htons(p->length());  ip->ip_id = htons(_id++);  ip->ip_p = _ip_p;  ip->ip_src = _ip_src;  ip->ip_dst = p_in->dst_ip_anno().in_addr();  ip->ip_tos = 0;  ip->ip_off = 0;  ip->ip_ttl = 250;  ip->ip_sum = 0;#ifdef __KERNEL__  if (_aligned) {    ip->ip_sum = ip_fast_csum((unsigned char *)ip, sizeof(click_ip) >> 2);  } else {#endif  ip->ip_sum = click_in_cksum((unsigned char *)ip, sizeof(click_ip));#ifdef __KERNEL__  }#endif    p->set_dst_ip_anno(IPAddress(ip->ip_dst));  p->set_ip_header(ip, sizeof(click_ip));    return p;}static Stringread_handler(Element *, void *){  return "false\n";}voidIPEncap2::add_handlers(){  // needed for QuitWatcher  add_read_handler("scheduled", read_handler, 0);}//ELEMENT_REQUIRES(false)EXPORT_ELEMENT(IPEncap2)

⌨️ 快捷键说明

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