hdr_ip::access()的理解

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_;
 /* Monarch extn */
//  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_);
 }
。。。。。。
 
p->access(offset_)的定義在packet.h中:
inline unsigned char* access(int off) const {
  if (off < 0)
   abort();
  return (&bits_[off]);
 }
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章