Hello All,

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:

   1. Why is this interface private? It says that it is, but provides no 
   rationale. 
   2. 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.

Thanks in advance.

Elliot

-- 
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