diff options
author | Christian Pointner <equinox@anytun.org> | 2007-06-18 18:50:41 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2007-06-18 18:50:41 +0000 |
commit | 2a49fd31380e3b4fb041ee919eb429f074008924 (patch) | |
tree | f477e2c102d597967d5ea0be4960f6d4f532758d /package.cpp | |
parent | bugfix @buffer resize (diff) |
added header functions to package
Diffstat (limited to 'package.cpp')
-rw-r--r-- | package.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/package.cpp b/package.cpp index b008a67..e41c7a0 100644 --- a/package.cpp +++ b/package.cpp @@ -28,7 +28,103 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <arpa/inet.h> + #include "datatypes.h" #include "package.h" +Package::Package() +{ + header_ = 0; + payload_type_ = 0; + auth_tag_ = 0; +} + +Package::Package(u_int32_t length) : Buffer(length) +{ + header_ = 0; + payload_type_ = 0; + auth_tag_ = 0; +} + +Package::Package(const Buffer &src) : Buffer(src) +{ + header_ = 0; + payload_type_ = 0; + auth_tag_ = 0; +} + +bool Package::hasHeader() const +{ + return header_; +} + +Package& Package::withHeader(bool b) +{ + if(b && length_ >= sizeof(struct HeaderStruct)) + header_ = reinterpret_cast<struct HeaderStruct*>(buf_); + else + header_ = 0; + + return *this; +} + +seq_nr_t Package::getSeqNr() const +{ + if(!header_) + return 0; + + return SEQ_NR_T_NTOH(header_->seq_nr); +} + +sender_id_t Package::getSenderId() const +{ + if(!header_) + return 0; + + return SENDER_ID_T_NTOH(header_->sender_id); +} + +Package& Package::addHeader(seq_nr_t seq_nr, sender_id_t sender_id) +{ + if(!header_) + { + if(sizeof(struct HeaderStruct) > resizeFront(length_ + sizeof(struct HeaderStruct))) + return *this; + + header_ = reinterpret_cast<struct HeaderStruct*>(buf_); + } + header_->seq_nr = SEQ_NR_T_HTON(seq_nr); + header_->sender_id = SENDER_ID_T_HTON(sender_id); + return *this; +} + +Package& Package::removeHeader() +{ + if(!header_) + return *this; + + if(length_ >= sizeof(struct HeaderStruct)) + resizeFront(length_ - sizeof(struct HeaderStruct)); + + header_ = 0; + + return *this; +} + +Package& Package::setSeqNr(seq_nr_t seq_nr) +{ + if(header_) + header_->seq_nr = SEQ_NR_T_HTON(seq_nr); + + return *this; +} + +Package& Package::setSenderId(sender_id_t sender_id) +{ + if(header_) + header_->sender_id = SENDER_ID_T_HTON(sender_id); + + return *this; +} |