WiimoteReal: fix Linux Bluetooth connectivity on Linux >= 3.5

An uninitialized struct member "l2_bdaddr_type" was making most connect calls
fail with "Invalid argument". The connection could succeed if the unitialized
memory happened to have a zero byte in the appropriate location.
This commit is contained in:
Ryan Hitchman 2015-01-09 22:28:05 -08:00
parent 1e39fd825d
commit c1b391d08b
1 changed files with 3 additions and 3 deletions

View File

@ -166,7 +166,7 @@ WiimoteLinux::~WiimoteLinux()
// Connect to a wiimote with a known address.
bool WiimoteLinux::ConnectInternal()
{
sockaddr_l2 addr;
sockaddr_l2 addr = {};
addr.l2_family = AF_BLUETOOTH;
addr.l2_bdaddr = m_bdaddr;
addr.l2_cid = 0;
@ -176,7 +176,7 @@ bool WiimoteLinux::ConnectInternal()
if ((m_cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_cmd_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{
DEBUG_LOG(WIIMOTE, "Unable to open output socket to wiimote.");
DEBUG_LOG(WIIMOTE, "Unable to open output socket to wiimote: %s", strerror(errno));
close(m_cmd_sock);
m_cmd_sock = -1;
return false;
@ -187,7 +187,7 @@ bool WiimoteLinux::ConnectInternal()
if ((m_int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_int_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{
DEBUG_LOG(WIIMOTE, "Unable to open input socket from wiimote.");
DEBUG_LOG(WIIMOTE, "Unable to open input socket from wiimote: %s", strerror(errno));
close(m_int_sock);
close(m_cmd_sock);
m_int_sock = m_cmd_sock = -1;