SocketCAN has been part of mainline linux since kernel 2.6.25 (so getting
close to a decade now), and it is pretty much the standard for all CAN bus
communication on linux.

Thanks for the hint, I will look into adding support in the
golang.org/x/sys/unix package.

Regards,
Elliot

On Fri, Jun 24, 2016 at 7:52 PM, Ian Lance Taylor <i...@golang.org> wrote:

> On Fri, Jun 24, 2016 at 8:05 AM,  <ellio...@gmail.com> wrote:
> >
> > I am trying to set up an interface from Go to SocketCAN
> > (https://www.kernel.org/doc/Documentation/networking/can.txt).  This
> > implements the linux socket interface, however it is a completely
> separate
> > socket type from the regular AF_INET or AF_UNIX socket types.
> >
> > The sockaddr struct for SocketCAN looks like this:
> >
> > struct sockaddr_can {
> >     sa_family_t can_family;
> >     int         can_ifindex;
> >     union {
> >         /* transport protocol class address info (e.g. ISOTP) */
> >         struct { canid_t rx_id, tx_id; } tp;
> >
> >         /* reserved for future CAN protocols address information */
> >     } can_addr;
> > };
> >
> >
> > Since the union only has one possible entry right now, this is easy
> enough
> > to write in Go
> >
> > type CanID uint32
> >
> > type sockaddrCan struct {
> >    Family  uint16
> >    IfIndex int32
> >    TpRxId  CanID
> >    TpTxId  CanID
> > }
> >
> >
> > Everything is straight forward so far, but now if I want to pass this to
> > different syscall functions ( syscall.Bind, syscall.Connect, etc.) I
> have to
> > implement the syscall.Sockaddr interface, however looking in the code I
> see
> > this:
> >
> > type Sockaddr interface {
> >     sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) //
> lowercase;
> > only we can define Sockaddrs
> > }
> >
> >
> > So, finally the questions:
> >
> > Why is this interface private? It says that it is, but provides no
> > rationale.
> > Does this mean that I have to reimplement all the functions syscall
> > functions using raw syscall.Syscall?  Or is there some clever way around
> > this so I can use the syscall package to make a Sockaddr type that is not
> > already defined.
>
> If this is going to be a standard thing in future Linux kernels, I
> suggest that you add support for it to the golang.org/x/sys/unix
> package.
>
> I don't actually know the answer to why Sockaddr has a private method.
> I agree that it doesn't seem strictly necessary.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to