RealworldApp.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #include "RealworldApp.h"
00026 
00027 
00028 Define_Module(RealworldApp);
00029 
00030 char* RealworldApp::encapsulate(cPacket *msg,
00031                                 unsigned int* length,
00032                                 sockaddr** addr,
00033                                 socklen_t* addrlen)
00034 {
00035     unsigned int payloadLen;
00036     *addr = 0;
00037     *addrlen = 0;
00038 
00039     // parse payload
00040     char* payload = parser->encapsulatePayload(msg, &payloadLen);
00041     if (!payload )
00042         return NULL;
00043 
00044     if(payloadLen > 0xffff) {
00045         opp_error("RealworldApp: Encapsulating packet failed: packet too long");
00046     }
00047     *length = payloadLen;
00048 
00049     return payload;
00050 }
00051 
00052 cPacket* RealworldApp::decapsulate(char* buf,
00053                                    uint32_t length,
00054                                    sockaddr* addr,
00055                                    socklen_t addrlen)
00056 {
00057     cPacket* payload = 0;
00058     // "Decode" packet: 16bit payload length|payload
00059     payload = parser->decapsulatePayload( buf, length );
00060     if (!payload) {
00061         EV << "[RealworldApp::decapsulate()]\n"
00062            << "    Parsing of Payload failed, dropping packet"
00063            << endl;
00064     }
00065 
00066     delete buf;
00067     return payload;
00068     delete addr; // FIXME: unreachable
00069 }
00070 
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3