I'm trying to open an RFCOMM socket from Go. I have a test setup where the client connects to an echo server. The part that I'm stuck on is setting up the Bluetooth address. In C you have str2ba, which converts the MAC string to a byte array of six elements. In Go it appears it expects the device to be a uint16. I'm not sure how this would work.
package main
import (
"fmt"
"log"
"syscall"
"golang.org/x/sys/unix"
)
func main() {
fd, err := unix.Socket(syscall.AF_BLUETOOTH, syscall.SOCK_STREAM, unix.BTPROTO_RFCOMM)
if err != nil {
log.Fatalf("%v
", err)
}
addr := unix.SockaddrHCI{Dev: 1, Channel: 1}
unix.Connect(fd, addr)
unix.Write(fd, []byte("Hello"))
var data []byte
unix.Read(fd, data)
fmt.Printf("Received: %v
", string(data))
}
The Dev
member in unix.SockaddrHCI
is a uint16 and I think this is to represent the Bluetooth MAC. Is this correct?
Thanks.