[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] how can you have a string field in a packet header?



> I have a new packet header type, and am having trouble setting a string
> value in the header.  Int values get set fine, but the simulation crashes
> when I try to set a string.

You can't put a POINTER in the packet header; every field must be concrete
value. the reason is when a packet is new/freed, it does not know how to
handle the pointers in headers, I think. As you can see in message.{h,cc},
using a fixed-size char array is perhaps your only choice if you want to
put it in packet header.

The other way, though more complicated, is to use AppData. The description
in ns manual is obsolete though, I need to update it later this month...
:(

> I use a 'const char *' field for the string (like 'int' for the integer
> fields) in the packet header.  I set the string like this:
> set thisString "string"
> set stringHeaderField $thisString
> 
> And in the parsing of "command" (for the 'send' function), the header
> field string can be printed.  ie:
> printf("The string field in the header is now %s", myHeader->stringValue);
> prints out: "The string field in the header is now string"
> 
> However, the script crashes in the packet 'recv' function.  The error
> message I get, using the GDB debugger, is "no value given for parameter,
> Program exited with code 01".