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

📄 ipsumdump_ip.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
📖 第 1 页 / 共 2 页
字号:
	  if (d.iph) {	      off = d.p->transport_header_offset();	      if (d.tcph && d.p->transport_length() >= 13)		  off += (d.tcph->th_off << 2);	      else if (d.udph)		  off += sizeof(click_udp);	      len = ntohs(d.iph->ip_len) - off + d.p->network_header_offset();	      if (len + off > d.p->length()) // EXTRA_LENGTH?		  len = d.p->length() - off;	  } else {	      off = 0;	      len = d.p->length();	  }	  String s = String::stable_string((const char *)(d.p->data() + off), len);	  *d.sa << cp_quote(s);	  break;      }    }} #define U DO_IPOPT_UNKNOWNstatic int ip_opt_mask_mapping[] = {    DO_IPOPT_PADDING, DO_IPOPT_PADDING,		// EOL, NOP    U, U, U, U,	U,				// 2, 3, 4, 5, 6    DO_IPOPT_ROUTE,				// RR    U, U, U, U, U, U, U, U, U, U, U, U, U, 	// 8-20    U, U, U, U, U, U, U, U, U, U, 		// 21-30    U, U, U, U, U, U, U, U, U, U, 		// 31-40    U, U, U, U, U, U, U, U, U, U, 		// 41-50    U, U, U, U, U, U, U, U, U, U, 		// 51-60    U, U, U, U, U, U, U,	 		// 61-67    DO_IPOPT_TS, U, U,				// TS, 69-70    U, U, U, U, U, U, U, U, U, U, 		// 71-80    U, U, U, U, U, U, U, U, U, U, 		// 81-90    U, U, U, U, U, U, U, U, U, U, 		// 91-100    U, U, U, U, U, U, U, U, U, U, 		// 101-110    U, U, U, U, U, U, U, U, U, U, 		// 111-120    U, U, U, U, U, U, U, U, U,			// 121-129    DO_IPOPT_UNKNOWN, DO_IPOPT_ROUTE,		// SECURITY, LSRR    U, U, U, U,					// 132-135    DO_IPOPT_UNKNOWN, DO_IPOPT_ROUTE, 		// SATID, SSRR    U, U, U,					// 138-140    U, U, U, U, U, U, U,	 		// 141-147    DO_IPOPT_UNKNOWN				// RA};#undef Uvoid unparse_ip_opt(StringAccum& sa, const uint8_t* opt, int opt_len, int mask){    int initial_sa_len = sa.length();    const uint8_t *end_opt = opt + opt_len;    const char *sep = "";        while (opt < end_opt)	switch (*opt) {	  case IPOPT_EOL:	    if (mask & DO_IPOPT_PADDING)		sa << sep << "eol";	    goto done;	  case IPOPT_NOP:	    if (mask & DO_IPOPT_PADDING) {		sa << sep << "nop";		sep = ";";	    }	    opt++;	    break;	  case IPOPT_RR:	    if (opt + opt[1] > end_opt || opt[1] < 3 || opt[2] < 4)		goto bad_opt;	    if (!(mask & DO_IPOPT_ROUTE))		goto unknown;	    sa << sep << "rr";	    goto print_route;	  case IPOPT_LSRR:	    if (opt + opt[1] > end_opt || opt[1] < 3 || opt[2] < 4)		goto bad_opt;	    if (!(mask & DO_IPOPT_ROUTE))		goto unknown;	    sa << sep << "lsrr";	    goto print_route;	  case IPOPT_SSRR:	    if (opt + opt[1] > end_opt || opt[1] < 3 || opt[2] < 4)		goto bad_opt;	    if (!(mask & DO_IPOPT_ROUTE))		goto unknown;	    sa << sep << "ssrr";	    goto print_route;	  print_route: {		const uint8_t *o = opt + 3, *ol = opt + opt[1], *op = opt + opt[2] - 1;		sep = "";		sa << '{';		for (; o + 4 <= ol; o += 4) {		    if (o == op) {			if (opt[0] == IPOPT_RR)			    break;			sep = "^";		    }		    sa << sep << (int)o[0] << '.' << (int)o[1] << '.' << (int)o[2] << '.' << (int)o[3];		    sep = ",";		}		if (o == ol && o == op && opt[0] != IPOPT_RR)		    sa << '^';		sa << '}';		if (o + 4 <= ol && o == op && opt[0] == IPOPT_RR)		    sa << '+' << (ol - o) / 4;		opt = ol;		sep = ";";		break;	    }	  case IPOPT_TS: {	      if (opt + opt[1] > end_opt || opt[1] < 4 || opt[2] < 5)		  goto bad_opt;	      const uint8_t *o = opt + 4, *ol = opt + opt[1], *op = opt + opt[2] - 1;	      int flag = opt[3] & 0xF;	      int size = (flag >= 1 && flag <= 3 ? 8 : 4);	      sa << sep << "ts";	      if (flag == 1)		  sa << ".ip";	      else if (flag == 3)		  sa << ".preip";	      else if (flag != 0)		  sa << "." << flag;	      sa << '{';	      sep = "";	      for (; o + size <= ol; o += 4) {		  if (o == op) {		      if (flag != 3)			  break;		      sep = "^";		  }		  if (flag != 0) {		      sa << sep << (int)o[0] << '.' << (int)o[1] << '.' << (int)o[2] << '.' << (int)o[3] << '=';		      o += 4;		  } else		      sa << sep;		  if (flag == 3 && o > op)		      sa.pop_back();		  else {		      uint32_t v = (o[0] << 24) | (o[1] << 16) | (o[2] << 8) | o[3];		      if (v & 0x80000000U)			  sa << '!';		      sa << (v & 0x7FFFFFFFU);		  }		  sep = ",";	      }	      if (o == ol && o == op)		  sa << '^';	      sa << '}';	      if (o + size <= ol && o == op)		  sa << '+' << (ol - o) / size;	      if (opt[3] & 0xF0)		  sa << '+' << '+' << (opt[3] >> 4);	      opt = ol;	      sep = ";";	      break;	  }	  default: {	      if (opt + opt[1] > end_opt || opt[1] < 2)		  goto bad_opt;	      if (!(mask & DO_IPOPT_UNKNOWN))		  goto unknown;	      sa << sep << (int)(opt[0]);	      const uint8_t *end_this_opt = opt + opt[1];	      char opt_sep = '=';	      for (opt += 2; opt < end_this_opt; opt++) {		  sa << opt_sep << (int)(*opt);		  opt_sep = ':';	      }	      sep = ";";	      break;	  }	  unknown:	    opt += (opt[1] >= 2 ? opt[1] : 128);	    break;	}  done:    if (sa.length() == initial_sa_len)	sa << '.';    return;  bad_opt:    sa.set_length(initial_sa_len);    sa << '?';}void unparse_ip_opt(StringAccum& sa, const click_ip* iph, int mask){    unparse_ip_opt(sa, reinterpret_cast<const uint8_t *>(iph + 1), (iph->ip_hl << 2) - sizeof(click_ip), mask);}void unparse_ip_opt_binary(StringAccum& sa, const uint8_t *opt, int opt_len, int mask){    if (mask == (int)DO_IPOPT_ALL) {	// store all options	sa.append((char)opt_len);	sa.append(opt, opt_len);    }    const uint8_t *end_opt = opt + opt_len;    int initial_sa_len = sa.length();    sa.append('\0');        while (opt < end_opt) {	// one-byte options	if (*opt == IPOPT_EOL) {	    if (mask & DO_IPOPT_PADDING)		sa.append(opt, 1);	    goto done;	} else if (*opt == IPOPT_NOP) {	    if (mask & DO_IPOPT_PADDING)		sa.append(opt, 1);	    opt++;	    continue;	}		// quit copying options if you encounter something obviously invalid	if (opt[1] < 2 || opt + opt[1] > end_opt)	    break;	int this_content = (*opt > IPOPT_RA ? (int)DO_IPOPT_UNKNOWN : ip_opt_mask_mapping[*opt]);	if (mask & this_content)	    sa.append(opt, opt[1]);	opt += opt[1];    }  done:    sa[initial_sa_len] = sa.length() - initial_sa_len - 1;}void unparse_ip_opt_binary(StringAccum& sa, const click_ip *iph, int mask){    unparse_ip_opt_binary(sa, reinterpret_cast<const uint8_t *>(iph + 1), (iph->ip_hl << 2) - sizeof(click_ip), mask);}void ip_register_unparsers(){    register_unparser("ip_src", T_IP_SRC | B_4NET, ip_prepare, ip_extract, ip_outa, outb, inb);    register_unparser("ip_dst", T_IP_DST | B_4NET, ip_prepare, ip_extract, ip_outa, outb, inb);    register_unparser("ip_tos", T_IP_TOS | B_1, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_ttl", T_IP_TTL | B_1, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_frag", T_IP_FRAG | B_1, ip_prepare, ip_extract, ip_outa, outb, inb);    register_unparser("ip_fragoff", T_IP_FRAGOFF | B_2, ip_prepare, ip_extract, ip_outa, outb, inb);    register_unparser("ip_id", T_IP_ID | B_2, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_sum", T_IP_SUM | B_2, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_proto", T_IP_PROTO | B_1, ip_prepare, ip_extract, ip_outa, outb, inb);    register_unparser("ip_len", T_IP_LEN | B_4, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_capture_len", T_IP_CAPTURE_LEN | B_4, ip_prepare, ip_extract, num_outa, outb, inb);    register_unparser("ip_opt", T_IP_OPT | B_SPECIAL, ip_prepare, ip_extract, ip_outa, ip_outb, ip_inb);    register_unparser("sport", T_SPORT | B_2, ip_prepare, transport_extract, num_outa, outb, inb);    register_unparser("dport", T_DPORT | B_2, ip_prepare, transport_extract, num_outa, outb, inb);    register_unparser("payload_len", T_PAYLOAD_LEN | B_4, ip_prepare, transport_extract, num_outa, outb, inb);    register_unparser("payload", T_PAYLOAD | B_NOTALLOWED, ip_prepare, transport_extract, transport_outa, 0, 0);    register_synonym("length", "ip_len");    register_synonym("ip_p", "ip_proto");    register_synonym("payload_length", "payload_len");}}ELEMENT_REQUIRES(userlevel IPSummaryDump)ELEMENT_PROVIDES(IPSummaryDump_IP)CLICK_ENDDECLS

⌨️ 快捷键说明

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