📄 xorheader_bak
字号:
#ifndef CLICK_XORHEADERN_HH#define CLICK_XORHEADERN_HH#include <clicknet/ip.h>#include <clicknet/tcp.h>CLICK_SIZE_PACKED_STRUCTURE(struct click_xorn_header {, uint8_t _nentries; uint16_t _cksum; // One unit of the xor header uint16_t _ether_type; uint16_t _nseq; // neighbor sequence no from sr header uint16_t _ipid; // IP ID uint32_t _src; // src IP (along with IP ID, uniquely identifies pkt) uint8_t _ipttl; // IP TTL of the packet you coded uint8_t _alias; // destination of the packet uint16_t _len; void set_entry(int entry_index, uint16_t ether_type, uint16_t ipid, uint32_t src, uint8_t alias, uint16_t len) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; uint16_t *etype_t = (uint16_t*)ndx; etype_t[0] = htons(ether_type); uint16_t *ipid_t = (uint16_t *)(ndx + 2); ipid_t[0] = htons(ipid); uint32_t *src_t = (uint32_t *)(ndx + 4); src_t[0] = src; ndx[8] = alias; uint16_t *len_t = (uint16_t *)(ndx + 9); len_t[0] = htons(len); } uint16_t get_entry_ethtype(int entry_index) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; uint16_t *etype_t = (uint16_t*)ndx; return ntohs(etype_t[0]); } uint16_t get_entry_ipid(int entry_index) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; uint16_t *ipid_t = (uint16_t *)(ndx + 2); return ntohs(ipid_t[0]); } uint32_t get_entry_src(int entry_index) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; uint32_t *src_t = (uint32_t *)(ndx + 4); return src_t[0]; } uint8_t get_entry_alias(int entry_index) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; return ndx[8]; } uint16_t get_entry_len(int entry_index) { uint8_t *ndx = (uint8_t *) (this+1); ndx += (entry_index - 1) * 11; uint16_t *len_t = (uint16_t *)(ndx + 9); return ntohs(len_t[0]); } void set_nentries(int n) { _nentries = n; } static size_t get_hlen(int nentries) { return sizeof(struct click_xorn_header) + sizeof(uint16_t) * nentries + sizeof(uint16_t) * nentries + sizeof(uint32_t) * nentries + sizeof(uint8_t) * nentries + sizeof(uint16_t) * nentries - 11; } size_t nentries() { return _nentries; } void set_checksum() { unsigned int max_len = 0; for (unsigned int i = 0; i < nentries(); i++) { if (get_entry_len(i) > max_len) max_len = get_entry_len(i); } max_len += sizeof(struct click_xorn_header); _cksum = 0; _cksum = click_in_cksum((unsigned char *)this, max_len); }}); #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -