You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The linux manpage ipv6(7) states that in6_addr is a C struct containing an unsigned char array[16] with name s6_addr. When compiling a C program, this works:
However, the following Go program does not compile with the error addr.s6_addr undefined (type C.struct_in6_addr has no field or method s6_addr):
package main
// #include <netinet/in.h>// #include <sys/socket.h>import"C"import"fmt"funcmain() {
// See man 7 ipv6varaddr C.struct_in6_addrfmt.Printf("%v", addr.s6_addr)
}
Testing with go tool cgo reveals that the struct used is defined in in.h, and thus using addr.__in6_u works with go.
When the include file linux/in6.h is included, and go tool cgo -- -D__USE_KERNEL_IPV6_DEFS test.go is run, the correct (man page) definition of struct in6_addr shows up in _obj/_cgo_gotypes.go. I do not know how to get go to compile this correctly however.
Go version used is go version go1.3.3 linux/amd64. Contact me if you need any more information.
The text was updated successfully, but these errors were encountered:
As you probably know, this doesn't work because struct in6_addr has no field named s6_addr. Instead, the header file has
#define s6_addr __in6_u.__u6_addr8
So if we are going to fix this, the fix would be to somehow get cgo to recognize defined macro names when they are used as field names. I don't think this is likely to happen any time soon, but I will leave the issue open since it would be nice if it worked.
The linux manpage ipv6(7) states that in6_addr is a C struct containing an unsigned char array[16] with name s6_addr. When compiling a C program, this works:
However, the following Go program does not compile with the error
addr.s6_addr undefined (type C.struct_in6_addr has no field or method s6_addr)
:Testing with
go tool cgo
reveals that the struct used is defined in in.h, and thus usingaddr.__in6_u
works with go.When the include file
linux/in6.h
is included, andgo tool cgo -- -D__USE_KERNEL_IPV6_DEFS test.go
is run, the correct (man page) definition ofstruct in6_addr
shows up in_obj/_cgo_gotypes.go
. I do not know how to get go to compile this correctly however.Go version used is go version go1.3.3 linux/amd64. Contact me if you need any more information.
The text was updated successfully, but these errors were encountered: