All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] odd code for loopback option in /src/utils/can/rtcansend.c
@ 2011-08-18 18:58 Andrew Tannenbaum
  2011-08-18 19:19 ` Andrew Tannenbaum
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Tannenbaum @ 2011-08-18 18:58 UTC (permalink / raw)
  To: xenomai

In xenomai-2.5.5.2/src/utils/can/rtcansend.c, the code that handles 
local loopback mode looks like this:

static void print_usage(char *prg)
{
...
             " -L, --loopback=0|1    switch local loopback off or on\n"
...
}

static int loopback=-1;

         switch (opt) {
	...
         case 'L':
             loopback = strtoul(optarg, NULL, 0);
             break;
	...
	}

...
     if (loopback >= 0) {
         ret = rt_dev_setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
                                 &loopback, sizeof(loopback));
         if (ret < 0) {
             fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror(-ret));
             goto failure;
         }
         if (verbose)
             printf("Using loopback=%d\n", loopback);
     }

It looks like the default value for loopback is -1, and if you set it to 
0 or 1, it turns loopback on, which seems strange.  I don't understand 
rt_dev_setsockopt() fully, so I'm not sure if it's a bug - I don't know 
if -1 and 0 and 1 are three separate loopback states, but I think it 
merits attention.  I think either the code is wrong or the help string 
and man page are not clear.

-Andy


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xenomai-help] odd code for loopback option in /src/utils/can/rtcansend.c
  2011-08-18 18:58 [Xenomai-help] odd code for loopback option in /src/utils/can/rtcansend.c Andrew Tannenbaum
@ 2011-08-18 19:19 ` Andrew Tannenbaum
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Tannenbaum @ 2011-08-18 19:19 UTC (permalink / raw)
  To: xenomai, Wolfgang Grandegger

Andrew Tannenbaum wrote:

> It looks like the default value for loopback is -1, and if you set it to
> 0 or 1, it turns loopback on, which seems strange. I don't understand
> rt_dev_setsockopt() fully, so I'm not sure if it's a bug - I don't know
> if -1 and 0 and 1 are three separate loopback states, but I think it
> merits attention. I think either the code is wrong or the help string
> and man page are not clear.

Ah, I see what it's doing.  It's changing an existing state, so there 
are three choices:

-1: no change
0: clear
1: set

So the code looks correct.

-Andy


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-18 19:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-18 18:58 [Xenomai-help] odd code for loopback option in /src/utils/can/rtcansend.c Andrew Tannenbaum
2011-08-18 19:19 ` Andrew Tannenbaum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.