[ns] How to create a new packet?

Park, Pusik parksik at keti.re.kr
Mon Feb 23 22:10:42 PST 2004


Hi.

The Packet::alloc function can allocate a Packet class by new operator and initiaize the bits of the Packet.

inline Packet * Packet::alloc()
{
   ....
    Packet * p = new Packet;
    p->bits = new unsigned char[hdrlen];
   ...
}

You can write your own contents on p->bits buffer directly and if you need more variable for your contents, you can create member varialbles of the Packet class e.g. Packet::body, Packet::option, etc.

In addition to the direct modification of contents, you can write your contents with the struct-type variable point.
You can refer the below code.

Packet *p = new Packet;
strcut cmn_hdr *h = p->bits;
h->type = PT_GET;
h->length = 20;
....



----- Original Message ----- 
From: "Shen Ren" <isc10487 at nus.edu.sg>
To: <ns-users at ISI.EDU>
Sent: Thursday, February 19, 2004 1:55 PM
Subject: [ns] How to create a new packet?


> 
> Hi Friends,
>     It is saying that Packet::alloc() could allocate the memory space for it, but how about the content of the packet? how could i fill the content into the packet???
>  
> Thanks.
> Se
> 
> 
> 
> 
> 



More information about the Ns-users mailing list