From 1039ba2bca0d7d79cb4cebfe3217eabe1d0606df Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Sat, 3 Sep 2022 09:02:34 +0000 Subject: [PATCH] gh-96534: socketmodule: support FreeBSD divert(4) socket --- Doc/library/socket.rst | 11 +++++++++++ .../2022-09-03-09-24-02.gh-issue-96534.EU4Oxv.rst | 1 + Modules/socketmodule.c | 13 +++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-09-03-09-24-02.gh-issue-96534.EU4Oxv.rst diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index f97c4f67001633..8535f63d9b09f8 100644 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -498,6 +498,17 @@ Constants .. versionadded:: 3.9 +.. data:: AF_DIVERT + PF_DIVERT + + These two constants, documented in the FreeBSD divert(4) manual page, are + also defined in the socket module. + + .. availability:: FreeBSD >= 14.0. + + .. versionadded:: 3.12 + + .. data:: AF_PACKET PF_PACKET PACKET_* diff --git a/Misc/NEWS.d/next/Library/2022-09-03-09-24-02.gh-issue-96534.EU4Oxv.rst b/Misc/NEWS.d/next/Library/2022-09-03-09-24-02.gh-issue-96534.EU4Oxv.rst new file mode 100644 index 00000000000000..0497d9eb69163e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-09-03-09-24-02.gh-issue-96534.EU4Oxv.rst @@ -0,0 +1 @@ +Support divert(4) added in FreeBSD 14. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 869bacde924d83..f345707a6ba973 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1850,6 +1850,11 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, /* RDS sockets use sockaddr_in: fall-through */ #endif /* AF_RDS */ +#ifdef AF_DIVERT + case AF_DIVERT: + /* FreeBSD divert(4) sockets use sockaddr_in: fall-through */ +#endif /* AF_DIVERT */ + case AF_INET: { struct maybe_idna host = {NULL, NULL}; @@ -7628,6 +7633,14 @@ PyInit__socket(void) PyModule_AddIntMacro(m, AF_SYSTEM); #endif +/* FreeBSD divert(4) */ +#ifdef PF_DIVERT + PyModule_AddIntMacro(m, PF_DIVERT); +#endif +#ifdef AF_DIVERT + PyModule_AddIntMacro(m, AF_DIVERT); +#endif + #ifdef AF_PACKET PyModule_AddIntMacro(m, AF_PACKET); #endif