Environment: Ubuntu 18.04
In my C++-based project, I have two different applications:
- A Bluetooth server
- A Bluetooth client
Once the BT server runs on one box, my BT client from another box can connect to the server app using the specified Bluetooth MAC address.
The Bluetooth MAC address is currently obtained by running "hciconfig hci0" on the server box. However, I would like to display this address programmatically.
Here is my BT initialization code on the server:
int s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
// bind socket to port 1 of the first available
// local bluetooth adapter
bdaddr_t bdaddrAny = {{0, 0, 0, 0, 0, 0}};
sockaddr_rc locAddr = {0, {0, 0, 0, 0, 0, 0}, 0};
locAddr.rc_family = AF_BLUETOOTH;
locAddr.rc_bdaddr = bdaddrAny;
locAddr.rc_channel = (uint8_t)1;
bind(s, (struct sockaddr *)&locAddr, sizeof(locAddr));
char addr[19] = {0};
ba2str(&locAddr.rc_bdaddr, addr);
fprintf(stderr, "BT server MAC address %s\n", addr);
However, even after a successful bind, the displayed address is 00:00:00:00:00:00.
Can someone please show me the correct way to obtain the MAC address of the BT socket the server is bound to? Regards.