hdr_ip为ip.h中定义的struct。
在我的印象中,结构体内不能定义函数,所以一直没有弄明白hdr_ip::access( )的含义。
原来C++中,struct的功能类似class,是可以内嵌函数体,只不过struct的所有成员为public,而class的成员默认为private。
struct hdr_ip {
/* common to IPv{4,6} */
ns_addr_t src_;
ns_addr_t dst_;
int ttl_;
/* common to IPv{4,6} */
ns_addr_t src_;
ns_addr_t dst_;
int ttl_;
/* Monarch extn */
// u_int16_t sport_;
// u_int16_t dport_;
/* IPv6 */
int fid_; /* flow id */
int prio_;
// u_int16_t sport_;
// u_int16_t dport_;
/* IPv6 */
int fid_; /* flow id */
int prio_;
static int offset_;
inline static int& offset() { return offset_; }
inline static hdr_ip* access(const Packet* p) {
return (hdr_ip*) p->access(offset_);
}
inline static int& offset() { return offset_; }
inline static hdr_ip* access(const Packet* p) {
return (hdr_ip*) p->access(offset_);
}
。。。。。。
p->access(offset_)的定义在packet.h中:
inline unsigned char* access(int off) const {
if (off < 0)
abort();
return (&bits_[off]);
}
if (off < 0)
abort();
return (&bits_[off]);
}
转载于:https://blog.51cto.com/xgucs/187701