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

📄 packet.hh

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 HH
📖 第 1 页 / 共 5 页
字号:
    skb()->nh.raw = 0;# endif#else				/* User-space and BSD kernel module */    _nh = 0;#endif}/** @brief Return the offset from the packet data to the MAC header. * @return mac_header() - data() * @warning Not useful if !has_mac_header(). */inline intPacket::mac_header_offset() const{    return mac_header() - data();}/** @brief Return the MAC header length. * @return network_header() - mac_header() * * This equals the offset from the MAC header pointer to the network header * pointer. * @warning Not useful if !has_mac_header() or !has_network_header(). */inline uint32_tPacket::mac_header_length() const{    return network_header() - mac_header();}/** @brief Return the offset from the packet data to the network header. * @return network_header() - data() * @warning Not useful if !has_network_header(). */inline intPacket::network_header_offset() const{    return network_header() - data();}/** @brief Return the network header length. * @return transport_header() - network_header() * * This equals the offset from the network header pointer to the transport * header pointer. * @warning Not useful if !has_network_header() or !has_transport_header(). */inline uint32_tPacket::network_header_length() const{    return transport_header() - network_header();}/** @brief Return the offset from the packet data to the IP header. * @return network_header() - mac_header() * @warning Not useful if !has_network_header(). * @sa network_header_offset */inline intPacket::ip_header_offset() const{    return network_header_offset();}/** @brief Return the IP header length. * @return transport_header() - network_header() * * This equals the offset from the network header pointer to the transport * header pointer. * @warning Not useful if !has_network_header() or !has_transport_header(). * @sa network_header_length */inline uint32_tPacket::ip_header_length() const{    return network_header_length();}/** @brief Return the offset from the packet data to the IPv6 header. * @return network_header() - data() * @warning Not useful if !has_network_header(). * @sa network_header_offset */inline intPacket::ip6_header_offset() const{    return network_header_offset();}/** @brief Return the IPv6 header length. * @return transport_header() - network_header() * * This equals the offset from the network header pointer to the transport * header pointer. * @warning Not useful if !has_network_header() or !has_transport_header(). * @sa network_header_length */inline uint32_tPacket::ip6_header_length() const{    return network_header_length();}/** @brief Return the offset from the packet data to the transport header. * @return transport_header() - data() * @warning Not useful if !has_transport_header(). */inline intPacket::transport_header_offset() const{    return transport_header() - data();}/** @brief Unset the transport header pointer. * @post has_transport_header() == false * Does not affect the MAC or network header pointers. */inline voidPacket::clear_transport_header(){#if CLICK_LINUXMODULE	/* Linux kernel module */# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET    skb()->transport_header = ~0U;# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)    skb()->transport_header = 0;# else    skb()->h.raw = 0;# endif#else				/* User-space and BSD kernel module */    _h = 0;#endif}/** @brief Clear all packet annotations. * @param  all  If true, clear all annotations.  If false, clear only Click's *   internal annotations. * * All user annotations and the address annotation are set to zero, the packet * type annotation is set to HOST, the device annotation and all header * pointers are set to null, the timestamp annotation is cleared, and the * next/prev-packet annotations are set to null. * * If @a all is false, then the packet type, device, timestamp, header, and * next/prev-packet annotations are left alone. */inline voidPacket::clear_annotations(bool all){    memset(xanno(), '\0', sizeof(Anno));    if (all) {	set_packet_type_anno(HOST);	set_device_anno(0);	set_timestamp_anno(Timestamp());	clear_mac_header();	clear_network_header();	clear_transport_header();	set_next(0);	set_prev(0);    }}/** @brief Copy most packet annotations from @a p. * @param p source of annotations * * This packet's user annotations, address annotation, packet type annotation, * device annotation, and timestamp annotation are set to the corresponding * annotations from @a p. * * @note The next/prev-packet and header annotations are not copied. */inline voidPacket::copy_annotations(const Packet *p){    *xanno() = *p->xanno();    set_packet_type_anno(p->packet_type_anno());    set_device_anno(p->device_anno());    set_timestamp_anno(p->timestamp_anno());}inline voidPacket::shift_header_annotations(const unsigned char *old_head,				 int32_t extra_headroom){#if CLICK_LINUXMODULE    struct sk_buff *mskb = skb();# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && NET_SKBUFF_DATA_USES_OFFSET    (void) old_head;    mskb->mac_header += (mskb->mac_header == ~0U ? 0 : extra_headroom);    mskb->network_header += (mskb->network_header == ~0U ? 0 : extra_headroom);    mskb->transport_header += (mskb->transport_header == ~0U ? 0 : extra_headroom);# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)    ptrdiff_t shift = (mskb->head - old_head) + extra_headroom;    mskb->mac_header += (mskb->mac_header ? shift : 0);    mskb->network_header += (mskb->network_header ? shift : 0);    mskb->transport_header += (mskb->transport_header ? shift : 0);# else    ptrdiff_t shift = (mskb->head - old_head) + extra_headroom;    mskb->mac.raw += (mskb->mac.raw ? shift : 0);    mskb->nh.raw += (mskb->nh.raw ? shift : 0);    mskb->h.raw += (mskb->h.raw ? shift : 0);# endif#else    ptrdiff_t shift = (_head - old_head) + extra_headroom;    _mac += (_mac ? shift : 0);    _nh += (_nh ? shift : 0);    _h += (_h ? shift : 0);#endif}/** @cond never *//** @brief Return a pointer to the packet's data buffer. * @deprecated Use buffer() instead. */inline const unsigned char *Packet::buffer_data() const{#if CLICK_LINUXMODULE    return skb()->head;#else    return _head;#endif}/** @brief Return a pointer to the address annotation area. * @deprecated Use anno() instead. * * The area is ADDR_ANNO_SIZE bytes long. */inline void *Packet::addr_anno() {    return anno_u8() + addr_anno_offset;}/** @overload */inline const void *Packet::addr_anno() const {    return anno_u8() + addr_anno_offset;}/** @brief Return a pointer to the user annotation area. * @deprecated Use Packet::anno() instead. * * The area is USER_ANNO_SIZE bytes long. */inline void *Packet::user_anno() {    return anno_u8() + user_anno_offset;}/** @overload */inline const void *Packet::user_anno() const {    return anno_u8() + user_anno_offset;}/** @brief Return a pointer to the user annotation area as uint8_ts. * @deprecated Use Packet::anno_u8() instead. */inline uint8_t *Packet::user_anno_u8() {    return anno_u8() + user_anno_offset;}/** @brief overload */inline const uint8_t *Packet::user_anno_u8() const {    return anno_u8() + user_anno_offset;}/** @brief Return a pointer to the user annotation area as uint32_ts. * @deprecated Use Packet::anno_u32() instead. */inline uint32_t *Packet::user_anno_u32() {    return anno_u32() + user_anno_offset / 4;}/** @brief overload */inline const uint32_t *Packet::user_anno_u32() const {    return anno_u32() + user_anno_offset / 4;}/** @brief Return user annotation byte @a i. * @param i annotation index * @pre 0 <= @a i < USER_ANNO_SIZE * @deprecated Use Packet::anno_u8(@a i) instead. */inline uint8_t Packet::user_anno_u8(int i) const {    return anno_u8(user_anno_offset + i);}/** @brief Set user annotation byte @a i. * @param i annotation index * @param v value * @pre 0 <= @a i < USER_ANNO_SIZE * @deprecated Use Packet::set_anno_u8(@a i, @a v) instead. */inline void Packet::set_user_anno_u8(int i, uint8_t v) {    set_anno_u8(user_anno_offset + i, v);}/** @brief Return 16-bit user annotation @a i. * @param i annotation index * @pre 0 <= @a i < USER_ANNO_U16_SIZE * @deprecated Use Packet::anno_u16(@a i * 2) instead. * * Affects user annotation bytes [2*@a i, 2*@a i+1]. */inline uint16_t Packet::user_anno_u16(int i) const {    return anno_u16(user_anno_offset + i * 2);}/** @brief Set 16-bit user annotation @a i. * @param i annotation index * @param v value * @pre 0 <= @a i < USER_ANNO_U16_SIZE * @deprecated Use Packet::set_anno_u16(@a i * 2, @a v) instead. * * Affects user annotation bytes [2*@a i, 2*@a i+1]. */inline void Packet::set_user_anno_u16(int i, uint16_t v) {    set_anno_u16(user_anno_offset + i * 2, v);}/** @brief Return 32-bit user annotation @a i. * @param i annotation index * @pre 0 <= @a i < USER_ANNO_U32_SIZE * @deprecated Use Packet::anno_u32(@a i * 4) instead. * * Affects user annotation bytes [4*@a i, 4*@a i+3]. */inline uint32_t Packet::user_anno_u32(int i) const {    return anno_u32(user_anno_offset + i * 4);}/** @brief Set 32-bit user annotation @a i. * @param i annotation index * @param v value * @pre 0 <= @a i < USER_ANNO_U32_SIZE * @deprecated Use Packet::set_anno_u32(@a i * 4, @a v) instead. * * Affects user annotation bytes [4*@a i, 4*@a i+3]. */inline void Packet::set_user_anno_u32(int i, uint32_t v) {    set_anno_u32(user_anno_offset + i * 4, v);}/** @brief Return 32-bit user annotation @a i. * @param i annotation index * @pre 0 <= @a i < USER_ANNO_U32_SIZE * @deprecated Use Packet::anno_s32(@a i * 4) instead. * * Affects user annotation bytes [4*@a i, 4*@a i+3]. */inline int32_t Packet::user_anno_s32(int i) const {    return anno_s32(user_anno_offset + i * 4);}/** @brief Set 32-bit user annotation @a i. * @param i annotation index * @param v value * @pre 0 <= @a i < USER_ANNO_U32_SIZE * @deprecated Use Packet::set_anno_s32(@a i * 4, @a v) instead. * * Affects user annotation bytes [4*@a i, 4*@a i+3]. */inline void Packet::set_user_anno_s32(int i, int32_t v) {    set_anno_s32(user_anno_offset + i * 4, v);}#if HAVE_INT64_TYPES/** @brief Return 64-bit user annotation @a i. * @param i annotation index * @pre 0 <= @a i < USER_ANNO_U64_SIZE * @deprecated Use Packet::anno_u64(@a i * 8) instead. * * Affects user annotation bytes [8*@a i, 8*@a i+7]. */inline uint64_t Packet::user_anno_u64(int i) const {    return anno_u64(user_anno_offset + i * 8);}/** @brief Set 64-bit user annotation @a i. * @param i annotation index * @param v value * @pre 0 <= @a i < USER_ANNO_U64_SIZE * @deprecated Use Packet::set_anno_u64(@a i * 8, @a v) instead. * * Affects user annotation bytes [8*@a i, 8*@a i+7]. */inline void Packet::set_user_anno_u64(int i, uint64_t v) {    set_anno_u64(user_anno_offset + i * 8, v);}#endif/** @brief Return a pointer to the user annotation area. * @deprecated Use anno() instead. */inline const uint8_t *Packet::all_user_anno() const {    return anno_u8() + user_anno_offset;}/** @overload * @deprecated Use anno() instead. */inline uint8_t *Packet::all_user_anno() {    return anno_u8() + user_anno_offset;}/** @brief Return a pointer to the user annotation area as uint32_ts. * @deprecated Use anno_u32() instead. */inline const uint32_t *Packet::all_user_anno_u() const {    return anno_u32() + user_anno_offset / 4;}/** @overload * @deprecated Use anno_u32() instead. */inline uint32_t *Packet::all_user_anno_u() {    return anno_u32() + user_anno_offset / 4;}/** @brief Return user annotation byte @a i. * @deprecated Use anno_u8() instead. */inline uint8_t Packet::user_anno_c(int i) const {    return anno_u8(user_anno_offset + i);}/** @brief Set user annotation byte @a i. * @deprecated Use set_anno_u8() instead. */inline void Packet::set_user_anno_c(int i, uint8_t v) {    set_anno_u8(user_anno_offset + i, v);}/** @brief Return 16-bit user annotation @a i. * @deprecated Use anno_u16() instead. */inline uint16_t Packet::user_anno_us(int i) const {    return anno_u16(user_anno_offset + i * 2);}/** @brief Set 16-bit user annotation @a i. * @deprecated Use set_anno_u16() instead. */inline void Packet::set_user_anno_us(int i, uint16_t v) {    set_anno_u16(user_anno_offset + i * 2, v);}/** @brief Return 16-bit user annotation @a i. * @deprecated Use anno_u16() instead. */inline int16_t Packet::user_anno_s(int i) const {    return (int16_t) anno_u16(user_anno_offset + i * 2);}/** @brief Set 16-bit user annotation @a i. * @deprecated Use set_anno_u16() instead. */inline void Packet::set_user_anno_s(int i, int16_t v) {    set_anno_u16(user_anno_offset + i * 2, v);}/** @brief Return 32-bit user annotation @a i. * @deprecated Use anno_u32() instead. */inline uint32_t Packet::u

⌨️ 快捷键说明

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