Main Page | Class Hierarchy | Class List | File List | Class Members

PacketHdr Class Reference

A Packet Header class. More...

#include <common.h>

List of all members.

Public Member Functions

void init ()
short getShortIntegerInfo (int position)
int getIntegerInfo (int position)
unsigned 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.

Based on the functions provided in PacketHdr. You can put three datatype in a header by calling those functions:

info_ is defined "unsigned char" because reading a number byte by byte dose not allow any mistakes in type conversion involving the HSB. And both 16-bit and 32-bit data are large enough for any sequence number or other signaling appearing in a short test, so we do not need functions for 64-bit number.

Definition at line 42 of file common.h.


Member Function Documentation

unsigned char* PacketHdr::accessInfo  )  [inline]
 

Get a pointer to the actual information header .

Definition at line 61 of file common.h.

References info_.

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

00061 {return info_;}

int PacketHdr::getIntegerInfo int  position  ) 
 

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

Definition at line 18 of file common.cpp.

References info_.

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

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

get an octet

Definition at line 85 of file common.h.

References info_.

00085 { return info_[position];}

short PacketHdr::getShortIntegerInfo int  position  ) 
 

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

Definition at line 30 of file common.cpp.

References info_.

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

int PacketHdr::getSize  )  [inline]
 

get the length(size) of the header

Definition at line 65 of file common.h.

References length_.

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

00065 { return length_; } 

void PacketHdr::init  )  [inline]
 

Clear all information fileds as empty

Definition at line 49 of file common.h.

References info_.

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

void PacketHdr::setHeaderSize int  len  )  [inline]
 

Set the header size

Definition at line 81 of file common.h.

References length_.

Referenced by Packet::extractHeader().

00081 { length_ =len; }

void PacketHdr::setIntegerInfo int  a,
int  position
 

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

Definition at line 40 of file common.cpp.

References info_, and length_.

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

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 77 of file common.h.

References info_, and length_.

00077 { *(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 50 of file common.cpp.

References info_, and length_.

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


The documentation for this class was generated from the following files:
Generated on Fri Feb 17 17:55:49 2006 for Common_Classes_Projects_ECE544 by  doxygen 1.4.2