Re: [ns] Help: accessing contents of data payload in NS2
There are many options to circunvent this issue and use packet payloads. Some more elegant, some less elegant. A more elegant is to use a new class inherited from AppData, ready to manipulate a real payload, and more, ready to manipulate real objects, or everything you want. (you must implement a virtual copy() and a virtual destructor of this class to use inheritance. So, the packet may be copied and destructed). A less elegant is use a pointer in the packet's header (a new packet type for your app). This pointer will be "your packet payload", so it may carry what you want. You may use a buffer of payloads as a onipresent entity (like in BitTorrent.patch from Kolja Eger). Many options, but you'll not carry a real packet payload (with everything you want) in a standard NS-2. Sidney Doria UFCG / BRAZIL 2010/4/6 MiLo_TUD : > > > Oh, sorry. You used PacketData. > But how did you wrote your payload to your packet ? > > I see, there's a problem. setdata(..) want a pointer to the class AppData. > And you don't have direct access to the unsigned char* data_ of PacketData. > So you can't create a new object with data inside. It is only possible to > create an empty packet or copy an existing packet of type PacketData. > So you have to derive a class from class PacketData or change the the class > PacketData. > > > -- > View this message in context: > http://old.nabble.com/Help%3A-accessing-contents-of-data-payload-in-NS2-tp28115846p28153305.html > Sent from the ns-users mailing list archive at Nabble.com. > > -- Sidney Doria Redes ad hoc móveis Doutorado em Computação UFCG Brasil "Nessa jornada, o conhecimento será o seu escudo..." (Mestre dos Magos no episódio do grimoire de ouro)
Re: [ns] Help: accessing contents of data payload in NS2
Oh, sorry. You used PacketData. But how did you wrote your payload to your packet ? I see, there's a problem. setdata(..) want a pointer to the class AppData. And you don't have direct access to the unsigned char* data_ of PacketData. So you can't create a new object with data inside. It is only possible to create an empty packet or copy an existing packet of type PacketData. So you have to derive a class from class PacketData or change the the class PacketData. -- View this message in context: http://old.nabble.com/Help%3A-accessing-contents-of-data-payload-in-NS2-tp28115846p28153305.html Sent from the ns-users mailing list archive at Nabble.com.
Re: [ns] Help: accessing contents of data payload in NS2
O S wrote: > > > if((PacketData*)p->userdata()!=NULL) { > PacketData* packdata = (PacketData*)p->userdata(); > char* pdata = (char*)packdata->data(); > printf("data = %c\n", pdata); > } > > if (p->accessdata()!=NULL){ > data_char = p->accessdata(); > printf("data = %c and p->datalength = %d real length = %d \n", > data_char, p->datalen(), ((PacketData*)(p->userdata()))->size() ); > } > > > "data_" is a pointer to the class "AppData" . 1. so it is no good idea to cast to a pointer of "char" . try to avoid type casting ! this is not a good programmer's style and resolves in faults. 2. the class AppData is only a interface for different types of payload. so you have to specify the type of payload and the data. maybe you can use the class "PacketData" for your purposes. regards mike -- View this message in context: http://old.nabble.com/Help%3A-accessing-contents-of-data-payload-in-NS2-tp28115846p28132310.html Sent from the ns-users mailing list archive at Nabble.com.
Re: [ns] Help: accessing contents of data payload in NS2
Hi, I'm also want to know how to access the contents of the data payload. Please help me too.. -- Regards, yogalakshmi