| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef MS_WINDOWS |
| 5 |
#ifdef __VMS |
| 6 |
# include <socket.h> |
| 7 |
# else |
| 8 |
# include <sys/socket.h> |
| 9 |
# endif |
| 10 |
# include <netinet/in.h> |
| 11 |
# if !(defined(__BEOS__) || defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))) |
| 12 |
# include <netinet/tcp.h> |
| 13 |
# endif |
| 14 |
|
| 15 |
#else |
| 16 |
# include <winsock2.h> |
| 17 |
# include <ws2tcpip.h> |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
# ifdef SIO_GET_MULTICAST_FILTER |
| 24 |
# include <MSTcpIP.h> |
| 25 |
# define HAVE_ADDRINFO |
| 26 |
# define HAVE_SOCKADDR_STORAGE |
| 27 |
# define HAVE_GETADDRINFO |
| 28 |
# define HAVE_GETNAMEINFO |
| 29 |
# define ENABLE_IPV6 |
| 30 |
# else |
| 31 |
typedef int socklen_t; |
| 32 |
# endif |
| 33 |
#endif |
| 34 |
|
| 35 |
#ifdef HAVE_SYS_UN_H |
| 36 |
# include <sys/un.h> |
| 37 |
#else |
| 38 |
# undef AF_UNIX |
| 39 |
#endif |
| 40 |
|
| 41 |
#ifdef HAVE_LINUX_NETLINK_H |
| 42 |
# ifdef HAVE_ASM_TYPES_H |
| 43 |
# include <asm/types.h> |
| 44 |
# endif |
| 45 |
# include <linux/netlink.h> |
| 46 |
#else |
| 47 |
# undef AF_NETLINK |
| 48 |
#endif |
| 49 |
|
| 50 |
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 51 |
#include <bluetooth/bluetooth.h> |
| 52 |
#include <bluetooth/rfcomm.h> |
| 53 |
#include <bluetooth/l2cap.h> |
| 54 |
#include <bluetooth/sco.h> |
| 55 |
#include <bluetooth/hci.h> |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifdef HAVE_BLUETOOTH_H |
| 59 |
#include <bluetooth.h> |
| 60 |
#endif |
| 61 |
|
| 62 |
#ifdef HAVE_NETPACKET_PACKET_H |
| 63 |
# include <sys/ioctl.h> |
| 64 |
# include <net/if.h> |
| 65 |
# include <netpacket/packet.h> |
| 66 |
#endif |
| 67 |
|
| 68 |
#ifdef HAVE_LINUX_TIPC_H |
| 69 |
# include <linux/tipc.h> |
| 70 |
#endif |
| 71 |
|
| 72 |
#ifndef Py__SOCKET_H |
| 73 |
#define Py__SOCKET_H |
| 74 |
#ifdef __cplusplus |
| 75 |
extern "C" { |
| 76 |
#endif |
| 77 |
|
| 78 |
|
| 79 |
#define PySocket_MODULE_NAME "_socket" |
| 80 |
#define PySocket_CAPI_NAME "CAPI" |
| 81 |
#define PySocket_CAPSULE_NAME (PySocket_MODULE_NAME "." PySocket_CAPI_NAME) |
| 82 |
|
| 83 |
|
| 84 |
#ifdef MS_WINDOWS |
| 85 |
typedef SOCKET SOCKET_T; |
| 86 |
# ifdef MS_WIN64 |
| 87 |
# define SIZEOF_SOCKET_T 8 |
| 88 |
# else |
| 89 |
# define SIZEOF_SOCKET_T 4 |
| 90 |
# endif |
| 91 |
#else |
| 92 |
typedef int SOCKET_T; |
| 93 |
# define SIZEOF_SOCKET_T SIZEOF_INT |
| 94 |
#endif |
| 95 |
|
| 96 |
|
| 97 |
typedef union sock_addr { |
| 98 |
struct sockaddr_in in; |
| 99 |
#ifdef AF_UNIX |
| 100 |
struct sockaddr_un un; |
| 101 |
#endif |
| 102 |
#ifdef AF_NETLINK |
| 103 |
struct sockaddr_nl nl; |
| 104 |
#endif |
| 105 |
#ifdef ENABLE_IPV6 |
| 106 |
struct sockaddr_in6 in6; |
| 107 |
struct sockaddr_storage storage; |
| 108 |
#endif |
| 109 |
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 110 |
struct sockaddr_l2 bt_l2; |
| 111 |
struct sockaddr_rc bt_rc; |
| 112 |
struct sockaddr_sco bt_sco; |
| 113 |
struct sockaddr_hci bt_hci; |
| 114 |
#endif |
| 115 |
#ifdef HAVE_NETPACKET_PACKET_H |
| 116 |
struct sockaddr_ll ll; |
| 117 |
#endif |
| 118 |
} sock_addr_t; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
typedef struct { |
| 125 |
PyObject_HEAD |
| 126 |
SOCKET_T sock_fd; |
| 127 |
int sock_family; |
| 128 |
int sock_type; |
| 129 |
int sock_proto; |
| 130 |
PyObject *(*errorhandler)(void); |
| 131 |
|
| 132 |
|
| 133 |
double sock_timeout; |
| 134 |
|
| 135 |
PyObject *weakreflist; |
| 136 |
} PySocketSockObject; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
typedef struct { |
| 190 |
PyTypeObject *Sock_Type; |
| 191 |
PyObject *error; |
| 192 |
} PySocketModule_APIObject; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
#ifndef PySocket_BUILDING_SOCKET |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
static |
| 218 |
PySocketModule_APIObject PySocketModule; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
#ifndef DPRINTF |
| 225 |
# define DPRINTF if (0) printf |
| 226 |
#endif |
| 227 |
|
| 228 |
static |
| 229 |
int PySocketModule_ImportModuleAndAPI(void) |
| 230 |
{ |
| 231 |
void *api; |
| 232 |
|
| 233 |
DPRINTF(" Loading capsule %s\n", PySocket_CAPSULE_NAME); |
| 234 |
api = PyCapsule_Import(PySocket_CAPSULE_NAME, 1); |
| 235 |
if (api == NULL) |
| 236 |
goto onError; |
| 237 |
memcpy(&PySocketModule, api, sizeof(PySocketModule)); |
| 238 |
DPRINTF(" API object loaded and initialized.\n"); |
| 239 |
return 0; |
| 240 |
|
| 241 |
onError: |
| 242 |
DPRINTF(" not found.\n"); |
| 243 |
return -1; |
| 244 |
} |
| 245 |
|
| 246 |
#endif |
| 247 |
|
| 248 |
#ifdef __cplusplus |
| 249 |
} |
| 250 |
#endif |
| 251 |
#endif |