[Xorp-hackers] Constructing packets

Pavlin Radoslavov pavlin at ICSI.Berkeley.EDU
Wed Feb 25 02:17:31 PST 2009


Victor Faion <vfaion at gmail.com> wrote:

> Thank you for the help, the embed_*() and extract_*() functions are
> working. I use embed_8() on each character of the string. I don't
> understand when (or if) I need to use the alignment functions in
> AlignData. When I receive the packet now I just use the extract_*()
> functions and everything seems to be aligned.

You don't need AlignData. That class is used only in the FEA when we
need to deal with certain system struct types when they are aligned
with data buffers.

> A sort of related question, I was trying to put a timestamp in a
> packet using TimeVal::sec(). To test the time functions I just did
> this:
> 
> TimeVal now;
> TimerList::system_gettimeofday(&now);
> XLOG_INFO("Time is %s", now.pretty_print().c_str());
> 
> But when I run this I get something like this:
> 
> Time is Thu Apr  6 08:23:07 1972
> 
> even though the system clock is set right and date gives the right
> time. Am I using these functions in the wrong way?

You shouldn't use TimerList::system_gettimeofday() to print
the current time.
Depending on the OS, TimerList::system_gettimeofday() might call
either clock_gettime(CLOCK_MONOTONIC) or gettimeofday(2)
(the former is preferred).
If it is the former, then you get the monotonic time since some
unspecified starting point in the past.

If you really want to print the current time then you can use
xlog_localtime2string() function from libxorp (you must include
header file "libxorp/xlog.h").

Regards,
Pavlin



More information about the Xorp-hackers mailing list