I am writing a Bluetooth utility on Windows in Rust, using winsock2 (but happy to use any other libraries) and have hit a roadblock. The following C++ sample from the Windows Bluetooth Connection Sample is what I am using as a reference:.
SOCKADDR_BTH SockAddrBthServer;
# code to set SockAddrBthServer vals in here
connect(LocalSocket, (struct sockaddr *) &SockAddrBthServer, sizeof(SOCKADDR_BTH));
The structs are defined like so:
typedef struct _SOCKADDR_BTH
{
USHORT addressFamily; // Always AF_BTH
BTH_ADDR btAddr; // Bluetooth device address
GUID serviceClassId; // [OPTIONAL] system will query SDP for port
ULONG port; // RFCOMM channel or L2CAP PSM
} SOCKADDR_BTH, *PSOCKADDR_BTH;
typedef struct sockaddr {
#if (_WIN32_WINNT < 0x0600)
u_short sa_family;
#else
ADDRESS_FAMILY sa_family; // Address family.
#endif //(_WIN32_WINNT < 0x0600)
CHAR sa_data[14]; // Up to 14 bytes of direct address.
} SOCKADDR, *PSOCKADDR, FAR *LPSOCKADDR;
How do I replicate the (struct sockaddr *) &SockAddrBthServer cast from the connect line above in Rust? So far, I'm making use of the winapi, user32 and ws2_32 crates.
Here is the Rust version of the connect function from the ws2_32 crate.
pub unsafe extern "system" fn connect(s: SOCKET, name: *const SOCKADDR, namelen: c_int) -> c_int