Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 1 | /* Socket module header file */ |
| 2 | |
| 3 | /* Includes needed for the sockaddr_* symbols below */ |
| 4 | #ifndef MS_WINDOWS |
Martin v. Löwis | c16f3bd | 2003-05-03 09:14:54 +0000 | [diff] [blame] | 5 | #ifdef __VMS |
| 6 | # include <socket.h> |
| 7 | # else |
| 8 | # include <sys/socket.h> |
| 9 | # endif |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 10 | # include <netinet/in.h> |
Jesus Cea | 14c81ab | 2012-10-05 02:11:36 +0200 | [diff] [blame] | 11 | # if !defined(__CYGWIN__) |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 12 | # include <netinet/tcp.h> |
| 13 | # endif |
| 14 | |
| 15 | #else /* MS_WINDOWS */ |
Martin v. Löwis | 272cb40 | 2002-03-01 08:31:07 +0000 | [diff] [blame] | 16 | # include <winsock2.h> |
Greg Bowser | 8fbece1 | 2019-08-02 16:29:52 -0400 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * If Windows has bluetooth support, include bluetooth constants. |
| 20 | */ |
| 21 | #ifdef AF_BTH |
| 22 | # include <ws2bth.h> |
| 23 | # include <pshpack1.h> |
| 24 | |
| 25 | /* |
| 26 | * The current implementation assumes the bdaddr in the sockaddr structs |
| 27 | * will be a bdaddr_t. We treat this as an opaque type: on *nix systems, it |
| 28 | * will be a struct with a single member (an array of six bytes). On windows, |
| 29 | * we typedef this to ULONGLONG to match the Windows definition. |
| 30 | */ |
| 31 | typedef ULONGLONG bdaddr_t; |
| 32 | |
| 33 | /* |
| 34 | * Redefine SOCKADDR_BTH to provide names compatible with _BT_RC_MEMB() macros. |
| 35 | */ |
| 36 | struct SOCKADDR_BTH_REDEF { |
| 37 | union { |
| 38 | USHORT addressFamily; |
| 39 | USHORT family; |
| 40 | }; |
| 41 | |
| 42 | union { |
| 43 | ULONGLONG btAddr; |
| 44 | bdaddr_t bdaddr; |
| 45 | }; |
| 46 | |
| 47 | GUID serviceClassId; |
| 48 | |
| 49 | union { |
| 50 | ULONG port; |
| 51 | ULONG channel; |
| 52 | }; |
| 53 | |
| 54 | }; |
| 55 | # include <poppack.h> |
| 56 | #endif |
| 57 | |
Steve Dower | 3e96f32 | 2015-03-02 08:01:10 -0800 | [diff] [blame] | 58 | /* Windows 'supports' CMSG_LEN, but does not follow the POSIX standard |
| 59 | * interface at all, so there is no point including the code that |
| 60 | * attempts to use it. |
| 61 | */ |
| 62 | # ifdef PySocket_BUILDING_SOCKET |
| 63 | # undef CMSG_LEN |
| 64 | # endif |
Martin v. Löwis | 272cb40 | 2002-03-01 08:31:07 +0000 | [diff] [blame] | 65 | # include <ws2tcpip.h> |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 66 | /* VC6 is shipped with old platform headers, and does not have MSTcpIP.h |
| 67 | * Separate SDKs have all the functions we want, but older ones don't have |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 | * any version information. |
Martin v. Löwis | b072cf2 | 2008-06-14 11:59:52 +0000 | [diff] [blame] | 69 | * I use SIO_GET_MULTICAST_FILTER to detect a decent SDK. |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 70 | */ |
Martin v. Löwis | b072cf2 | 2008-06-14 11:59:52 +0000 | [diff] [blame] | 71 | # ifdef SIO_GET_MULTICAST_FILTER |
erikjanss | 6cf8255 | 2018-07-25 02:41:46 +0200 | [diff] [blame] | 72 | # include <mstcpip.h> /* for SIO_RCVALL */ |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 73 | # define HAVE_ADDRINFO |
| 74 | # define HAVE_SOCKADDR_STORAGE |
| 75 | # define HAVE_GETADDRINFO |
| 76 | # define HAVE_GETNAMEINFO |
| 77 | # define ENABLE_IPV6 |
| 78 | # else |
| 79 | typedef int socklen_t; |
| 80 | # endif /* IPPROTO_IPV6 */ |
| 81 | #endif /* MS_WINDOWS */ |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 82 | |
| 83 | #ifdef HAVE_SYS_UN_H |
| 84 | # include <sys/un.h> |
| 85 | #else |
| 86 | # undef AF_UNIX |
| 87 | #endif |
| 88 | |
Martin v. Löwis | 11017b1 | 2006-01-14 18:12:57 +0000 | [diff] [blame] | 89 | #ifdef HAVE_LINUX_NETLINK_H |
Neal Norwitz | 6585166 | 2006-01-16 04:31:40 +0000 | [diff] [blame] | 90 | # ifdef HAVE_ASM_TYPES_H |
| 91 | # include <asm/types.h> |
| 92 | # endif |
Martin v. Löwis | 11017b1 | 2006-01-14 18:12:57 +0000 | [diff] [blame] | 93 | # include <linux/netlink.h> |
| 94 | #else |
| 95 | # undef AF_NETLINK |
| 96 | #endif |
| 97 | |
Bjorn Andersson | bb81651 | 2018-09-26 06:47:52 -0700 | [diff] [blame] | 98 | #ifdef HAVE_LINUX_QRTR_H |
| 99 | # ifdef HAVE_ASM_TYPES_H |
| 100 | # include <asm/types.h> |
| 101 | # endif |
| 102 | # include <linux/qrtr.h> |
| 103 | #else |
| 104 | # undef AF_QIPCRTR |
| 105 | #endif |
| 106 | |
Martin v. Löwis | 12af048 | 2004-01-31 12:34:17 +0000 | [diff] [blame] | 107 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 108 | #include <bluetooth/bluetooth.h> |
| 109 | #include <bluetooth/rfcomm.h> |
| 110 | #include <bluetooth/l2cap.h> |
| 111 | #include <bluetooth/sco.h> |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 112 | #include <bluetooth/hci.h> |
Martin v. Löwis | 12af048 | 2004-01-31 12:34:17 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
Hye-Shik Chang | 96c44658 | 2004-02-02 08:48:45 +0000 | [diff] [blame] | 115 | #ifdef HAVE_BLUETOOTH_H |
| 116 | #include <bluetooth.h> |
| 117 | #endif |
| 118 | |
Nadeem Vawda | d74b593 | 2011-05-15 13:16:22 +0200 | [diff] [blame] | 119 | #ifdef HAVE_NET_IF_H |
| 120 | # include <net/if.h> |
| 121 | #endif |
| 122 | |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 123 | #ifdef HAVE_NETPACKET_PACKET_H |
| 124 | # include <sys/ioctl.h> |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 125 | # include <netpacket/packet.h> |
| 126 | #endif |
| 127 | |
Christian Heimes | 043d6f6 | 2008-01-07 17:19:16 +0000 | [diff] [blame] | 128 | #ifdef HAVE_LINUX_TIPC_H |
| 129 | # include <linux/tipc.h> |
| 130 | #endif |
| 131 | |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 132 | #ifdef HAVE_LINUX_CAN_H |
Serhiy Storchaka | d318715 | 2017-11-09 18:00:38 +0200 | [diff] [blame] | 133 | # include <linux/can.h> |
| 134 | #else |
| 135 | # undef AF_CAN |
| 136 | # undef PF_CAN |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | #ifdef HAVE_LINUX_CAN_RAW_H |
| 140 | #include <linux/can/raw.h> |
| 141 | #endif |
| 142 | |
Charles-François Natali | 773e42d | 2013-02-05 19:42:01 +0100 | [diff] [blame] | 143 | #ifdef HAVE_LINUX_CAN_BCM_H |
| 144 | #include <linux/can/bcm.h> |
| 145 | #endif |
| 146 | |
karl ding | 360371f | 2020-04-29 15:31:19 -0700 | [diff] [blame] | 147 | #ifdef HAVE_LINUX_CAN_J1939_H |
| 148 | #include <linux/can/j1939.h> |
| 149 | #endif |
| 150 | |
Martin v. Löwis | 9d6c669 | 2012-02-03 17:44:58 +0100 | [diff] [blame] | 151 | #ifdef HAVE_SYS_SYS_DOMAIN_H |
| 152 | #include <sys/sys_domain.h> |
| 153 | #endif |
| 154 | #ifdef HAVE_SYS_KERN_CONTROL_H |
| 155 | #include <sys/kern_control.h> |
| 156 | #endif |
| 157 | |
caavery | effc12f | 2017-09-06 18:18:10 -0400 | [diff] [blame] | 158 | #ifdef HAVE_LINUX_VM_SOCKETS_H |
| 159 | # include <linux/vm_sockets.h> |
| 160 | #else |
| 161 | # undef AF_VSOCK |
| 162 | #endif |
| 163 | |
Thomas Herzog | 2d7102e | 2018-09-02 00:13:57 +0200 | [diff] [blame] | 164 | #ifdef HAVE_SOCKADDR_ALG |
Christian Heimes | d37c068 | 2017-02-22 12:12:00 +0100 | [diff] [blame] | 165 | |
Thomas Herzog | 2d7102e | 2018-09-02 00:13:57 +0200 | [diff] [blame] | 166 | # include <linux/if_alg.h> |
| 167 | # ifndef AF_ALG |
| 168 | # define AF_ALG 38 |
| 169 | # endif |
| 170 | # ifndef SOL_ALG |
| 171 | # define SOL_ALG 279 |
| 172 | # endif |
| 173 | |
| 174 | /* Linux 3.19 */ |
| 175 | # ifndef ALG_SET_AEAD_ASSOCLEN |
| 176 | # define ALG_SET_AEAD_ASSOCLEN 4 |
| 177 | # endif |
| 178 | # ifndef ALG_SET_AEAD_AUTHSIZE |
| 179 | # define ALG_SET_AEAD_AUTHSIZE 5 |
| 180 | # endif |
| 181 | /* Linux 4.8 */ |
| 182 | # ifndef ALG_SET_PUBKEY |
| 183 | # define ALG_SET_PUBKEY 6 |
| 184 | # endif |
| 185 | |
| 186 | # ifndef ALG_OP_SIGN |
| 187 | # define ALG_OP_SIGN 2 |
| 188 | # endif |
| 189 | # ifndef ALG_OP_VERIFY |
| 190 | # define ALG_OP_VERIFY 3 |
| 191 | # endif |
Christian Heimes | d37c068 | 2017-02-22 12:12:00 +0100 | [diff] [blame] | 192 | |
| 193 | #endif /* HAVE_SOCKADDR_ALG */ |
| 194 | |
| 195 | |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 196 | #ifndef Py__SOCKET_H |
| 197 | #define Py__SOCKET_H |
| 198 | #ifdef __cplusplus |
| 199 | extern "C" { |
| 200 | #endif |
| 201 | |
| 202 | /* Python module and C API name */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 203 | #define PySocket_MODULE_NAME "_socket" |
| 204 | #define PySocket_CAPI_NAME "CAPI" |
| 205 | #define PySocket_CAPSULE_NAME PySocket_MODULE_NAME "." PySocket_CAPI_NAME |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 206 | |
| 207 | /* Abstract the socket file descriptor type */ |
| 208 | #ifdef MS_WINDOWS |
| 209 | typedef SOCKET SOCKET_T; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 210 | # ifdef MS_WIN64 |
| 211 | # define SIZEOF_SOCKET_T 8 |
| 212 | # else |
| 213 | # define SIZEOF_SOCKET_T 4 |
| 214 | # endif |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 215 | #else |
| 216 | typedef int SOCKET_T; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 217 | # define SIZEOF_SOCKET_T SIZEOF_INT |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 218 | #endif |
| 219 | |
Antoine Pitrou | 67c7ce4 | 2010-08-28 20:42:55 +0000 | [diff] [blame] | 220 | #if SIZEOF_SOCKET_T <= SIZEOF_LONG |
| 221 | #define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd)) |
| 222 | #define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLong(fd) |
| 223 | #else |
| 224 | #define PyLong_FromSocket_t(fd) PyLong_FromLongLong((SOCKET_T)(fd)) |
| 225 | #define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd) |
| 226 | #endif |
| 227 | |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 228 | /* Socket address */ |
| 229 | typedef union sock_addr { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 230 | struct sockaddr_in in; |
Charles-François Natali | 8b75965 | 2011-12-23 16:44:51 +0100 | [diff] [blame] | 231 | struct sockaddr sa; |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 232 | #ifdef AF_UNIX |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 233 | struct sockaddr_un un; |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 234 | #endif |
Martin v. Löwis | 11017b1 | 2006-01-14 18:12:57 +0000 | [diff] [blame] | 235 | #ifdef AF_NETLINK |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 236 | struct sockaddr_nl nl; |
Martin v. Löwis | 11017b1 | 2006-01-14 18:12:57 +0000 | [diff] [blame] | 237 | #endif |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 238 | #ifdef ENABLE_IPV6 |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 239 | struct sockaddr_in6 in6; |
| 240 | struct sockaddr_storage storage; |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 241 | #endif |
Pablo Galindo | 27b33fb | 2019-10-13 02:03:54 +0100 | [diff] [blame] | 242 | #if defined(HAVE_BLUETOOTH_H) && defined(__FreeBSD__) |
| 243 | struct sockaddr_l2cap bt_l2; |
| 244 | struct sockaddr_rfcomm bt_rc; |
| 245 | struct sockaddr_sco bt_sco; |
| 246 | struct sockaddr_hci bt_hci; |
| 247 | #elif defined(HAVE_BLUETOOTH_BLUETOOTH_H) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 248 | struct sockaddr_l2 bt_l2; |
| 249 | struct sockaddr_rc bt_rc; |
| 250 | struct sockaddr_sco bt_sco; |
| 251 | struct sockaddr_hci bt_hci; |
Greg Bowser | 8fbece1 | 2019-08-02 16:29:52 -0400 | [diff] [blame] | 252 | #elif defined(MS_WINDOWS) |
| 253 | struct SOCKADDR_BTH_REDEF bt_rc; |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 254 | #endif |
| 255 | #ifdef HAVE_NETPACKET_PACKET_H |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 256 | struct sockaddr_ll ll; |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 257 | #endif |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 258 | #ifdef HAVE_LINUX_CAN_H |
| 259 | struct sockaddr_can can; |
| 260 | #endif |
Martin v. Löwis | 9d6c669 | 2012-02-03 17:44:58 +0100 | [diff] [blame] | 261 | #ifdef HAVE_SYS_KERN_CONTROL_H |
| 262 | struct sockaddr_ctl ctl; |
| 263 | #endif |
Christian Heimes | d37c068 | 2017-02-22 12:12:00 +0100 | [diff] [blame] | 264 | #ifdef HAVE_SOCKADDR_ALG |
| 265 | struct sockaddr_alg alg; |
| 266 | #endif |
Bjorn Andersson | bb81651 | 2018-09-26 06:47:52 -0700 | [diff] [blame] | 267 | #ifdef AF_QIPCRTR |
| 268 | struct sockaddr_qrtr sq; |
| 269 | #endif |
Serhiy Storchaka | 13ad3b7 | 2017-09-14 09:38:36 +0300 | [diff] [blame] | 270 | #ifdef AF_VSOCK |
caavery | effc12f | 2017-09-06 18:18:10 -0400 | [diff] [blame] | 271 | struct sockaddr_vm vm; |
| 272 | #endif |
Victor Stinner | d565fb9 | 2019-10-10 21:30:20 +0200 | [diff] [blame] | 273 | #ifdef HAVE_LINUX_TIPC_H |
| 274 | struct sockaddr_tipc tipc; |
| 275 | #endif |
Guido van Rossum | 8ee3e5a | 2005-09-14 18:09:42 +0000 | [diff] [blame] | 276 | } sock_addr_t; |
| 277 | |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 278 | /* The object holding a socket. It holds some extra information, |
| 279 | like the address family, which is used to decode socket address |
| 280 | arguments properly. */ |
| 281 | |
| 282 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | PyObject_HEAD |
| 284 | SOCKET_T sock_fd; /* Socket file descriptor */ |
| 285 | int sock_family; /* Address family, e.g., AF_INET */ |
| 286 | int sock_type; /* Socket type, e.g., SOCK_STREAM */ |
| 287 | int sock_proto; /* Protocol type, usually 0 */ |
| 288 | PyObject *(*errorhandler)(void); /* Error handler; checks |
| 289 | errno, returns NULL and |
| 290 | sets a Python exception */ |
Victor Stinner | 71694d5 | 2015-03-28 01:18:54 +0100 | [diff] [blame] | 291 | _PyTime_t sock_timeout; /* Operation timeout in seconds; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 292 | 0.0 means non-blocking */ |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 293 | } PySocketSockObject; |
| 294 | |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 295 | /* --- C API ----------------------------------------------------*/ |
| 296 | |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 297 | /* Short explanation of what this C API export mechanism does |
| 298 | and how it works: |
| 299 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 300 | The _ssl module needs access to the type object defined in |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 301 | the _socket module. Since cross-DLL linking introduces a lot of |
| 302 | problems on many platforms, the "trick" is to wrap the |
| 303 | C API of a module in a struct which then gets exported to |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 304 | other modules via a PyCapsule. |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 305 | |
| 306 | The code in socketmodule.c defines this struct (which currently |
| 307 | only contains the type object reference, but could very |
| 308 | well also include other C APIs needed by other modules) |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 309 | and exports it as PyCapsule via the module dictionary |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 310 | under the name "CAPI". |
| 311 | |
| 312 | Other modules can now include the socketmodule.h file |
| 313 | which defines the needed C APIs to import and set up |
| 314 | a static copy of this struct in the importing module. |
| 315 | |
| 316 | After initialization, the importing module can then |
| 317 | access the C APIs from the _socket module by simply |
| 318 | referring to the static struct, e.g. |
| 319 | |
| 320 | Load _socket module and its C API; this sets up the global |
| 321 | PySocketModule: |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 322 | |
| 323 | if (PySocketModule_ImportModuleAndAPI()) |
| 324 | return; |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 325 | |
| 326 | |
| 327 | Now use the C API as if it were defined in the using |
| 328 | module: |
| 329 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 330 | if (!PyArg_ParseTuple(args, "O!|zz:ssl", |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 331 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 332 | PySocketModule.Sock_Type, |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 333 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 334 | (PyObject*)&Sock, |
| 335 | &key_file, &cert_file)) |
| 336 | return NULL; |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 337 | |
| 338 | Support could easily be extended to export more C APIs/symbols |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 339 | this way. Currently, only the type object is exported, |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 340 | other candidates would be socket constructors and socket |
| 341 | access functions. |
| 342 | |
| 343 | */ |
| 344 | |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 345 | /* C API for usage by other Python modules */ |
| 346 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 347 | PyTypeObject *Sock_Type; |
| 348 | PyObject *error; |
Antoine Pitrou | c4df784 | 2010-12-03 19:59:41 +0000 | [diff] [blame] | 349 | PyObject *timeout_error; |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 350 | } PySocketModule_APIObject; |
Tim Peters | 6f5505a | 2002-02-17 03:58:51 +0000 | [diff] [blame] | 351 | |
Benjamin Peterson | 81c447f | 2009-05-06 02:43:58 +0000 | [diff] [blame] | 352 | #define PySocketModule_ImportModuleAndAPI() PyCapsule_Import(PySocket_CAPSULE_NAME, 1) |
Marc-André Lemburg | 666e70d | 2002-02-25 14:45:40 +0000 | [diff] [blame] | 353 | |
Benjamin Peterson | 2349020 | 2009-08-12 18:11:03 +0000 | [diff] [blame] | 354 | #ifdef __cplusplus |
Marc-André Lemburg | a5d2b4c | 2002-02-16 18:23:30 +0000 | [diff] [blame] | 355 | } |
| 356 | #endif |
| 357 | #endif /* !Py__SOCKET_H */ |