Skip to content

Commit 2debf1e

Browse files
gh-85302: Add support for BTPROTO_SCO on FreeBSD
BTPROTO_SCO has been supported on FreeBSD since 2008.
1 parent 8cd29c2 commit 2debf1e

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

Doc/library/socket.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ created. Socket addresses are represented as follows:
164164

165165
- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is a
166166
:class:`bytes` object containing the Bluetooth address in a
167-
string format. (ex. ``b'12:23:34:45:56:67'``) This protocol is not
168-
supported under FreeBSD.
167+
string format. (ex. ``b'12:23:34:45:56:67'``)
168+
169+
.. versionchanged:: next
170+
FreeBSD support added.
169171

170172
- :const:`AF_ALG` is a Linux-only socket based interface to Kernel
171173
cryptography. An algorithm socket is configured with a tuple of two to four

Lib/test/test_socket.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,9 +2619,7 @@ def testBluetoothConstants(self):
26192619
socket.BTPROTO_HCI
26202620
socket.SOL_HCI
26212621
socket.BTPROTO_L2CAP
2622-
2623-
if not sys.platform.startswith("freebsd"):
2624-
socket.BTPROTO_SCO
2622+
socket.BTPROTO_SCO
26252623

26262624
def testCreateRfcommSocket(self):
26272625
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM) as s:
@@ -2637,8 +2635,7 @@ def testCreateHciSocket(self):
26372635
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) as s:
26382636
pass
26392637

2640-
@unittest.skipIf(sys.platform == "win32" or sys.platform.startswith("freebsd"),
2641-
"windows and freebsd do not support SCO sockets")
2638+
@unittest.skipIf(sys.platform == "win32", "windows does not support SCO sockets")
26422639
def testCreateScoSocket(self):
26432640
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_SCO) as s:
26442641
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for :data:`~socket.BTPROTO_SCO` in sockets on FreeBSD.

Modules/socketmodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,15 +1536,15 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
15361536
return ret;
15371537
#endif
15381538
}
1539+
#endif /* BTPROTO_HCI */
15391540

1540-
#if !defined(__FreeBSD__)
1541+
#ifdef BTPROTO_SCO
15411542
case BTPROTO_SCO:
15421543
{
15431544
struct sockaddr_sco *a = (struct sockaddr_sco *) addr;
15441545
return makebdaddr(&_BT_SCO_MEMB(a, bdaddr));
15451546
}
1546-
#endif /* !__FreeBSD__ */
1547-
#endif /* BTPROTO_HCI */
1547+
#endif /* BTPROTO_SCO */
15481548

15491549
default:
15501550
PyErr_SetString(PyExc_ValueError,
@@ -2149,7 +2149,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
21492149
*len_ret = sizeof *addr;
21502150
return 1;
21512151
}
2152-
#if !defined(__FreeBSD__)
2152+
#endif /* BTPROTO_HCI */
2153+
#ifdef BTPROTO_SCO
21532154
case BTPROTO_SCO:
21542155
{
21552156
const char *straddr;
@@ -2168,8 +2169,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
21682169
*len_ret = sizeof *addr;
21692170
return 1;
21702171
}
2171-
#endif /* !__FreeBSD__ */
2172-
#endif /* BTPROTO_HCI */
2172+
#endif /* BTPROTO_SCO */
21732173
default:
21742174
PyErr_Format(PyExc_OSError,
21752175
"%s(): unknown Bluetooth protocol", caller);
@@ -2719,11 +2719,11 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
27192719
case BTPROTO_HCI:
27202720
*len_ret = sizeof (struct sockaddr_hci);
27212721
return 1;
2722-
#if !defined(__FreeBSD__)
2722+
#endif /* BTPROTO_HCI */
2723+
#ifdef BTPROTO_SCO
27232724
case BTPROTO_SCO:
27242725
*len_ret = sizeof (struct sockaddr_sco);
27252726
return 1;
2726-
#endif /* !__FreeBSD__ */
27272727
#endif /* BTPROTO_HCI */
27282728
default:
27292729
PyErr_SetString(PyExc_OSError, "getsockaddrlen: "

0 commit comments

Comments
 (0)