#include <GenericPacketParser.h>
Inheritance diagram for GenericPacketParser:
Public Member Functions | |
char * | encapsulatePayload (cMessage *msg, unsigned int *length) |
Convert a cMessage to a data block for sending it to the tun device. | |
cMessage * | decapsulatePayload (char *buf, unsigned int length) |
Parses a block of data received from the tun device. | |
Private Attributes | |
cNetCommBuffer | commBuffer |
cMessage * GenericPacketParser::decapsulatePayload | ( | char * | buf, | |
unsigned int | length | |||
) | [virtual] |
Parses a block of data received from the tun device.
Pure virtual function, has to be implemented by inherited classes.
buf | The data to be parsed | |
length | The length of the data |
Implements PacketParser.
00043 { 00044 commBuffer.reset(); 00045 commBuffer.pack(buf, length); 00046 cMessage* msg; 00047 00048 try { 00049 msg = check_and_cast<cMessage*>(commBuffer.unpackObject()); 00050 // } catch (cRuntimeError err) { 00051 // FIXME: 00052 // the above does, for some reason, not work. So we catch everyting, 00053 // which may prevent the simulation from terminating corectly while 00054 // parsing a message. 00055 } catch (...) { 00056 ev << "GenericPacketParser: parsing of payload failed.\n"; 00057 return NULL; 00058 } 00059 00060 return msg; 00061 }
char * GenericPacketParser::encapsulatePayload | ( | cMessage * | msg, | |
unsigned int * | length | |||
) | [virtual] |
Convert a cMessage to a data block for sending it to the tun device.
Pure virtual function, has to be implemented by inherited classes.
msg | A pointer to the message to be converted | |
length | A pointer to an integer that will hold the length of the data |
Implements PacketParser.
00031 { 00032 commBuffer.reset(); 00033 commBuffer.packObject(msg); 00034 00035 *length = commBuffer.getMessageSize(); 00036 char* byte_buf = new char[*length]; 00037 memcpy(byte_buf, commBuffer.getBuffer(), *length); 00038 00039 return byte_buf; 00040 }