PacketHdr Class Reference

A Packet Header class. More...

#include <common.h>

List of all members.

Public Member Functions

 PacketHdr ()
void init ()
short getShortIntegerInfo (int position)
int getIntegerInfo (int position)
char * accessInfo ()
int getSize ()
void setIntegerInfo (int a, int position)
void setShortIntegerInfo (short b, int position)
void setOctet (unsigned char c, int position)
void setHeaderSize (int len)
unsigned char getOctet (int position)

Protected Attributes

unsigned char * info_
 pointer to the header's content
int length_
 length of the header


Detailed Description

A Packet Header class.

Packethdr is an entity which represents the packet header portion of a packet. Important protocol information fields are stored in the header.

Definition at line 32 of file common.h.


Member Function Documentation

char* PacketHdr::accessInfo  )  [inline]
 

Get a pointer to the actual information header .

Definition at line 51 of file common.h.

References info_.

Referenced by Packet::extractHeader(), and Packet::makePacket().

00051 {return info_;}

int PacketHdr::getIntegerInfo int  position  ) 
 

read the information filed at "postion" as a 32-bit integer

Definition at line 16 of file common.cpp.

References info_.

00017 {
00018   int val;
00019   unsigned char *p = info_ +position;
00020   val = *(p++);
00021   val = val << 8 | *(p++);
00022   val = val << 8 | *(p++);
00023   val = val << 8 | *(p++);
00024 
00025   return val;
00026 }

unsigned char PacketHdr::getOctet int  position  )  [inline]
 

get an octet

Definition at line 75 of file common.h.

References info_.

00075 { return info_[position];}

short PacketHdr::getShortIntegerInfo int  position  ) 
 

read the information filed at "postion" as a short integer

Definition at line 28 of file common.cpp.

References info_.

00029 {
00030   short val;
00031   unsigned char *p = info_ + position;
00032   val = *(p++);
00033   val = val << 8 | *(p++);
00034 
00035   return val;
00036 }

int PacketHdr::getSize  )  [inline]
 

get the length(size) of the header

Definition at line 55 of file common.h.

References length_.

Referenced by Packet::getHeaderSize(), and Packet::makePacket().

00055 { return length_; } 

void PacketHdr::init  )  [inline]
 

Clear all information fileds as empty

Definition at line 39 of file common.h.

References info_.

00039 {memset(info_,0,MAX_HEADER_SIZE );}

void PacketHdr::setHeaderSize int  len  )  [inline]
 

Set the header size

Definition at line 71 of file common.h.

References length_.

Referenced by Packet::extractHeader().

00071 { length_ =len; }

void PacketHdr::setIntegerInfo int  a,
int  position
 

set a 4-byte(32-bit) information field with an integer

Definition at line 38 of file common.cpp.

References info_, and length_.

00039 {
00040   unsigned char *p = info_ + position;
00041   *(p++) =  a >> 24;
00042   *(p++) = (a >> 16) & 0xFF;
00043   *(p++) = (a >> 8) & 0xFF;
00044   *(p++) =  a & 0xFF;
00045   length_ +=4;
00046 }

void PacketHdr::setOctet unsigned char  c,
int  position
[inline]
 

set one octet as a desired character An octet in computer networking is an eight bit quantity

Definition at line 67 of file common.h.

References info_, and length_.

00067 { *(info_+position)= c; length_++;}

void PacketHdr::setShortIntegerInfo short  b,
int  position
 

set a 2-byte(16-bit) information field with an short integer

Definition at line 48 of file common.cpp.

References info_, and length_.

00049 {
00050   unsigned char *p = info_ + position;
00051   *(p++) =  b >> 8;
00052   *(p++) =  b & 0xFF;
00053   length_+=2;
00054 }


The documentation for this class was generated from the following files:
Generated on Fri Feb 9 12:49:37 2007 for Common_Classes_Projects_ECE544 by  doxygen 1.4.6