Skip to content
Prev Previous commit
Next Next commit
Fix BTPROTO_HCI on FreeBSD
  • Loading branch information
vstinner committed Apr 1, 2025
commit 99dcf45d39e64e2065f983f6a3972b554981cf06
15 changes: 15 additions & 0 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,21 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
straddr = PyBytes_AS_STRING(args);
if (setbdaddr(straddr, &_BT_HCI_MEMB(addr, bdaddr)) < 0)
return 0;
#elif defined(__FreeBSD__)
_BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
if (!PyBytes_Check(args)) {
PyErr_Format(PyExc_OSError, "%s: "
"wrong node format", caller);
return 0;
}
const char *straddr = PyBytes_AS_STRING(args);
size_t len = PyBytes_GET_SIZE(args);
if (len >= sizeof(_BT_HCI_MEMB(addr, node))) {
Comment thread
vstinner marked this conversation as resolved.
Outdated
PyErr_Format(PyExc_OSError, "%s: "
"node too long", caller);
return 0;
}
strcpy(_BT_HCI_MEMB(addr, node), straddr);
#else /* __NetBSD__ || __DragonFly__ */
_BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
unsigned short dev = _BT_HCI_MEMB(addr, dev);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it defined?

Copy link
Copy Markdown
Member

@picnixz picnixz Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of define at the top of the file:

#if (defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)) \
     && !defined(__NetBSD__) && !defined(__DragonFly__)
#define USE_BLUETOOTH 1
#if defined(__FreeBSD__)
...
#define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb)
...
#elif defined(__NetBSD__) || defined(__DragonFly__) // <- unreachable
... 
#define _BT_HCI_MEMB(sa, memb) ((sa)->bt_##memb)
#else
...
#define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb)
...
#endif
#endif

But AFAICT, the elif defined(__NetBSD__) || defined(__DragonFly__) is not possible at all since we're still in the big #if where we want !defined(__NetBSD__) && !defined(__DragonFly__). So indeed, it looks like the macro wouldn't be defined here.

I think we should remove !defined(__NetBSD__) && !defined(__DragonFly__)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know about _BT_HCI_MEMB. I asked on what platform the *_dev member is defined, what its name and the structure name. Its turned out that it is hci_node on FreeBSD and NetBSD. hci_dev should exist on Linux.

Expand Down
Loading