Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.c @ 13667:a6c7bfdd6777 legacy-trunk
Even more ANSIfication: fix as many function pointers and declarations as
possible.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Sat, 22 Jul 2000 23:57:55 +0000 |
| parents | 8a063423e0b7 |
| children | 9f6189e89212 |
| rev | line source |
|---|---|
| 294 | 1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
5 All rights reserved. |
| 294 | 6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13171
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 294 | 9 ******************************************************************/ |
| 10 | |
| 11 /* Socket module */ | |
| 12 | |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
13 /* SSL support based on patches by Brian E Gallew and Laszlo Kovacs */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
14 |
| 294 | 15 /* |
| 16 This module provides an interface to Berkeley socket IPC. | |
| 17 | |
| 18 Limitations: | |
| 19 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
20 - only AF_INET and AF_UNIX address families are supported |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
21 - no read/write operations (use send/recv or makefile instead) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
22 - additional restrictions apply on Windows |
| 294 | 23 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
24 Module interface: |
| 294 | 25 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
26 - socket.error: exception raised for socket specific errors |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
27 - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
28 - socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...]) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
29 - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com') |
|
4783
feba6d58d204
Added the new getprotobyname() call to the module overview at the top.
Guido van Rossum <guido@python.org>
parents:
4782
diff
changeset
|
30 - socket.getprotobyname(protocolname) --> protocol number |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
31 - socket.getservbyname(servicename, protocolname) --> port number |
|
309
382323f92fce
Connection sockets now have the proper family/type/proto values.
Guido van Rossum <guido@python.org>
parents:
295
diff
changeset
|
32 - socket.socket(family, type [, proto]) --> new socket object |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
33 - socket.ntohs(16 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
34 - socket.ntohl(32 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
35 - socket.htons(16 bit value) --> new int object |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
36 - socket.htonl(32 bit value) --> new int object |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
37 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h> |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
38 - socket.inet_aton(IP address) -> 32-bit packed IP representation |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
39 - socket.inet_ntoa(packed IP) -> IP address string |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
40 - socket.ssl(socket, keyfile, certfile) -> new ssl object |
| 294 | 41 - an Internet socket address is a pair (hostname, port) |
| 42 where hostname can be anything recognized by gethostbyname() | |
| 43 (including the dd.dd.dd.dd notation) and port is in host byte order | |
| 44 - where a hostname is returned, the dd.dd.dd.dd notation is used | |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
45 - a UNIX domain socket address is a string specifying the pathname |
| 294 | 46 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
47 Socket methods: |
| 294 | 48 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
49 - s.accept() --> new socket object, sockaddr |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
50 - s.bind(sockaddr) --> None |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
51 - s.close() --> None |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
52 - s.connect(sockaddr) --> None |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
53 - s.connect_ex(sockaddr) --> 0 or errno (handy for e.g. async connect) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
54 - s.fileno() --> file descriptor |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
55 - s.dup() --> same as socket.fromfd(os.dup(s.fileno(), ...) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
56 - s.getpeername() --> sockaddr |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
57 - s.getsockname() --> sockaddr |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
58 - s.getsockopt(level, optname[, buflen]) --> int or string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
59 - s.listen(backlog) --> None |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
60 - s.makefile([mode[, bufsize]]) --> file object |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
61 - s.recv(buflen [,flags]) --> string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
62 - s.recvfrom(buflen [,flags]) --> string, sockaddr |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
63 - s.send(string [,flags]) --> nbytes |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
64 - s.sendto(string, [flags,] sockaddr) --> nbytes |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
65 - s.setblocking(0 | 1) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
66 - s.setsockopt(level, optname, value) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
67 - s.shutdown(how) --> None |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
68 - repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>" |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
69 |
| 294 | 70 */ |
| 71 | |
| 1970 | 72 #include "Python.h" |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
73 |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
74 /* Hacks for gethostbyname_r(). On some non-Linux platforms, the configure |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
75 script doesn't get this right, so we hardcode some platform checks below. |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
76 On the other hand, not all Linux versions agree, so there the settings |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
77 computed by the configure script are needed! */ |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
78 |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
79 #ifndef linux |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
80 #undef HAVE_GETHOSTBYNAME_R_3_ARG |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
81 #undef HAVE_GETHOSTBYNAME_R_5_ARG |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
82 #undef HAVE_GETHOSTBYNAME_R_6_ARG |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
83 #endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
84 |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
85 #ifndef WITH_THREAD |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
86 #undef HAVE_GETHOSTBYNAME_R |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
87 #endif |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
88 |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
89 #ifdef HAVE_GETHOSTBYNAME_R |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
90 #if defined(_AIX) || defined(__osf__) |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
91 #define HAVE_GETHOSTBYNAME_R_3_ARG |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
92 #elif defined(__sun__) || defined(__sgi) |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
93 #define HAVE_GETHOSTBYNAME_R_5_ARG |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
94 #elif defined(linux) |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
95 /* Rely on the configure script */ |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
96 #else |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
97 #undef HAVE_GETHOSTBYNAME_R |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
98 #endif |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
99 #endif |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
100 |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
101 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
102 #define USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
103 #endif |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
104 |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
105 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9095
diff
changeset
|
106 #include "pythread.h" |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
107 #endif |
| 294 | 108 |
| 4600 | 109 #ifdef HAVE_UNISTD_H |
| 110 #include <unistd.h> | |
| 111 #endif | |
| 112 | |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
113 #if !defined(MS_WINDOWS) && !defined(PYOS_OS2) && !defined(__BEOS__) |
|
13667
a6c7bfdd6777
Even more ANSIfication: fix as many function pointers and declarations as
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
114 extern int gethostname(char *, size_t); /* For Solaris, at least */ |
|
4651
6effd10e7233
Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
115 #endif |
|
6effd10e7233
Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
116 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
117 #if defined(PYCC_VACPP) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
118 #include <types.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
119 #include <io.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
120 #include <sys/ioctl.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
121 #include <utils.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
122 #include <ctype.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
123 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
124 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
125 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
126 #define INCL_DOS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
127 #define INCL_DOSERRORS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
128 #define INCL_NOPMAPI |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
129 #include <os2.h> |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
130 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
131 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
132 #if defined(__BEOS__) |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
133 /* It's in the libs, but not the headers... - [cjh] */ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
134 int shutdown( int, int ); |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
135 #endif |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
136 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
137 #include <sys/types.h> |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
138 #include "mytime.h" |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
139 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
140 #include <signal.h> |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
141 #ifndef MS_WINDOWS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
142 #include <netdb.h> |
| 294 | 143 #include <sys/socket.h> |
| 144 #include <netinet/in.h> | |
| 12712 | 145 #ifndef __BEOS__ |
|
12194
4dd8b6a3b9c5
Add '#include <netinet/tcp.h>'
Andrew M. Kuchling <amk@amk.ca>
parents:
12050
diff
changeset
|
146 #include <netinet/tcp.h> |
| 12712 | 147 #endif |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
148 |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
149 /* Headers needed for inet_ntoa() and inet_addr() */ |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
150 #ifdef __BEOS__ |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
151 #include <net/netdb.h> |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
152 #else |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
153 #ifndef USE_GUSI1 |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
154 #include <arpa/inet.h> |
|
11288
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
155 #endif |
|
11438
be25aaca11f4
Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents:
11288
diff
changeset
|
156 #endif |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
157 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
158 #include <fcntl.h> |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
159 #else |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
160 #include <winsock.h> |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
161 #include <fcntl.h> |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
162 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
163 #ifdef HAVE_SYS_UN_H |
| 294 | 164 #include <sys/un.h> |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
165 #else |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
166 #undef AF_UNIX |
|
1271
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
167 #endif |
|
2919b448e385
* Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
168 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
169 #ifndef O_NDELAY |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
170 #define O_NDELAY O_NONBLOCK /* For QNX only? */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
171 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
172 |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
173 #ifdef USE_GUSI1 |
|
3390
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
174 /* fdopen() isn't declared in stdio.h (sigh) */ |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
175 #include <GUSI.h> |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
176 #endif |
|
832f26d0e069
Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents:
3335
diff
changeset
|
177 |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
178 #ifdef USE_SSL |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
179 #include "rsa.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
180 #include "crypto.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
181 #include "x509.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
182 #include "pem.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
183 #include "ssl.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
184 #include "err.h" |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
185 #endif /* USE_SSL */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
186 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
187 #if defined(MS_WINDOWS) || defined(__BEOS__) |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
188 /* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
189 /* seem to be a few differences in the API */ |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
190 #define SOCKETCLOSE closesocket |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
191 #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
192 #endif |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
193 |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
194 /* abstract the socket file descriptor type */ |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
195 #ifdef MS_WINDOWS |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
196 typedef SOCKET SOCKET_T; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
197 # ifdef MS_WIN64 |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
198 # define SIZEOF_SOCKET_T 8 |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
199 # else |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
200 # define SIZEOF_SOCKET_T 4 |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
201 # endif |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
202 #else |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
203 typedef int SOCKET_T; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
204 # define SIZEOF_SOCKET_T SIZEOF_INT |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
205 #endif |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
206 |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
207 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
208 #if defined(PYOS_OS2) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
209 #define SOCKETCLOSE soclose |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
210 #define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
211 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
212 |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
213 #ifndef SOCKETCLOSE |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
214 #define SOCKETCLOSE close |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
215 #endif |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
216 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
217 /* Global variable holding the exception type for errors detected |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
218 by this module (but not argument type or memory errors, etc.). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
219 |
| 1970 | 220 static PyObject *PySocket_Error; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
221 |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
222 #ifdef USE_SSL |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
223 static PyObject *SSLErrorObject; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
224 #endif /* USE_SSL */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
225 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
226 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
227 /* Convenience function to raise an error according to errno |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
228 and return a NULL pointer from a function. */ |
| 294 | 229 |
| 1970 | 230 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
231 PySocket_Err(void) |
| 294 | 232 { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
233 #ifdef MS_WINDOWS |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
234 if (WSAGetLastError()) { |
| 1970 | 235 PyObject *v; |
| 236 v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error"); | |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
237 if (v != NULL) { |
| 1970 | 238 PyErr_SetObject(PySocket_Error, v); |
| 239 Py_DECREF(v); | |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
240 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
241 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
242 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
243 else |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
244 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
245 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
246 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
247 if (sock_errno() != NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
248 APIRET rc; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
249 ULONG msglen; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
250 char outbuf[100]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
251 int myerrorcode = sock_errno(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
252 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
253 /* Retrieve Socket-Related Error Message from MPTN.MSG File */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
254 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
255 myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
256 if (rc == NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
257 PyObject *v; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
258 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
259 outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
260 if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
261 char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
262 while (lastc > outbuf && isspace(*lastc)) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
263 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
264 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
265 v = Py_BuildValue("(is)", myerrorcode, outbuf); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
266 if (v != NULL) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
267 PyErr_SetObject(PySocket_Error, v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
268 Py_DECREF(v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
269 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
270 return NULL; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
271 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
272 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
273 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
274 |
| 1970 | 275 return PyErr_SetFromErrno(PySocket_Error); |
| 294 | 276 } |
| 277 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
278 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
279 /* The object holding a socket. It holds some extra information, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
280 like the address family, which is used to decode socket address |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
281 arguments properly. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
282 |
| 294 | 283 typedef struct { |
| 1970 | 284 PyObject_HEAD |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
285 SOCKET_T sock_fd; /* Socket file descriptor */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
286 int sock_family; /* Address family, e.g., AF_INET */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
287 int sock_type; /* Socket type, e.g., SOCK_STREAM */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
288 int sock_proto; /* Protocol type, usually 0 */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
289 union sock_addr { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
290 struct sockaddr_in in; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
291 #ifdef AF_UNIX |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
292 struct sockaddr_un un; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
293 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
294 } sock_addr; |
| 1970 | 295 } PySocketSockObject; |
| 294 | 296 |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
297 #ifdef USE_SSL |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
298 |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
299 typedef struct { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
300 PyObject_HEAD |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
301 PySocketSockObject *Socket; /* Socket on which we're layered */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
302 PyObject *x_attr; /* Attributes dictionary */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
303 SSL_CTX* ctx; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
304 SSL* ssl; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
305 X509* server_cert; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
306 BIO* sbio; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
307 char server[256]; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
308 char issuer[256]; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
309 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
310 } SSLObject; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
311 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
312 staticforward PyTypeObject SSL_Type; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
313 staticforward PyObject *SSL_SSLwrite(SSLObject *self, PyObject *args); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
314 staticforward PyObject *SSL_SSLread(SSLObject *self, PyObject *args); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
315 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
316 #define SSLObject_Check(v) ((v)->ob_type == &SSL_Type) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
317 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
318 #endif /* USE_SSL */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
319 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
320 /* A forward reference to the Socktype type object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
321 The Socktype variable contains pointers to various functions, |
| 1970 | 322 some of which call newsockobject(), which uses Socktype, so |
|
374
70a18a6689d4
Make Socktype global so old and new compilers will like it.
Guido van Rossum <guido@python.org>
parents:
324
diff
changeset
|
323 there has to be a circular reference. */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
324 |
| 1970 | 325 staticforward PyTypeObject PySocketSock_Type; |
| 294 | 326 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
327 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
328 /* Create a new socket object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
329 This just creates the object and initializes it. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
330 If the creation fails, return NULL and set an exception (implicit |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
331 in NEWOBJ()). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
332 |
| 1970 | 333 static PySocketSockObject * |
| 13470 | 334 PySocketSock_New(SOCKET_T fd, int family, int type, int proto) |
| 294 | 335 { |
| 1970 | 336 PySocketSockObject *s; |
| 3594 | 337 PySocketSock_Type.ob_type = &PyType_Type; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
338 s = PyObject_New(PySocketSockObject, &PySocketSock_Type); |
| 294 | 339 if (s != NULL) { |
| 340 s->sock_fd = fd; | |
| 341 s->sock_family = family; | |
| 342 s->sock_type = type; | |
| 343 s->sock_proto = proto; | |
| 344 } | |
| 345 return s; | |
| 346 } | |
| 347 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
348 |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
349 /* Lock to allow python interpreter to continue, but only allow one |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
350 thread to be in gethostbyname */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
351 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
352 PyThread_type_lock gethostbyname_lock; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
353 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
354 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
355 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
356 /* Convert a string specifying a host name or one of a few symbolic |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
357 names to a numeric IP address. This usually calls gethostbyname() |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
358 to do the work; the names "" and "<broadcast>" are special. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
359 Return the length (should always be 4 bytes), or negative if |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
360 an error occurred; then an exception is raised. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
361 |
| 294 | 362 static int |
| 13470 | 363 setipaddr(char* name, struct sockaddr_in * addr_ret) |
| 294 | 364 { |
| 365 struct hostent *hp; | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
366 int d1, d2, d3, d4; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
367 int h_length; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
368 char ch; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
369 #ifdef HAVE_GETHOSTBYNAME_R |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
370 struct hostent hp_allocated; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
371 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
372 struct hostent_data data; |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
373 #else |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
374 char buf[1001]; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
375 int buf_len = (sizeof buf) - 1; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
376 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
377 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
378 #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
379 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
380 #endif |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
381 #endif /* HAVE_GETHOSTBYNAME_R */ |
| 294 | 382 |
| 4600 | 383 memset((void *) addr_ret, '\0', sizeof(*addr_ret)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
384 if (name[0] == '\0') { |
| 294 | 385 addr_ret->sin_addr.s_addr = INADDR_ANY; |
| 386 return 4; | |
| 387 } | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
388 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) { |
| 294 | 389 addr_ret->sin_addr.s_addr = INADDR_BROADCAST; |
| 390 return 4; | |
| 391 } | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
392 if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
393 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
394 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
395 addr_ret->sin_addr.s_addr = htonl( |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
396 ((long) d1 << 24) | ((long) d2 << 16) | |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
397 ((long) d3 << 8) | ((long) d4 << 0)); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
398 return 4; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
399 } |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
400 Py_BEGIN_ALLOW_THREADS |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
401 #ifdef HAVE_GETHOSTBYNAME_R |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
402 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
403 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &hp, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
404 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
405 hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
406 #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
407 memset((void *) &data, '\0', sizeof(data)); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
408 result = gethostbyname_r(name, &hp_allocated, &data); |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
409 hp = (result != 0) ? NULL : &hp_allocated; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
410 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
411 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
412 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
413 PyThread_acquire_lock(gethostbyname_lock, 1); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
414 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
415 hp = gethostbyname(name); |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
416 #endif /* HAVE_GETHOSTBYNAME_R */ |
| 1970 | 417 Py_END_ALLOW_THREADS |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
418 |
| 294 | 419 if (hp == NULL) { |
|
2115
7ea369d05c2e
better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
420 #ifdef HAVE_HSTRERROR |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
421 /* Let's get real error message to return */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
422 extern int h_errno; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
423 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
424 #else |
| 1970 | 425 PyErr_SetString(PySocket_Error, "host not found"); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
426 #endif |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
427 #ifdef USE_GETHOSTBYNAME_LOCK |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
428 PyThread_release_lock(gethostbyname_lock); |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
429 #endif |
| 294 | 430 return -1; |
| 431 } | |
| 432 memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length); | |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
433 h_length = hp->h_length; |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
434 #ifdef USE_GETHOSTBYNAME_LOCK |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
435 PyThread_release_lock(gethostbyname_lock); |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
436 #endif |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
437 return h_length; |
| 294 | 438 } |
| 439 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
440 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
441 /* Create a string object representing an IP address. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
442 This is always a string of the form 'dd.dd.dd.dd' (with variable |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
443 size numbers). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
444 |
| 1970 | 445 static PyObject * |
| 13470 | 446 makeipaddr(struct sockaddr_in *addr) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
447 { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
448 long x = ntohl(addr->sin_addr.s_addr); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
449 char buf[100]; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
450 sprintf(buf, "%d.%d.%d.%d", |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
451 (int) (x>>24) & 0xff, (int) (x>>16) & 0xff, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
452 (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); |
| 1970 | 453 return PyString_FromString(buf); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
454 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
455 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
456 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
457 /* Create an object representing the given socket address, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
458 suitable for passing it back to bind(), connect() etc. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
459 The family field of the sockaddr structure is inspected |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
460 to determine what kind of address it really is. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
461 |
| 294 | 462 /*ARGSUSED*/ |
| 1970 | 463 static PyObject * |
| 13470 | 464 makesockaddr(struct sockaddr *addr, int addrlen) |
| 294 | 465 { |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
466 if (addrlen == 0) { |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
467 /* No address -- may be recvfrom() from known socket */ |
| 1970 | 468 Py_INCREF(Py_None); |
| 469 return Py_None; | |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
470 } |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
471 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
472 #ifdef __BEOS__ |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
473 /* XXX: BeOS version of accept() doesn't set family correctly */ |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
474 addr->sa_family = AF_INET; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
475 #endif |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
476 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
477 switch (addr->sa_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
478 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
479 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
480 { |
| 294 | 481 struct sockaddr_in *a = (struct sockaddr_in *) addr; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
482 PyObject *addrobj = makeipaddr(a); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
483 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
484 if (addrobj) { |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
485 ret = Py_BuildValue("Oi", addrobj, ntohs(a->sin_port)); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
486 Py_DECREF(addrobj); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
487 } |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
488 return ret; |
| 294 | 489 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
490 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
491 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
492 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
493 { |
| 294 | 494 struct sockaddr_un *a = (struct sockaddr_un *) addr; |
| 1970 | 495 return PyString_FromString(a->sun_path); |
| 294 | 496 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
497 #endif /* AF_UNIX */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
498 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
499 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
500 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
501 default: |
|
5436
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
502 /* If we don't know the address family, don't raise an |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
503 exception -- return it as a tuple. */ |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
504 return Py_BuildValue("is#", |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
505 addr->sa_family, |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
506 addr->sa_data, |
|
cf818b70da3e
In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents:
5287
diff
changeset
|
507 sizeof(addr->sa_data)); |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
508 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
509 } |
| 294 | 510 } |
| 511 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
512 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
513 /* Parse a socket address argument according to the socket object's |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
514 address family. Return 1 if the address was in the proper format, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
515 0 of not. The address is returned through addr_ret, its length |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
516 through len_ret. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
517 |
| 294 | 518 static int |
| 13470 | 519 getsockaddrarg(PySocketSockObject *s, PyObject *args, struct sockaddr **addr_ret, int *len_ret) |
| 294 | 520 { |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
521 switch (s->sock_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
522 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
523 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
524 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
525 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
526 struct sockaddr_un* addr; |
| 926 | 527 char *path; |
| 294 | 528 int len; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
529 addr = (struct sockaddr_un* )&(s->sock_addr).un; |
|
9307
928ea5a409e5
Use the t# format where appropriate. Greg Stein.
Guido van Rossum <guido@python.org>
parents:
9203
diff
changeset
|
530 if (!PyArg_Parse(args, "t#", &path, &len)) |
| 294 | 531 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
532 if (len > sizeof addr->sun_path) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
533 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
534 "AF_UNIX path too long"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
535 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
536 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
537 addr->sun_family = AF_UNIX; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
538 memcpy(addr->sun_path, path, len); |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
539 addr->sun_path[len] = 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
540 *addr_ret = (struct sockaddr *) addr; |
|
3666
556ec82f4d93
Calculate length of AF_UNIX addr struct portably in getsockaddrarg().
Guido van Rossum <guido@python.org>
parents:
3665
diff
changeset
|
541 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path); |
| 294 | 542 return 1; |
| 543 } | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
544 #endif /* AF_UNIX */ |
| 294 | 545 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
546 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
547 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
548 struct sockaddr_in* addr; |
| 926 | 549 char *host; |
| 294 | 550 int port; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
551 addr=(struct sockaddr_in*)&(s->sock_addr).in; |
| 1970 | 552 if (!PyArg_Parse(args, "(si)", &host, &port)) |
| 294 | 553 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
554 if (setipaddr(host, addr) < 0) |
| 294 | 555 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
556 addr->sin_family = AF_INET; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
557 addr->sin_port = htons((short)port); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
558 *addr_ret = (struct sockaddr *) addr; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
559 *len_ret = sizeof *addr; |
| 294 | 560 return 1; |
| 561 } | |
| 562 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
563 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
564 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
565 default: |
| 1970 | 566 PyErr_SetString(PySocket_Error, "getsockaddrarg: bad family"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
567 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
568 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
569 } |
| 294 | 570 } |
| 571 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
572 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
573 /* Get the address length according to the socket object's address family. |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
574 Return 1 if the family is known, 0 otherwise. The length is returned |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
575 through len_ret. */ |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
576 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
577 static int |
|
13554
906efc1da247
Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13538
diff
changeset
|
578 getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
579 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
580 switch (s->sock_family) { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
581 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
582 #ifdef AF_UNIX |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
583 case AF_UNIX: |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
584 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
585 *len_ret = sizeof (struct sockaddr_un); |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
586 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
587 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
588 #endif /* AF_UNIX */ |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
589 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
590 case AF_INET: |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
591 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
592 *len_ret = sizeof (struct sockaddr_in); |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
593 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
594 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
595 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
596 /* More cases here... */ |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
597 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
598 default: |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
599 PyErr_SetString(PySocket_Error, "getsockaddrlen: bad family"); |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
600 return 0; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
601 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
602 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
603 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
604 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
605 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
606 /* s.accept() method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
607 |
| 1970 | 608 static PyObject * |
| 13470 | 609 PySocketSock_accept(PySocketSockObject *s, PyObject *args) |
| 294 | 610 { |
| 611 char addrbuf[256]; | |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
612 SOCKET_T newfd; |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
613 socklen_t addrlen; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
614 PyObject *sock = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
615 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
616 PyObject *res = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
617 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
618 if (!PyArg_ParseTuple(args, ":accept")) |
| 294 | 619 return NULL; |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
620 if (!getsockaddrlen(s, &addrlen)) |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
621 return NULL; |
| 1970 | 622 Py_BEGIN_ALLOW_THREADS |
| 294 | 623 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 624 Py_END_ALLOW_THREADS |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
625 #ifdef MS_WINDOWS |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
626 if (newfd == INVALID_SOCKET) |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
627 #else |
| 294 | 628 if (newfd < 0) |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
629 #endif |
| 1970 | 630 return PySocket_Err(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
631 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
632 /* Create the new object with unspecified family, |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
633 to avoid calls to bind() etc. on it. */ |
| 1970 | 634 sock = (PyObject *) PySocketSock_New(newfd, |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
635 s->sock_family, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
636 s->sock_type, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
637 s->sock_proto); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
638 if (sock == NULL) { |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
639 SOCKETCLOSE(newfd); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
640 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
641 } |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
642 if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
643 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
644 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
645 if (!(res = Py_BuildValue("OO", sock, addr))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
646 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
647 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
648 finally: |
| 1970 | 649 Py_XDECREF(sock); |
| 650 Py_XDECREF(addr); | |
| 294 | 651 return res; |
| 652 } | |
| 653 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
654 static char accept_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
655 "accept() -> (socket object, address info)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
656 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
657 Wait for an incoming connection. Return a new socket representing the\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
658 connection, and the address of the client. For IP sockets, the address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
659 info is a pair (hostaddr, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
660 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
661 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
662 /* s.setblocking(1 | 0) method */ |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
663 |
| 1970 | 664 static PyObject * |
| 13470 | 665 PySocketSock_setblocking(PySocketSockObject *s, PyObject *args) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
666 { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
667 int block; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
668 #ifndef MS_WINDOWS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
669 int delay_flag; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
670 #endif |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
671 if (!PyArg_ParseTuple(args, "i:setblocking", &block)) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
672 return NULL; |
| 1970 | 673 Py_BEGIN_ALLOW_THREADS |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
674 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
675 block = !block; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
676 setsockopt( s->sock_fd, SOL_SOCKET, SO_NONBLOCK, |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
677 (void *)(&block), sizeof( int ) ); |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
678 #else |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
679 #ifndef MS_WINDOWS |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
680 #ifdef PYOS_OS2 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
681 block = !block; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
682 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
683 #else /* !PYOS_OS2 */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
684 delay_flag = fcntl (s->sock_fd, F_GETFL, 0); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
685 if (block) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
686 delay_flag &= (~O_NDELAY); |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
687 else |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
688 delay_flag |= O_NDELAY; |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
689 fcntl (s->sock_fd, F_SETFL, delay_flag); |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
690 #endif /* !PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
691 #else /* MS_WINDOWS */ |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
692 block = !block; |
|
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
693 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
694 #endif /* MS_WINDOWS */ |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
695 #endif /* __BEOS__ */ |
| 1970 | 696 Py_END_ALLOW_THREADS |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
697 |
| 1970 | 698 Py_INCREF(Py_None); |
| 699 return Py_None; | |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
700 } |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
701 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
702 static char setblocking_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
703 "setblocking(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
704 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
705 Set the socket to blocking (flag is true) or non-blocking (false).\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
706 This uses the FIONBIO ioctl with the O_NDELAY flag."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
707 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
708 |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
709 /* s.setsockopt() method. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
710 With an integer third argument, sets an integer option. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
711 With a string third argument, sets an option from a buffer; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
712 use optional built-in module 'struct' to encode the string. */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
713 |
| 1970 | 714 static PyObject * |
| 13470 | 715 PySocketSock_setsockopt(PySocketSockObject *s, PyObject *args) |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
716 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
717 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
718 int optname; |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
719 int res; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
720 char *buf; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
721 int buflen; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
722 int flag; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
723 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
724 if (PyArg_ParseTuple(args, "iii:setsockopt", |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
725 &level, &optname, &flag)) { |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
726 buf = (char *) &flag; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
727 buflen = sizeof flag; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
728 } |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
729 else { |
| 1970 | 730 PyErr_Clear(); |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
731 if (!PyArg_ParseTuple(args, "iis#:setsockopt", |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
732 &level, &optname, &buf, &buflen)) |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
733 return NULL; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
734 } |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
735 res = setsockopt(s->sock_fd, level, optname, (ANY *)buf, buflen); |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
736 if (res < 0) |
| 1970 | 737 return PySocket_Err(); |
| 738 Py_INCREF(Py_None); | |
| 739 return Py_None; | |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
740 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
741 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
742 static char setsockopt_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
743 "setsockopt(level, option, value)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
744 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
745 Set a socket option. See the Unix manual for level and option.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
746 The value argument can either be an integer or a string."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
747 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
748 |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
749 /* s.getsockopt() method. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
750 With two arguments, retrieves an integer option. |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
751 With a third integer argument, retrieves a string buffer of that size; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
752 use optional built-in module 'struct' to decode the string. */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
753 |
| 1970 | 754 static PyObject * |
| 13470 | 755 PySocketSock_getsockopt(PySocketSockObject *s, PyObject *args) |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
756 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
757 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
758 int optname; |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
759 int res; |
| 1970 | 760 PyObject *buf; |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
761 socklen_t buflen = 0; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
762 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
763 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
764 /* We have incomplete socket support. */ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
765 PyErr_SetString( PySocket_Error, "getsockopt not supported" ); |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
766 return NULL; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
767 #else |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
768 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
769 if (!PyArg_ParseTuple(args, "ii|i:getsockopt", |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
770 &level, &optname, &buflen)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
771 return NULL; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
772 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
773 if (buflen == 0) { |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
774 int flag = 0; |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
775 socklen_t flagsize = sizeof flag; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
776 res = getsockopt(s->sock_fd, level, optname, |
|
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
777 (ANY *)&flag, &flagsize); |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
778 if (res < 0) |
| 1970 | 779 return PySocket_Err(); |
| 780 return PyInt_FromLong(flag); | |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
781 } |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
782 if (buflen <= 0 || buflen > 1024) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
783 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
784 "getsockopt buflen out of range"); |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
785 return NULL; |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
786 } |
| 1970 | 787 buf = PyString_FromStringAndSize((char *)NULL, buflen); |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
788 if (buf == NULL) |
|
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
789 return NULL; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
790 res = getsockopt(s->sock_fd, level, optname, |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2115
diff
changeset
|
791 (ANY *)PyString_AsString(buf), &buflen); |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
792 if (res < 0) { |
| 1970 | 793 Py_DECREF(buf); |
| 794 return PySocket_Err(); | |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
795 } |
| 1970 | 796 _PyString_Resize(&buf, buflen); |
|
1039
6aa0ee14ac2e
Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
797 return buf; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
798 #endif /* __BEOS__ */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
799 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
800 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
801 static char getsockopt_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
802 "getsockopt(level, option[, buffersize]) -> value\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
803 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
804 Get a socket option. See the Unix manual for level and option.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
805 If a nonzero buffersize argument is given, the return value is a\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
806 string of that length; otherwise it is an integer."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
807 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
808 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
809 /* s.bind(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
810 |
| 1970 | 811 static PyObject * |
| 13470 | 812 PySocketSock_bind(PySocketSockObject *s, PyObject *args) |
| 294 | 813 { |
| 814 struct sockaddr *addr; | |
| 815 int addrlen; | |
| 926 | 816 int res; |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
817 PyObject *addro; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
818 if (!PyArg_ParseTuple(args, "O:bind", &addro)) |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
819 return NULL; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
820 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 821 return NULL; |
| 1970 | 822 Py_BEGIN_ALLOW_THREADS |
| 926 | 823 res = bind(s->sock_fd, addr, addrlen); |
| 1970 | 824 Py_END_ALLOW_THREADS |
| 926 | 825 if (res < 0) |
| 1970 | 826 return PySocket_Err(); |
| 827 Py_INCREF(Py_None); | |
| 828 return Py_None; | |
| 294 | 829 } |
| 830 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
831 static char bind_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
832 "bind(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
833 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
834 Bind the socket to a local address. For IP sockets, the address is a\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
835 pair (host, port); the host must refer to the local host."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
836 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
837 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
838 /* s.close() method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
839 Set the file descriptor to -1 so operations tried subsequently |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
840 will surely fail. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
841 |
| 1970 | 842 static PyObject * |
| 13470 | 843 PySocketSock_close(PySocketSockObject *s, PyObject *args) |
| 294 | 844 { |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
845 if (!PyArg_ParseTuple(args, ":close")) |
| 294 | 846 return NULL; |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
847 if (s->sock_fd != -1) { |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
848 Py_BEGIN_ALLOW_THREADS |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
849 (void) SOCKETCLOSE(s->sock_fd); |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
850 Py_END_ALLOW_THREADS |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
851 } |
| 294 | 852 s->sock_fd = -1; |
| 1970 | 853 Py_INCREF(Py_None); |
| 854 return Py_None; | |
| 294 | 855 } |
| 856 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
857 static char close_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
858 "close()\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
859 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
860 Close the socket. It cannot be used after this call."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
861 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
862 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
863 /* s.connect(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
864 |
| 1970 | 865 static PyObject * |
| 13470 | 866 PySocketSock_connect(PySocketSockObject *s, PyObject *args) |
| 294 | 867 { |
| 868 struct sockaddr *addr; | |
| 869 int addrlen; | |
| 926 | 870 int res; |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
871 PyObject *addro; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
872 if (!PyArg_ParseTuple(args, "O:connect", &addro)) |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
873 return NULL; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
874 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 875 return NULL; |
| 1970 | 876 Py_BEGIN_ALLOW_THREADS |
| 926 | 877 res = connect(s->sock_fd, addr, addrlen); |
| 1970 | 878 Py_END_ALLOW_THREADS |
| 926 | 879 if (res < 0) |
| 1970 | 880 return PySocket_Err(); |
| 881 Py_INCREF(Py_None); | |
| 882 return Py_None; | |
| 294 | 883 } |
| 884 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
885 static char connect_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
886 "connect(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
887 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
888 Connect the socket to a remote address. For IP sockets, the address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
889 is a pair (host, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
890 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
891 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
892 /* s.connect_ex(sockaddr) method */ |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
893 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
894 static PyObject * |
| 13470 | 895 PySocketSock_connect_ex(PySocketSockObject *s, PyObject *args) |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
896 { |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
897 struct sockaddr *addr; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
898 int addrlen; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
899 int res; |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
900 PyObject *addro; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
901 if (!PyArg_ParseTuple(args, "O:connect_ex", &addro)) |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
902 return NULL; |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
903 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
904 return NULL; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
905 Py_BEGIN_ALLOW_THREADS |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
906 res = connect(s->sock_fd, addr, addrlen); |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
907 Py_END_ALLOW_THREADS |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
908 if (res != 0) |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
909 res = errno; |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
910 return PyInt_FromLong((long) res); |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
911 } |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
912 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
913 static char connect_ex_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
914 "connect_ex(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
915 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
916 This is like connect(address), but returns an error code (the errno value)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
917 instead of raising an exception when an error occurs."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
918 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
919 |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
920 /* s.fileno() method */ |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
921 |
| 1970 | 922 static PyObject * |
| 13470 | 923 PySocketSock_fileno(PySocketSockObject *s, PyObject *args) |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
924 { |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
925 if (!PyArg_ParseTuple(args, ":fileno")) |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
926 return NULL; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
927 #if SIZEOF_SOCKET_T <= SIZEOF_LONG |
| 1970 | 928 return PyInt_FromLong((long) s->sock_fd); |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
929 #else |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
930 return PyLong_FromLongLong((LONG_LONG)s->sock_fd); |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
931 #endif |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
932 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
933 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
934 static char fileno_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
935 "fileno() -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
936 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
937 Return the integer file descriptor of the socket."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
938 |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
939 |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
940 #ifndef NO_DUP |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
941 /* s.dup() method */ |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
942 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
943 static PyObject * |
| 13470 | 944 PySocketSock_dup(PySocketSockObject *s, PyObject *args) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
945 { |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
946 SOCKET_T newfd; |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
947 PyObject *sock; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
948 if (!PyArg_ParseTuple(args, ":dup")) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
949 return NULL; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
950 newfd = dup(s->sock_fd); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
951 if (newfd < 0) |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
952 return PySocket_Err(); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
953 sock = (PyObject *) PySocketSock_New(newfd, |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
954 s->sock_family, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
955 s->sock_type, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
956 s->sock_proto); |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
957 if (sock == NULL) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
958 SOCKETCLOSE(newfd); |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
959 return sock; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
960 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
961 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
962 static char dup_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
963 "dup() -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
964 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
965 Return a new socket object connected to the same system resource."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
966 |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
967 #endif |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
968 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
969 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
970 /* s.getsockname() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
971 |
| 1970 | 972 static PyObject * |
| 13470 | 973 PySocketSock_getsockname(PySocketSockObject *s, PyObject *args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
974 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
975 char addrbuf[256]; |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
976 int res; |
|
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
977 socklen_t addrlen; |
|
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
978 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
979 if (!PyArg_ParseTuple(args, ":getsockname")) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
980 return NULL; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
981 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
982 return NULL; |
|
3335
9bd1e41d6b11
clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents:
3091
diff
changeset
|
983 memset(addrbuf, 0, addrlen); |
| 1970 | 984 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
985 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 986 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
987 if (res < 0) |
| 1970 | 988 return PySocket_Err(); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
989 return makesockaddr((struct sockaddr *) addrbuf, addrlen); |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
990 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
991 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
992 static char getsockname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
993 "getsockname() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
994 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
995 Return the address of the local endpoint. For IP sockets, the address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
996 info is a pair (hostaddr, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
997 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
998 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
999 #ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1000 /* s.getpeername() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1001 |
| 1970 | 1002 static PyObject * |
| 13470 | 1003 PySocketSock_getpeername(PySocketSockObject *s, PyObject *args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1004 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1005 char addrbuf[256]; |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1006 int res; |
|
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1007 socklen_t addrlen; |
|
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1008 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1009 if (!PyArg_ParseTuple(args, ":getpeername")) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1010 return NULL; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1011 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1012 return NULL; |
| 1970 | 1013 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1014 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 1015 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1016 if (res < 0) |
| 1970 | 1017 return PySocket_Err(); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1018 return makesockaddr((struct sockaddr *) addrbuf, addrlen); |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1019 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1020 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1021 static char getpeername_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1022 "getpeername() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1023 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1024 Return the address of the remote endpoint. For IP sockets, the address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1025 info is a pair (hostaddr, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1026 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1027 #endif /* HAVE_GETPEERNAME */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1028 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1029 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1030 /* s.listen(n) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1031 |
| 1970 | 1032 static PyObject * |
| 13470 | 1033 PySocketSock_listen(PySocketSockObject *s, PyObject *args) |
| 294 | 1034 { |
| 1035 int backlog; | |
| 926 | 1036 int res; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1037 if (!PyArg_ParseTuple(args, "i:listen", &backlog)) |
| 294 | 1038 return NULL; |
| 1970 | 1039 Py_BEGIN_ALLOW_THREADS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1040 if (backlog < 1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1041 backlog = 1; |
| 926 | 1042 res = listen(s->sock_fd, backlog); |
| 1970 | 1043 Py_END_ALLOW_THREADS |
| 926 | 1044 if (res < 0) |
| 1970 | 1045 return PySocket_Err(); |
| 1046 Py_INCREF(Py_None); | |
| 1047 return Py_None; | |
| 294 | 1048 } |
| 1049 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1050 static char listen_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1051 "listen(backlog)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1052 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1053 Enable a server to accept connections. The backlog argument must be at\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1054 least 1; it specifies the number of unaccepted connection that the system\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1055 will allow before refusing new connections."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1056 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1057 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1058 #ifndef NO_DUP |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1059 /* s.makefile(mode) method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1060 Create a new open file object referring to a dupped version of |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1061 the socket's file descriptor. (The dup() call is necessary so |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1062 that the open file and socket objects may be closed independent |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1063 of each other.) |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1064 The mode argument specifies 'r' or 'w' passed to fdopen(). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1065 |
| 1970 | 1066 static PyObject * |
| 13470 | 1067 PySocketSock_makefile(PySocketSockObject *s, PyObject *args) |
| 294 | 1068 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13403
diff
changeset
|
1069 extern int fclose(FILE *); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1070 char *mode = "r"; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1071 int bufsize = -1; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1072 #ifdef MS_WIN32 |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1073 intptr_t fd; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1074 #else |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1075 int fd; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1076 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1077 FILE *fp; |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1078 PyObject *f; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1079 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1080 if (!PyArg_ParseTuple(args, "|si:makefile", &mode, &bufsize)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1081 return NULL; |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1082 #ifdef MS_WIN32 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1083 if (((fd = _open_osfhandle(s->sock_fd, _O_BINARY)) < 0) || |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1084 ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
1085 #else |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1086 if ((fd = dup(s->sock_fd)) < 0 || (fp = fdopen(fd, mode)) == NULL) |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
1087 #endif |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1088 { |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1089 if (fd >= 0) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
1090 SOCKETCLOSE(fd); |
| 1970 | 1091 return PySocket_Err(); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1092 } |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1093 f = PyFile_FromFile(fp, "<socket>", mode, fclose); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1094 if (f != NULL) |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1095 PyFile_SetBufSize(f, bufsize); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1096 return f; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1097 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1098 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1099 static char makefile_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1100 "makefile([mode[, buffersize]]) -> file object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1101 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1102 Return a regular file object corresponding to the socket.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1103 The mode and buffersize arguments are as for the built-in open() function."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1104 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1105 #endif /* NO_DUP */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1106 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1107 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1108 /* s.recv(nbytes [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1109 |
| 1970 | 1110 static PyObject * |
| 13470 | 1111 PySocketSock_recv(PySocketSockObject *s, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1112 { |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1113 int len, n, flags = 0; |
| 1970 | 1114 PyObject *buf; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1115 if (!PyArg_ParseTuple(args, "i|i:recv", &len, &flags)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1116 return NULL; |
| 1970 | 1117 buf = PyString_FromStringAndSize((char *) 0, len); |
| 294 | 1118 if (buf == NULL) |
| 1119 return NULL; | |
| 1970 | 1120 Py_BEGIN_ALLOW_THREADS |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2115
diff
changeset
|
1121 n = recv(s->sock_fd, PyString_AsString(buf), len, flags); |
| 1970 | 1122 Py_END_ALLOW_THREADS |
| 3091 | 1123 if (n < 0) { |
| 1124 Py_DECREF(buf); | |
| 1970 | 1125 return PySocket_Err(); |
| 3091 | 1126 } |
|
3665
5188374377ae
Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents:
3594
diff
changeset
|
1127 if (n != len && _PyString_Resize(&buf, n) < 0) |
| 294 | 1128 return NULL; |
| 1129 return buf; | |
| 1130 } | |
| 1131 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1132 static char recv_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1133 "recv(buffersize[, flags]) -> data\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1134 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1135 Receive up to buffersize bytes from the socket. For the optional flags\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1136 argument, see the Unix manual. When no data is available, block until\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1137 at least one byte is available or until the remote end is closed. When\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1138 the remote end is closed and all data is read, return the empty string."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1139 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1140 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1141 /* s.recvfrom(nbytes [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1142 |
| 1970 | 1143 static PyObject * |
| 13470 | 1144 PySocketSock_recvfrom(PySocketSockObject *s, PyObject *args) |
| 294 | 1145 { |
| 1146 char addrbuf[256]; | |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1147 PyObject *buf = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1148 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1149 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1150 |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1151 int len, n, flags = 0; |
|
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1152 socklen_t addrlen; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1153 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &len, &flags)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1154 return NULL; |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1155 if (!getsockaddrlen(s, &addrlen)) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1156 return NULL; |
| 1970 | 1157 buf = PyString_FromStringAndSize((char *) 0, len); |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1158 if (buf == NULL) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1159 return NULL; |
| 1970 | 1160 Py_BEGIN_ALLOW_THREADS |
| 1161 n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags, | |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1162 #ifndef MS_WINDOWS |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1163 #if defined(PYOS_OS2) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1164 (struct sockaddr *)addrbuf, &addrlen |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1165 #else |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1166 (ANY *)addrbuf, &addrlen |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1167 #endif |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1168 #else |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1169 (struct sockaddr *)addrbuf, &addrlen |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1170 #endif |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1171 ); |
| 1970 | 1172 Py_END_ALLOW_THREADS |
| 3091 | 1173 if (n < 0) { |
| 1174 Py_DECREF(buf); | |
| 1970 | 1175 return PySocket_Err(); |
| 3091 | 1176 } |
|
3665
5188374377ae
Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents:
3594
diff
changeset
|
1177 if (n != len && _PyString_Resize(&buf, n) < 0) |
| 294 | 1178 return NULL; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1179 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1180 if (!(addr = makesockaddr((struct sockaddr *)addrbuf, addrlen))) |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1181 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1182 |
| 1970 | 1183 ret = Py_BuildValue("OO", buf, addr); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1184 finally: |
| 1970 | 1185 Py_XDECREF(addr); |
| 1186 Py_XDECREF(buf); | |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
1187 return ret; |
| 294 | 1188 } |
| 1189 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1190 static char recvfrom_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1191 "recvfrom(buffersize[, flags]) -> (data, address info)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1192 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1193 Like recv(buffersize, flags) but also return the sender's address info."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1194 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1195 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1196 /* s.send(data [,flags]) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1197 |
| 1970 | 1198 static PyObject * |
| 13470 | 1199 PySocketSock_send(PySocketSockObject *s, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1200 { |
| 926 | 1201 char *buf; |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1202 int len, n, flags = 0; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1203 if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1204 return NULL; |
| 1970 | 1205 Py_BEGIN_ALLOW_THREADS |
| 926 | 1206 n = send(s->sock_fd, buf, len, flags); |
| 1970 | 1207 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1208 if (n < 0) |
| 1970 | 1209 return PySocket_Err(); |
| 1210 return PyInt_FromLong((long)n); | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1211 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1212 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1213 static char send_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1214 "send(data[, flags])\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1215 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1216 Send a data string to the socket. For the optional flags\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1217 argument, see the Unix manual."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1218 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1219 |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1220 /* s.sendto(data, [flags,] sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1221 |
| 1970 | 1222 static PyObject * |
| 13470 | 1223 PySocketSock_sendto(PySocketSockObject *s, PyObject *args) |
| 294 | 1224 { |
| 1970 | 1225 PyObject *addro; |
| 926 | 1226 char *buf; |
| 294 | 1227 struct sockaddr *addr; |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1228 int addrlen, len, n, flags; |
|
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1229 flags = 0; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1230 if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) { |
| 1970 | 1231 PyErr_Clear(); |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1232 if (!PyArg_ParseTuple(args, "s#iO:sendto", |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1233 &buf, &len, &flags, &addro)) |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1234 return NULL; |
| 294 | 1235 } |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1236 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 1237 return NULL; |
| 1970 | 1238 Py_BEGIN_ALLOW_THREADS |
|
1293
ac3c80abbf43
* classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
1239 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen); |
| 1970 | 1240 Py_END_ALLOW_THREADS |
| 294 | 1241 if (n < 0) |
| 1970 | 1242 return PySocket_Err(); |
| 1243 return PyInt_FromLong((long)n); | |
| 294 | 1244 } |
| 1245 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1246 static char sendto_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1247 "sendto(data[, flags], address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1248 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1249 Like send(data, flags) but allows specifying the destination address.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1250 For IP sockets, the address is a pair (hostaddr, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1251 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1252 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1253 /* s.shutdown(how) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1254 |
| 1970 | 1255 static PyObject * |
| 13470 | 1256 PySocketSock_shutdown(PySocketSockObject *s, PyObject *args) |
| 294 | 1257 { |
| 1258 int how; | |
| 926 | 1259 int res; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1260 if (!PyArg_ParseTuple(args, "i:shutdown", &how)) |
| 294 | 1261 return NULL; |
| 1970 | 1262 Py_BEGIN_ALLOW_THREADS |
| 926 | 1263 res = shutdown(s->sock_fd, how); |
| 1970 | 1264 Py_END_ALLOW_THREADS |
| 926 | 1265 if (res < 0) |
| 1970 | 1266 return PySocket_Err(); |
| 1267 Py_INCREF(Py_None); | |
| 1268 return Py_None; | |
| 294 | 1269 } |
| 1270 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1271 static char shutdown_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1272 "shutdown(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1273 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1274 Shut down the reading side of the socket (flag == 0), the writing side\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1275 of the socket (flag == 1), or both ends (flag == 2)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1276 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1277 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1278 /* List of methods for socket objects */ |
| 294 | 1279 |
| 1970 | 1280 static PyMethodDef PySocketSock_methods[] = { |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1281 {"accept", (PyCFunction)PySocketSock_accept, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1282 accept_doc}, |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1283 {"bind", (PyCFunction)PySocketSock_bind, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1284 bind_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1285 {"close", (PyCFunction)PySocketSock_close, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1286 close_doc}, |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1287 {"connect", (PyCFunction)PySocketSock_connect, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1288 connect_doc}, |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1289 {"connect_ex", (PyCFunction)PySocketSock_connect_ex, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1290 connect_ex_doc}, |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1291 #ifndef NO_DUP |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1292 {"dup", (PyCFunction)PySocketSock_dup, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1293 dup_doc}, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1294 #endif |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1295 {"fileno", (PyCFunction)PySocketSock_fileno, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1296 fileno_doc}, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1297 #ifdef HAVE_GETPEERNAME |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1298 {"getpeername", (PyCFunction)PySocketSock_getpeername, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1299 getpeername_doc}, |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1300 #endif |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1301 {"getsockname", (PyCFunction)PySocketSock_getsockname, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1302 getsockname_doc}, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1303 {"getsockopt", (PyCFunction)PySocketSock_getsockopt, 1, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1304 getsockopt_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1305 {"listen", (PyCFunction)PySocketSock_listen, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1306 listen_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1307 #ifndef NO_DUP |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1308 {"makefile", (PyCFunction)PySocketSock_makefile, 1, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1309 makefile_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1310 #endif |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1311 {"recv", (PyCFunction)PySocketSock_recv, 1, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1312 recv_doc}, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1313 {"recvfrom", (PyCFunction)PySocketSock_recvfrom, 1, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1314 recvfrom_doc}, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1315 {"send", (PyCFunction)PySocketSock_send, 1, |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1316 send_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1317 {"sendto", (PyCFunction)PySocketSock_sendto, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1318 sendto_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1319 {"setblocking", (PyCFunction)PySocketSock_setblocking, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1320 setblocking_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1321 {"setsockopt", (PyCFunction)PySocketSock_setsockopt, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1322 setsockopt_doc}, |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1323 {"shutdown", (PyCFunction)PySocketSock_shutdown, 1, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1324 shutdown_doc}, |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1325 {NULL, NULL} /* sentinel */ |
| 294 | 1326 }; |
| 1327 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1328 |
| 1970 | 1329 /* Deallocate a socket object in response to the last Py_DECREF(). |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1330 First close the file description. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1331 |
| 294 | 1332 static void |
| 13470 | 1333 PySocketSock_dealloc(PySocketSockObject *s) |
| 294 | 1334 { |
|
12319
57f34e162e67
In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents:
12229
diff
changeset
|
1335 if (s->sock_fd != -1) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
1336 (void) SOCKETCLOSE(s->sock_fd); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1337 PyObject_Del(s); |
| 294 | 1338 } |
| 1339 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1340 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1341 /* Return a socket object's named attribute. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1342 |
| 1970 | 1343 static PyObject * |
| 13470 | 1344 PySocketSock_getattr(PySocketSockObject *s, char *name) |
| 294 | 1345 { |
| 1970 | 1346 return Py_FindMethod(PySocketSock_methods, (PyObject *) s, name); |
| 294 | 1347 } |
| 1348 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1349 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1350 static PyObject * |
| 13470 | 1351 PySocketSock_repr(PySocketSockObject *s) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1352 { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1353 char buf[512]; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1354 #if SIZEOF_SOCKET_T > SIZEOF_LONG |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1355 if (s->sock_fd > LONG_MAX) { |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1356 /* this can occur on Win64, and actually there is a special |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1357 ugly printf formatter for decimal pointer length integer |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1358 printing, only bother if necessary*/ |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1359 PyErr_SetString(PyExc_OverflowError, |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1360 "no printf formatter to display the socket descriptor in decimal"); |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1361 return NULL; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1362 } |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1363 #endif |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1364 sprintf(buf, |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1365 "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>", |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1366 (long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto); |
|
3421
90b54312661a
remove unused variables
Guido van Rossum <guido@python.org>
parents:
3390
diff
changeset
|
1367 return PyString_FromString(buf); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1368 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1369 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1370 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1371 /* Type object for socket objects. */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1372 |
| 1970 | 1373 static PyTypeObject PySocketSock_Type = { |
| 3594 | 1374 PyObject_HEAD_INIT(0) /* Must fill in type value later */ |
| 294 | 1375 0, |
| 1376 "socket", | |
| 1970 | 1377 sizeof(PySocketSockObject), |
| 294 | 1378 0, |
| 1970 | 1379 (destructor)PySocketSock_dealloc, /*tp_dealloc*/ |
| 294 | 1380 0, /*tp_print*/ |
| 1970 | 1381 (getattrfunc)PySocketSock_getattr, /*tp_getattr*/ |
| 294 | 1382 0, /*tp_setattr*/ |
| 1383 0, /*tp_compare*/ | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1384 (reprfunc)PySocketSock_repr, /*tp_repr*/ |
| 294 | 1385 0, /*tp_as_number*/ |
| 1386 0, /*tp_as_sequence*/ | |
| 1387 0, /*tp_as_mapping*/ | |
| 1388 }; | |
| 1389 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1390 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1391 /* Python interface to gethostname(). */ |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1392 |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1393 /*ARGSUSED*/ |
| 1970 | 1394 static PyObject * |
| 13470 | 1395 PySocket_gethostname(PyObject *self, PyObject *args) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1396 { |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1397 char buf[1024]; |
| 926 | 1398 int res; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1399 if (!PyArg_ParseTuple(args, ":gethostname")) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1400 return NULL; |
| 1970 | 1401 Py_BEGIN_ALLOW_THREADS |
| 926 | 1402 res = gethostname(buf, (int) sizeof buf - 1); |
| 1970 | 1403 Py_END_ALLOW_THREADS |
| 926 | 1404 if (res < 0) |
| 1970 | 1405 return PySocket_Err(); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1406 buf[sizeof buf - 1] = '\0'; |
| 1970 | 1407 return PyString_FromString(buf); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1408 } |
| 926 | 1409 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1410 static char gethostname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1411 "gethostname() -> string\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1412 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1413 Return the current host name."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1414 |
| 926 | 1415 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1416 /* Python interface to gethostbyname(name). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1417 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1418 /*ARGSUSED*/ |
| 1970 | 1419 static PyObject * |
| 13470 | 1420 PySocket_gethostbyname(PyObject *self, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1421 { |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1422 char *name; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1423 struct sockaddr_in addrbuf; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1424 if (!PyArg_ParseTuple(args, "s:gethostbyname", &name)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1425 return NULL; |
| 926 | 1426 if (setipaddr(name, &addrbuf) < 0) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1427 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1428 return makeipaddr(&addrbuf); |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1429 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1430 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1431 static char gethostbyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1432 "gethostbyname(host) -> address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1433 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1434 Return the IP address (a string of the form '255.255.255.255') for a host."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1435 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1436 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1437 /* Convenience function common to gethostbyname_ex and gethostbyaddr */ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1438 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1439 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
1440 gethost_common(struct hostent *h, struct sockaddr_in *addr) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1441 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1442 char **pch; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1443 PyObject *rtn_tuple = (PyObject *)NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1444 PyObject *name_list = (PyObject *)NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1445 PyObject *addr_list = (PyObject *)NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1446 PyObject *tmp; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1447 if (h == NULL) { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1448 #ifdef HAVE_HSTRERROR |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1449 /* Let's get real error message to return */ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1450 extern int h_errno; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1451 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1452 #else |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1453 PyErr_SetString(PySocket_Error, "host not found"); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1454 #endif |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1455 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1456 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1457 if ((name_list = PyList_New(0)) == NULL) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1458 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1459 if ((addr_list = PyList_New(0)) == NULL) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1460 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1461 for (pch = h->h_aliases; *pch != NULL; pch++) { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1462 int status; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1463 tmp = PyString_FromString(*pch); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1464 if (tmp == NULL) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1465 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1466 status = PyList_Append(name_list, tmp); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1467 Py_DECREF(tmp); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1468 if (status) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1469 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1470 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1471 for (pch = h->h_addr_list; *pch != NULL; pch++) { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1472 int status; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1473 memcpy((char *) &addr->sin_addr, *pch, h->h_length); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1474 tmp = makeipaddr(addr); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1475 if (tmp == NULL) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1476 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1477 status = PyList_Append(addr_list, tmp); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1478 Py_DECREF(tmp); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1479 if (status) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1480 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1481 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1482 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1483 err: |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1484 Py_XDECREF(name_list); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1485 Py_XDECREF(addr_list); |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1486 return rtn_tuple; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1487 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1488 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1489 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1490 /* Python interface to gethostbyname_ex(name). */ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1491 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1492 /*ARGSUSED*/ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1493 static PyObject * |
| 13470 | 1494 PySocket_gethostbyname_ex(PyObject *self, PyObject *args) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1495 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1496 char *name; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1497 struct hostent *h; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1498 struct sockaddr_in addr; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
1499 PyObject *ret; |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1500 #ifdef HAVE_GETHOSTBYNAME_R |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1501 struct hostent hp_allocated; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1502 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1503 struct hostent_data data; |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1504 #else |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1505 char buf[16384]; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1506 int buf_len = (sizeof buf) - 1; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1507 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1508 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1509 #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1510 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1511 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1512 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1513 if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name)) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1514 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1515 if (setipaddr(name, &addr) < 0) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1516 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1517 Py_BEGIN_ALLOW_THREADS |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1518 #ifdef HAVE_GETHOSTBYNAME_R |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1519 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1520 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1521 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1522 h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1523 #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
1524 memset((void *) &data, '\0', sizeof(data)); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1525 result = gethostbyname_r(name, &hp_allocated, &data); |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1526 h = (result != 0) ? NULL : &hp_allocated; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1527 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1528 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1529 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1530 PyThread_acquire_lock(gethostbyname_lock, 1); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1531 #endif |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1532 h = gethostbyname(name); |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
1533 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
1534 Py_END_ALLOW_THREADS |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1535 ret = gethost_common(h, &addr); |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1536 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1537 PyThread_release_lock(gethostbyname_lock); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1538 #endif |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
1539 return ret; |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1540 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1541 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1542 static char ghbn_ex_doc[] = |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1543 "gethostbyname_ex(host) -> (name, aliaslist, addresslist)\n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1544 \n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1545 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1546 for a host. The host argument is a string giving a host name or IP number."; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1547 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1548 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1549 /* Python interface to gethostbyaddr(IP). */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1550 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1551 /*ARGSUSED*/ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1552 static PyObject * |
| 13470 | 1553 PySocket_gethostbyaddr(PyObject *self, PyObject *args) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1554 { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1555 struct sockaddr_in addr; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1556 char *ip_num; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1557 struct hostent *h; |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1558 PyObject *ret; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1559 #ifdef HAVE_GETHOSTBYNAME_R |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1560 struct hostent hp_allocated; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1561 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1562 struct hostent_data data; |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1563 #else |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1564 char buf[16384]; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1565 int buf_len = (sizeof buf) - 1; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1566 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1567 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1568 #if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1569 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1570 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1571 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1572 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1573 if (!PyArg_ParseTuple(args, "s:gethostbyaddr", &ip_num)) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1574 return NULL; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1575 if (setipaddr(ip_num, &addr) < 0) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1576 return NULL; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1577 Py_BEGIN_ALLOW_THREADS |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1578 #ifdef HAVE_GETHOSTBYNAME_R |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1579 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1580 result = gethostbyaddr_r((char *)&addr.sin_addr, |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1581 sizeof(addr.sin_addr), |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1582 AF_INET, &hp_allocated, buf, buf_len, |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1583 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1584 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1585 h = gethostbyaddr_r((char *)&addr.sin_addr, |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1586 sizeof(addr.sin_addr), |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1587 AF_INET, |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1588 &hp_allocated, buf, buf_len, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1589 #else /* HAVE_GETHOSTBYNAME_R_3_ARG */ |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
1590 memset((void *) &data, '\0', sizeof(data)); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1591 result = gethostbyaddr_r((char *)&addr.sin_addr, |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1592 sizeof(addr.sin_addr), |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1593 AF_INET, &hp_allocated, &data); |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1594 h = (result != 0) ? NULL : &hp_allocated; |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1595 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1596 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1597 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1598 PyThread_acquire_lock(gethostbyname_lock, 1); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1599 #endif |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1600 h = gethostbyaddr((char *)&addr.sin_addr, |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1601 sizeof(addr.sin_addr), |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1602 AF_INET); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1603 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1604 Py_END_ALLOW_THREADS |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1605 ret = gethost_common(h, &addr); |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1606 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1607 PyThread_release_lock(gethostbyname_lock); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
1608 #endif |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
1609 return ret; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1610 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1611 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1612 static char gethostbyaddr_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1613 "gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1614 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1615 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1616 for a host. The host argument is a string giving a host name or IP number."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1617 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1618 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1619 /* Python interface to getservbyname(name). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1620 This only returns the port number, since the other info is already |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1621 known or not useful (like the list of aliases). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1622 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1623 /*ARGSUSED*/ |
| 1970 | 1624 static PyObject * |
| 13470 | 1625 PySocket_getservbyname(PyObject *self, PyObject *args) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1626 { |
| 926 | 1627 char *name, *proto; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1628 struct servent *sp; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1629 if (!PyArg_ParseTuple(args, "ss:getservbyname", &name, &proto)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1630 return NULL; |
| 1970 | 1631 Py_BEGIN_ALLOW_THREADS |
| 926 | 1632 sp = getservbyname(name, proto); |
| 1970 | 1633 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1634 if (sp == NULL) { |
| 1970 | 1635 PyErr_SetString(PySocket_Error, "service/proto not found"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1636 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1637 } |
| 1970 | 1638 return PyInt_FromLong((long) ntohs(sp->s_port)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1639 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1640 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1641 static char getservbyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1642 "getservbyname(servicename, protocolname) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1643 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1644 Return a port number from a service name and protocol name.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1645 The protocol name should be 'tcp' or 'udp'."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1646 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1647 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1648 /* Python interface to getprotobyname(name). |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1649 This only returns the protocol number, since the other info is |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1650 already known or not useful (like the list of aliases). */ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1651 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1652 /*ARGSUSED*/ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1653 static PyObject * |
| 13470 | 1654 PySocket_getprotobyname(PyObject *self, PyObject *args) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1655 { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1656 char *name; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1657 struct protoent *sp; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1658 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1659 /* Not available in BeOS yet. - [cjh] */ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1660 PyErr_SetString( PySocket_Error, "getprotobyname not supported" ); |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1661 return NULL; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1662 #else |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1663 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name)) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1664 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1665 Py_BEGIN_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1666 sp = getprotobyname(name); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1667 Py_END_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1668 if (sp == NULL) { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1669 PyErr_SetString(PySocket_Error, "protocol not found"); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1670 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1671 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1672 return PyInt_FromLong((long) sp->p_proto); |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1673 #endif |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1674 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1675 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1676 static char getprotobyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1677 "getprotobyname(name) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1678 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1679 Return the protocol number for the named protocol. (Rarely used.)"; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1680 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
1681 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1682 /* Python interface to socket(family, type, proto). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1683 The third (protocol) argument is optional. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1684 Return a new socket object. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1685 |
| 294 | 1686 /*ARGSUSED*/ |
| 1970 | 1687 static PyObject * |
| 13470 | 1688 PySocket_socket(PyObject *self, PyObject *args) |
| 294 | 1689 { |
| 1970 | 1690 PySocketSockObject *s; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1691 SOCKET_T fd; |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1692 int family, type, proto = 0; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1693 if (!PyArg_ParseTuple(args, "ii|i:socket", &family, &type, &proto)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1694 return NULL; |
| 1970 | 1695 Py_BEGIN_ALLOW_THREADS |
| 294 | 1696 fd = socket(family, type, proto); |
| 1970 | 1697 Py_END_ALLOW_THREADS |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
1698 #ifdef MS_WINDOWS |
|
3672
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1699 if (fd == INVALID_SOCKET) |
|
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1700 #else |
| 294 | 1701 if (fd < 0) |
|
3672
cec27c93b5cb
more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents:
3666
diff
changeset
|
1702 #endif |
| 1970 | 1703 return PySocket_Err(); |
| 1704 s = PySocketSock_New(fd, family, type, proto); | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1705 /* If the object can't be created, don't forget to close the |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1706 file descriptor again! */ |
| 294 | 1707 if (s == NULL) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
1708 (void) SOCKETCLOSE(fd); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1709 /* From now on, ignore SIGPIPE and let the error checking |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1710 do the work. */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1711 #ifdef SIGPIPE |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1712 (void) signal(SIGPIPE, SIG_IGN); |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1713 #endif |
| 1970 | 1714 return (PyObject *) s; |
| 294 | 1715 } |
| 1716 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1717 static char socket_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1718 "socket(family, type[, proto]) -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1719 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1720 Open a socket of the given type. The family argument specifies the\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1721 address family; it is normally AF_INET, sometimes AF_UNIX.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1722 The type argument specifies whether this is a stream (SOCK_STREAM)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1723 or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1724 specifying the default protocol."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1725 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1726 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1727 #ifndef NO_DUP |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1728 /* Create a socket object from a numeric file description. |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1729 Useful e.g. if stdin is a socket. |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1730 Additional arguments as for socket(). */ |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1731 |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1732 /*ARGSUSED*/ |
| 1970 | 1733 static PyObject * |
| 13470 | 1734 PySocket_fromfd(PyObject *self, PyObject *args) |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1735 { |
| 1970 | 1736 PySocketSockObject *s; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1737 SOCKET_T fd; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1738 int family, type, proto = 0; |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1739 if (!PyArg_ParseTuple(args, "iii|i:fromfd", |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1740 &fd, &family, &type, &proto)) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
1741 return NULL; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1742 /* Dup the fd so it and the socket can be closed independently */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1743 fd = dup(fd); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1099
diff
changeset
|
1744 if (fd < 0) |
| 1970 | 1745 return PySocket_Err(); |
| 1746 s = PySocketSock_New(fd, family, type, proto); | |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1747 /* From now on, ignore SIGPIPE and let the error checking |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1748 do the work. */ |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1749 #ifdef SIGPIPE |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1750 (void) signal(SIGPIPE, SIG_IGN); |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1751 #endif |
| 1970 | 1752 return (PyObject *) s; |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1753 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1754 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1755 static char fromfd_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1756 "fromfd(fd, family, type[, proto]) -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1757 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1758 Create a socket object from the given file descriptor.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1759 The remaining arguments are the same as for socket()."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1760 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1761 #endif /* NO_DUP */ |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
1762 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1763 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1764 static PyObject * |
| 13470 | 1765 PySocket_ntohs(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1766 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1767 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1768 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1769 if (!PyArg_ParseTuple(args, "i:ntohs", &x1)) { |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1770 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1771 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1772 x2 = (int)ntohs((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1773 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1774 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1775 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1776 static char ntohs_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1777 "ntohs(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1778 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1779 Convert a 16-bit integer from network to host byte order."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1780 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1781 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1782 static PyObject * |
| 13470 | 1783 PySocket_ntohl(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1784 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1785 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1786 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1787 if (!PyArg_ParseTuple(args, "i:ntohl", &x1)) { |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1788 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1789 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1790 x2 = ntohl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1791 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1792 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1793 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1794 static char ntohl_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1795 "ntohl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1796 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1797 Convert a 32-bit integer from network to host byte order."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1798 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1799 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1800 static PyObject * |
| 13470 | 1801 PySocket_htons(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1802 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1803 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1804 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1805 if (!PyArg_ParseTuple(args, "i:htons", &x1)) { |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1806 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1807 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1808 x2 = (int)htons((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1809 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1810 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1811 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1812 static char htons_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1813 "htons(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1814 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1815 Convert a 16-bit integer from host to network byte order."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1816 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1817 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1818 static PyObject * |
| 13470 | 1819 PySocket_htonl(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1820 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1821 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1822 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1823 if (!PyArg_ParseTuple(args, "i:htonl", &x1)) { |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1824 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1825 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1826 x2 = htonl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1827 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1828 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
1829 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1830 static char htonl_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1831 "htonl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1832 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1833 Convert a 32-bit integer from host to network byte order."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1834 |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1835 /* |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1836 * socket.inet_aton() and socket.inet_ntoa() functions |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1837 * |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1838 * written 20 Aug 1999 by Ben Gertzfield <che@debian.org> <- blame him! |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1839 * |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1840 */ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1841 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1842 static char inet_aton_doc[] = |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1843 "inet_aton(string) -> packed 32-bit IP representation\n\ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1844 \n\ |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1845 Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1846 binary format used in low-level network functions."; |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1847 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1848 static PyObject* |
| 13470 | 1849 PySocket_inet_aton(PyObject *self, PyObject *args) |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1850 { |
|
11268
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
1851 #ifndef INADDR_NONE |
|
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
1852 #define INADDR_NONE (-1) |
|
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
1853 #endif |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1854 |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1855 /* Have to use inet_addr() instead */ |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1856 char *ip_addr; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1857 long packed_addr; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1858 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1859 if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) { |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1860 return NULL; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1861 } |
|
12479
a3e1fecb43c6
Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents:
12436
diff
changeset
|
1862 #ifdef USE_GUSI1 |
|
11438
be25aaca11f4
Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents:
11288
diff
changeset
|
1863 packed_addr = (long)inet_addr(ip_addr).s_addr; |
|
be25aaca11f4
Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents:
11288
diff
changeset
|
1864 #else |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1865 packed_addr = inet_addr(ip_addr); |
|
11438
be25aaca11f4
Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents:
11288
diff
changeset
|
1866 #endif |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1867 |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1868 if (packed_addr == INADDR_NONE) { /* invalid address */ |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1869 PyErr_SetString(PySocket_Error, |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1870 "illegal IP address string passed to inet_aton"); |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1871 return NULL; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1872 } |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1873 |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1874 return PyString_FromStringAndSize((char *) &packed_addr, |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1875 sizeof(packed_addr)); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1876 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1877 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1878 static char inet_ntoa_doc[] = |
| 11937 | 1879 "inet_ntoa(packed_ip) -> ip_address_string\n\ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1880 \n\ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1881 Convert an IP address from 32-bit packed binary format to string format"; |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1882 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1883 static PyObject* |
| 13470 | 1884 PySocket_inet_ntoa(PyObject *self, PyObject *args) |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1885 { |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1886 char *packed_str; |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
1887 int addr_len; |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1888 struct in_addr packed_addr; |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1889 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1890 if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) { |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1891 return NULL; |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1892 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1893 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1894 if (addr_len != sizeof(packed_addr)) { |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1895 PyErr_SetString(PySocket_Error, |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1896 "packed IP wrong length for inet_ntoa"); |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1897 return NULL; |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1898 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1899 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1900 memcpy(&packed_addr, packed_str, addr_len); |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1901 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1902 return PyString_FromString(inet_ntoa(packed_addr)); |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
1903 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1904 |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1905 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1906 #ifdef USE_SSL |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1907 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1908 /* This is a C function to be called for new object initialization */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1909 static SSLObject * |
| 13470 | 1910 newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file) |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1911 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1912 SSLObject *self; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1913 char *str; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1914 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1915 #if 0 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1916 meth=SSLv23_client_method(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1917 meth=SSLv3_client_method(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1918 meth=SSLv2_client_method(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1919 #endif |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1920 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1921 self = PyObject_New(SSLObject, &SSL_Type); /* Create new object */ |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1922 if (self == NULL){ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1923 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1924 PyString_FromString("newSSLObject error")); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1925 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1926 } |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
1927 memset(self->server, '\0', sizeof(char) * 256); |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
1928 memset(self->issuer, '\0', sizeof(char) * 256); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1929 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1930 self->x_attr = PyDict_New(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1931 self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1932 if (self->ctx == NULL) { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1933 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1934 PyString_FromString("SSL_CTX_new error")); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1935 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1936 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1937 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1938 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1939 if ( (key_file && !cert_file) || (!key_file && cert_file) ) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1940 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1941 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1942 PyString_FromString( |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1943 "Both the key & certificate files must be specified")); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1944 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1945 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1946 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1947 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1948 if (key_file && cert_file) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1949 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1950 if (SSL_CTX_use_PrivateKey_file(self->ctx, key_file, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1951 SSL_FILETYPE_PEM) < 1) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1952 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1953 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1954 PyString_FromString( |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1955 "SSL_CTX_use_PrivateKey_file error")); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1956 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1957 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1958 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1959 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1960 if (SSL_CTX_use_certificate_chain_file(self->ctx, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1961 cert_file) < 1) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1962 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1963 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1964 PyString_FromString( |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1965 "SSL_CTX_use_certificate_chain_file error")); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1966 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1967 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1968 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1969 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1970 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1971 SSL_CTX_set_verify(self->ctx, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1972 SSL_VERIFY_NONE, NULL); /* set verify lvl */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1973 self->ssl = SSL_new(self->ctx); /* New ssl struct */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1974 SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1975 SSL_set_connect_state(self->ssl); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1976 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1977 if ((SSL_connect(self->ssl)) == -1) { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1978 /* Actually negotiate SSL connection */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1979 PyErr_SetObject(SSLErrorObject, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1980 PyString_FromString("SSL_connect error")); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
1981 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1982 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1983 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1984 self->ssl->debug = 1; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1985 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1986 if ((self->server_cert = SSL_get_peer_certificate(self->ssl))) { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1987 X509_NAME_oneline(X509_get_subject_name(self->server_cert), |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1988 self->server, 256); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1989 X509_NAME_oneline(X509_get_issuer_name(self->server_cert), |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1990 self->issuer, 256); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1991 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1992 self->x_attr = NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1993 self->Socket = Sock; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1994 Py_INCREF(self->Socket); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1995 return self; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1996 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1997 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1998 /* This is the Python function called for new object initialization */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
1999 static PyObject * |
| 13470 | 2000 PySocket_ssl(PyObject *self, PyObject *args) |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2001 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2002 SSLObject *rv; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2003 PySocketSockObject *Sock; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2004 char *key_file; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2005 char *cert_file; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2006 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
2007 if (!PyArg_ParseTuple(args, "O!zz:ssl", |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2008 &PySocketSock_Type, (PyObject*)&Sock, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2009 &key_file, &cert_file) ) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2010 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2011 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2012 rv = newSSLObject(Sock, key_file, cert_file); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2013 if ( rv == NULL ) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2014 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2015 return (PyObject *)rv; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2016 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2017 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2018 static char ssl_doc[] = |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2019 "ssl(socket, keyfile, certfile) -> sslobject"; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2020 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2021 static PyObject * |
| 13470 | 2022 SSL_server(SSLObject *self, PyObject *args) |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2023 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2024 return PyString_FromString(self->server); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2025 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2026 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2027 static PyObject * |
| 13470 | 2028 SSL_issuer(SSLObject *self, PyObject *args) |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2029 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2030 return PyString_FromString(self->issuer); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2031 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2032 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2033 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2034 /* SSL object methods */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2035 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2036 static PyMethodDef SSLMethods[] = { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2037 { "write", (PyCFunction)SSL_SSLwrite, 1 }, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2038 { "read", (PyCFunction)SSL_SSLread, 1 }, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2039 { "server", (PyCFunction)SSL_server, 1 }, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2040 { "issuer", (PyCFunction)SSL_issuer, 1 }, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2041 { NULL, NULL} |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2042 }; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2043 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2044 static void SSL_dealloc(SSLObject *self) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2045 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2046 if (self->server_cert) /* Possible not to have one? */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2047 X509_free (self->server_cert); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2048 SSL_CTX_free(self->ctx); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2049 SSL_free(self->ssl); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2050 Py_XDECREF(self->x_attr); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2051 Py_XDECREF(self->Socket); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12493
diff
changeset
|
2052 PyObject_Del(self); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2053 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2054 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2055 static PyObject *SSL_getattr(SSLObject *self, char *name) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2056 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2057 return Py_FindMethod(SSLMethods, (PyObject *)self, name); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2058 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2059 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2060 staticforward PyTypeObject SSL_Type = { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2061 PyObject_HEAD_INIT(&PyType_Type) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2062 0, /*ob_size*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2063 "SSL", /*tp_name*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2064 sizeof(SSLObject), /*tp_basicsize*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2065 0, /*tp_itemsize*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2066 /* methods */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2067 (destructor)SSL_dealloc, /*tp_dealloc*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2068 0, /*tp_print*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2069 (getattrfunc)SSL_getattr, /*tp_getattr*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2070 0, /*tp_setattr*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2071 0, /*tp_compare*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2072 0, /*tp_repr*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2073 0, /*tp_as_number*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2074 0, /*tp_as_sequence*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2075 0, /*tp_as_mapping*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2076 0, /*tp_hash*/ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2077 }; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2078 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2079 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2080 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2081 static PyObject *SSL_SSLwrite(SSLObject *self, PyObject *args) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2082 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2083 char *data; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2084 size_t len = 0; |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2085 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
2086 if (!PyArg_ParseTuple(args, "s|i:write", &data, &len)) |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2087 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2088 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2089 if (!len) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2090 len = strlen(data); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2091 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2092 len = SSL_write(self->ssl, data, len); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2093 return PyInt_FromLong((long)len); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2094 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2095 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2096 static PyObject *SSL_SSLread(SSLObject *self, PyObject *args) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2097 { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2098 PyObject *buf; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2099 int count = 0; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2100 int len = 1024; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2101 int res; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2102 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
2103 PyArg_ParseTuple(args, "|i:read", &len); |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2104 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2105 if (!(buf = PyString_FromStringAndSize((char *) 0, len))) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2106 return NULL; /* Error object should already be set */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2107 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2108 count = SSL_read(self->ssl, PyString_AsString(buf), len); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2109 res = SSL_get_error(self->ssl, count); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2110 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2111 switch (res) { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2112 case 0: /* Good return value! */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2113 break; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2114 case 6: |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2115 PyErr_SetString(SSLErrorObject, "EOF"); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2116 Py_DECREF(buf); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2117 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2118 break; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2119 case 5: |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2120 default: |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2121 return PyErr_SetFromErrno(SSLErrorObject); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2122 break; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2123 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2124 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2125 fflush(stderr); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2126 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2127 if (count < 0) { |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2128 Py_DECREF(buf); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2129 return PyErr_SetFromErrno(SSLErrorObject); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2130 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2131 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2132 if (count != len && _PyString_Resize(&buf, count) < 0) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2133 return NULL; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2134 return buf; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2135 } |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2136 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2137 #endif /* USE_SSL */ |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2138 |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2139 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2140 /* List of functions exported by this module. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2141 |
| 1970 | 2142 static PyMethodDef PySocket_methods[] = { |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2143 {"gethostbyname", PySocket_gethostbyname, 1, gethostbyname_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2144 {"gethostbyname_ex", PySocket_gethostbyname_ex, 1, ghbn_ex_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2145 {"gethostbyaddr", PySocket_gethostbyaddr, 1, gethostbyaddr_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2146 {"gethostname", PySocket_gethostname, 1, gethostname_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2147 {"getservbyname", PySocket_getservbyname, 1, getservbyname_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2148 {"getprotobyname", PySocket_getprotobyname, 1,getprotobyname_doc}, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2149 {"socket", PySocket_socket, 1, socket_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2150 #ifndef NO_DUP |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2151 {"fromfd", PySocket_fromfd, 1, fromfd_doc}, |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2152 #endif |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2153 {"ntohs", PySocket_ntohs, 1, ntohs_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2154 {"ntohl", PySocket_ntohl, 1, ntohl_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2155 {"htons", PySocket_htons, 1, htons_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2156 {"htonl", PySocket_htonl, 1, htonl_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2157 {"inet_aton", PySocket_inet_aton, 1, inet_aton_doc}, |
|
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2158 {"inet_ntoa", PySocket_inet_ntoa, 1, inet_ntoa_doc}, |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2159 #ifdef USE_SSL |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2160 {"ssl", PySocket_ssl, 1, ssl_doc}, |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2161 #endif /* USE_SSL */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2162 {NULL, NULL} /* Sentinel */ |
| 294 | 2163 }; |
| 2164 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2165 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2166 /* Convenience routine to export an integer value. |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2167 * |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2168 * Errors are silently ignored, for better or for worse... |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2169 */ |
| 294 | 2170 static void |
| 13470 | 2171 insint(PyObject *d, char *name, int value) |
| 294 | 2172 { |
| 1970 | 2173 PyObject *v = PyInt_FromLong((long) value); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2174 if (!v || PyDict_SetItemString(d, name, v)) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2175 PyErr_Clear(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2176 |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2177 Py_XDECREF(v); |
| 294 | 2178 } |
| 2179 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2180 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2181 #ifdef MS_WINDOWS |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2182 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2183 /* Additional initialization and cleanup for NT/Windows */ |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2184 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2185 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2186 NTcleanup(void) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2187 { |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2188 WSACleanup(); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2189 } |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2190 |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2191 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2192 NTinit(void) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2193 { |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2194 WSADATA WSAData; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2195 int ret; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2196 char buf[100]; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2197 ret = WSAStartup(0x0101, &WSAData); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2198 switch (ret) { |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2199 case 0: /* no error */ |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2200 atexit(NTcleanup); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2201 return 1; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2202 case WSASYSNOTREADY: |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2203 PyErr_SetString(PyExc_ImportError, |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2204 "WSAStartup failed: network not ready"); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2205 break; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2206 case WSAVERNOTSUPPORTED: |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2207 case WSAEINVAL: |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2208 PyErr_SetString(PyExc_ImportError, |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2209 "WSAStartup failed: requested version not supported"); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2210 break; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2211 default: |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2212 sprintf(buf, "WSAStartup failed: error code %d", ret); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2213 PyErr_SetString(PyExc_ImportError, buf); |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2214 break; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2215 } |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2216 return 0; |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2217 } |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2218 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2219 #endif /* MS_WINDOWS */ |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2220 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2221 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2222 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2223 /* Additional initialization and cleanup for OS/2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2224 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2225 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2226 OS2cleanup(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2227 { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2228 /* No cleanup is necessary for OS/2 Sockets */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2229 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2230 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2231 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2232 OS2init(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2233 { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2234 char reason[64]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2235 int rc = sock_init(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2236 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2237 if (rc == 0) { |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2238 atexit(OS2cleanup); |
|
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2239 return 1; /* Indicate Success */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2240 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2241 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2242 sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno()); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2243 PyErr_SetString(PyExc_ImportError, reason); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2244 |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2245 return 0; /* Indicate Failure */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2246 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2247 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2248 #endif /* PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2249 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2250 /* Initialize this module. |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2251 * This is called when the first 'import socket' is done, |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2252 * via a table in config.c, if config.c is compiled with USE_SOCKET |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2253 * defined. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2254 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2255 * For MS_WINDOWS (which means any Windows variant), this module |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2256 * is actually called "_socket", and there's a wrapper "socket.py" |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2257 * which implements some missing functionality (such as makefile(), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2258 * dup() and fromfd()). The import of "_socket" may fail with an |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2259 * ImportError exception if initialization of WINSOCK fails. When |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2260 * WINSOCK is initialized succesfully, a call to WSACleanup() is |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2261 * scheduled to be made at exit time. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2262 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2263 * For OS/2, this module is also called "_socket" and uses a wrapper |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2264 * "socket.py" which implements that functionality that is missing |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2265 * when PC operating systems don't put socket descriptors in the |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2266 * operating system's filesystem layer. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2267 */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2268 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2269 static char module_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2270 "This module provides socket operations and some related functions.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2271 On Unix, it supports IP (Internet Protocol) and Unix domain sockets.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2272 On other systems, it only supports IP.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2273 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2274 Functions:\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2275 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2276 socket() -- create a new socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2277 fromfd() -- create a socket object from an open file descriptor (*)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2278 gethostname() -- return the current hostname\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2279 gethostbyname() -- map a hostname to its IP number\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2280 gethostbyaddr() -- map an IP number or hostname to DNS info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2281 getservbyname() -- map a service name and a protocol name to a port number\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2282 getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2283 ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2284 htons(), htonl() -- convert 16, 32 bit int from host to network byte order\n\ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2285 inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format\n\ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2286 inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)\n\ |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2287 ssl() -- secure socket layer support (only available if configured)\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2288 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2289 (*) not available on all platforms!)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2290 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2291 Special objects:\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2292 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2293 SocketType -- type object for socket objects\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2294 error -- exception raised for I/O errors\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2295 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2296 Integer constants:\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2297 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2298 AF_INET, AF_UNIX -- socket domains (first argument to socket() call)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2299 SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2300 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2301 Many other constants may be defined; these may be used in calls to\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2302 the setsockopt() and getsockopt() methods.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2303 "; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2304 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2305 static char sockettype_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2306 "A socket represents one endpoint of a network connection.\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2307 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2308 Methods:\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2309 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2310 accept() -- accept a connection, returning new socket and client address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2311 bind() -- bind the socket to a local address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2312 close() -- close the socket\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2313 connect() -- connect the socket to a remote address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2314 connect_ex() -- connect, return an error code instead of an exception \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2315 dup() -- return a new socket object identical to the current one (*)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2316 fileno() -- return underlying file descriptor\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2317 getpeername() -- return remote address (*)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2318 getsockname() -- return local address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2319 getsockopt() -- get socket options\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2320 listen() -- start listening for incoming connections\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2321 makefile() -- return a file object corresponding tot the socket (*)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2322 recv() -- receive data\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2323 recvfrom() -- receive data and sender's address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2324 send() -- send data\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2325 sendto() -- send data to a given address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2326 setblocking() -- set or clear the blocking I/O flag\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2327 setsockopt() -- set socket options\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2328 shutdown() -- shut down traffic in one or both directions\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2329 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2330 (*) not available on all platforms!)"; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2331 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9307
diff
changeset
|
2332 DL_EXPORT(void) |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2333 #if defined(MS_WINDOWS) || defined(PYOS_OS2) || defined(__BEOS__) |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2334 init_socket() |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2335 #else |
| 294 | 2336 initsocket() |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2337 #endif |
| 294 | 2338 { |
| 1970 | 2339 PyObject *m, *d; |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2340 #ifdef MS_WINDOWS |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2341 if (!NTinit()) |
|
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2342 return; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2343 m = Py_InitModule3("_socket", PySocket_methods, module_doc); |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2344 #else |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2345 #if defined(__TOS_OS2__) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2346 if (!OS2init()) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2347 return; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2348 m = Py_InitModule3("_socket", PySocket_methods, module_doc); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2349 #else |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2350 #if defined(__BEOS__) |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2351 m = Py_InitModule3("_socket", PySocket_methods, module_doc); |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2352 #else |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2353 m = Py_InitModule3("socket", PySocket_methods, module_doc); |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2354 #endif /* __BEOS__ */ |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2355 #endif |
|
3700
931086cb8529
More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents:
3673
diff
changeset
|
2356 #endif |
| 1970 | 2357 d = PyModule_GetDict(m); |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2358 PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2359 if (PySocket_Error == NULL) |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2360 return; |
|
11527
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2361 #ifdef USE_SSL |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2362 SSL_load_error_strings(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2363 SSLeay_add_ssl_algorithms(); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2364 SSLErrorObject = PyErr_NewException("socket.sslerror", NULL, NULL); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2365 if (SSLErrorObject == NULL) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2366 return; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2367 PyDict_SetItemString(d, "sslerror", SSLErrorObject); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2368 Py_INCREF(&SSL_Type); |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2369 if (PyDict_SetItemString(d, "SSLType", |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2370 (PyObject *)&SSL_Type) != 0) |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2371 return; |
|
28b8585354de
OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents:
11438
diff
changeset
|
2372 #endif /* USE_SSL */ |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2373 PyDict_SetItemString(d, "error", PySocket_Error); |
|
5572
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
2374 PySocketSock_Type.ob_type = &PyType_Type; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2375 PySocketSock_Type.tp_doc = sockettype_doc; |
|
5572
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
2376 Py_INCREF(&PySocketSock_Type); |
|
5697
88b0b2a3aab5
socket_type -> SocketType
Guido van Rossum <guido@python.org>
parents:
5572
diff
changeset
|
2377 if (PyDict_SetItemString(d, "SocketType", |
|
5572
b231855a9474
Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents:
5534
diff
changeset
|
2378 (PyObject *)&PySocketSock_Type) != 0) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2379 return; |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2380 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2381 /* Address families (we only support AF_INET and AF_UNIX) */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2382 #ifdef AF_UNSPEC |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2383 insint(d, "AF_UNSPEC", AF_UNSPEC); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2384 #endif |
| 294 | 2385 insint(d, "AF_INET", AF_INET); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2386 #ifdef AF_UNIX |
| 294 | 2387 insint(d, "AF_UNIX", AF_UNIX); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2388 #endif /* AF_UNIX */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2389 #ifdef AF_AX25 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2390 insint(d, "AF_AX25", AF_AX25); /* Amateur Radio AX.25 */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2391 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2392 #ifdef AF_IPX |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2393 insint(d, "AF_IPX", AF_IPX); /* Novell IPX */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2394 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2395 #ifdef AF_APPLETALK |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2396 insint(d, "AF_APPLETALK", AF_APPLETALK); /* Appletalk DDP */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2397 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2398 #ifdef AF_NETROM |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2399 insint(d, "AF_NETROM", AF_NETROM); /* Amateur radio NetROM */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2400 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2401 #ifdef AF_BRIDGE |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2402 insint(d, "AF_BRIDGE", AF_BRIDGE); /* Multiprotocol bridge */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2403 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2404 #ifdef AF_AAL5 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2405 insint(d, "AF_AAL5", AF_AAL5); /* Reserved for Werner's ATM */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2406 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2407 #ifdef AF_X25 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2408 insint(d, "AF_X25", AF_X25); /* Reserved for X.25 project */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2409 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2410 #ifdef AF_INET6 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2411 insint(d, "AF_INET6", AF_INET6); /* IP version 6 */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2412 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2413 #ifdef AF_ROSE |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2414 insint(d, "AF_ROSE", AF_ROSE); /* Amateur Radio X.25 PLP */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2415 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2416 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2417 /* Socket types */ |
| 294 | 2418 insint(d, "SOCK_STREAM", SOCK_STREAM); |
| 2419 insint(d, "SOCK_DGRAM", SOCK_DGRAM); | |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2420 #ifndef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2421 /* We have incomplete socket support. */ |
| 294 | 2422 insint(d, "SOCK_RAW", SOCK_RAW); |
| 2423 insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET); | |
| 2424 insint(d, "SOCK_RDM", SOCK_RDM); | |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2425 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2426 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2427 #ifdef SO_DEBUG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2428 insint(d, "SO_DEBUG", SO_DEBUG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2429 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2430 #ifdef SO_ACCEPTCONN |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2431 insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2432 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2433 #ifdef SO_REUSEADDR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2434 insint(d, "SO_REUSEADDR", SO_REUSEADDR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2435 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2436 #ifdef SO_KEEPALIVE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2437 insint(d, "SO_KEEPALIVE", SO_KEEPALIVE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2438 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2439 #ifdef SO_DONTROUTE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2440 insint(d, "SO_DONTROUTE", SO_DONTROUTE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2441 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2442 #ifdef SO_BROADCAST |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2443 insint(d, "SO_BROADCAST", SO_BROADCAST); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2444 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2445 #ifdef SO_USELOOPBACK |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2446 insint(d, "SO_USELOOPBACK", SO_USELOOPBACK); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2447 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2448 #ifdef SO_LINGER |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2449 insint(d, "SO_LINGER", SO_LINGER); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2450 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2451 #ifdef SO_OOBINLINE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2452 insint(d, "SO_OOBINLINE", SO_OOBINLINE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2453 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2454 #ifdef SO_REUSEPORT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2455 insint(d, "SO_REUSEPORT", SO_REUSEPORT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2456 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2457 #ifdef SO_SNDBUF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2458 insint(d, "SO_SNDBUF", SO_SNDBUF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2459 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2460 #ifdef SO_RCVBUF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2461 insint(d, "SO_RCVBUF", SO_RCVBUF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2462 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2463 #ifdef SO_SNDLOWAT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2464 insint(d, "SO_SNDLOWAT", SO_SNDLOWAT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2465 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2466 #ifdef SO_RCVLOWAT |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2467 insint(d, "SO_RCVLOWAT", SO_RCVLOWAT); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2468 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2469 #ifdef SO_SNDTIMEO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2470 insint(d, "SO_SNDTIMEO", SO_SNDTIMEO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2471 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2472 #ifdef SO_RCVTIMEO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2473 insint(d, "SO_RCVTIMEO", SO_RCVTIMEO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2474 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2475 #ifdef SO_ERROR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2476 insint(d, "SO_ERROR", SO_ERROR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2477 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2478 #ifdef SO_TYPE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2479 insint(d, "SO_TYPE", SO_TYPE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2480 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2481 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2482 /* Maximum number of connections for "listen" */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2483 #ifdef SOMAXCONN |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2484 insint(d, "SOMAXCONN", SOMAXCONN); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2485 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2486 insint(d, "SOMAXCONN", 5); /* Common value */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2487 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2488 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2489 /* Flags for send, recv */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2490 #ifdef MSG_OOB |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2491 insint(d, "MSG_OOB", MSG_OOB); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2492 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2493 #ifdef MSG_PEEK |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2494 insint(d, "MSG_PEEK", MSG_PEEK); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2495 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2496 #ifdef MSG_DONTROUTE |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2497 insint(d, "MSG_DONTROUTE", MSG_DONTROUTE); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2498 #endif |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
2499 #ifdef MSG_DONTWAIT |
|
12493
04cfa1341a50
Fix typo in last patch -- the symbol's name is MSG_DONWAIT, not
Guido van Rossum <guido@python.org>
parents:
12492
diff
changeset
|
2500 insint(d, "MSG_DONTWAIT", MSG_DONTWAIT); |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
2501 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2502 #ifdef MSG_EOR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2503 insint(d, "MSG_EOR", MSG_EOR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2504 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2505 #ifdef MSG_TRUNC |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2506 insint(d, "MSG_TRUNC", MSG_TRUNC); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2507 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2508 #ifdef MSG_CTRUNC |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2509 insint(d, "MSG_CTRUNC", MSG_CTRUNC); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2510 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2511 #ifdef MSG_WAITALL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2512 insint(d, "MSG_WAITALL", MSG_WAITALL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2513 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2514 #ifdef MSG_BTAG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2515 insint(d, "MSG_BTAG", MSG_BTAG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2516 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2517 #ifdef MSG_ETAG |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2518 insint(d, "MSG_ETAG", MSG_ETAG); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2519 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2520 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2521 /* Protocol level and numbers, usable for [gs]etsockopt */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2522 #ifdef SOL_SOCKET |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2523 insint(d, "SOL_SOCKET", SOL_SOCKET); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2524 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2525 #ifdef SOL_IP |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2526 insint(d, "SOL_IP", SOL_IP); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2527 #else |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2528 insint(d, "SOL_IP", 0); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2529 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2530 #ifdef SOL_IPX |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2531 insint(d, "SOL_IPX", SOL_IPX); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2532 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2533 #ifdef SOL_AX25 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2534 insint(d, "SOL_AX25", SOL_AX25); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2535 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2536 #ifdef SOL_ATALK |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2537 insint(d, "SOL_ATALK", SOL_ATALK); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2538 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2539 #ifdef SOL_NETROM |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2540 insint(d, "SOL_NETROM", SOL_NETROM); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2541 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2542 #ifdef SOL_ROSE |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2543 insint(d, "SOL_ROSE", SOL_ROSE); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2544 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2545 #ifdef SOL_TCP |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2546 insint(d, "SOL_TCP", SOL_TCP); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2547 #else |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2548 insint(d, "SOL_TCP", 6); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2549 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2550 #ifdef SOL_UDP |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2551 insint(d, "SOL_UDP", SOL_UDP); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2552 #else |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2553 insint(d, "SOL_UDP", 17); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2554 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2555 #ifdef IPPROTO_IP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2556 insint(d, "IPPROTO_IP", IPPROTO_IP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2557 #else |
|
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2558 insint(d, "IPPROTO_IP", 0); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2559 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2560 #ifdef IPPROTO_ICMP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2561 insint(d, "IPPROTO_ICMP", IPPROTO_ICMP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2562 #else |
|
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2563 insint(d, "IPPROTO_ICMP", 1); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2564 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2565 #ifdef IPPROTO_IGMP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2566 insint(d, "IPPROTO_IGMP", IPPROTO_IGMP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2567 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2568 #ifdef IPPROTO_GGP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2569 insint(d, "IPPROTO_GGP", IPPROTO_GGP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2570 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2571 #ifdef IPPROTO_TCP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2572 insint(d, "IPPROTO_TCP", IPPROTO_TCP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2573 #else |
|
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2574 insint(d, "IPPROTO_TCP", 6); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2575 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2576 #ifdef IPPROTO_EGP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2577 insint(d, "IPPROTO_EGP", IPPROTO_EGP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2578 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2579 #ifdef IPPROTO_PUP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2580 insint(d, "IPPROTO_PUP", IPPROTO_PUP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2581 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2582 #ifdef IPPROTO_UDP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2583 insint(d, "IPPROTO_UDP", IPPROTO_UDP); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2584 #else |
|
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2585 insint(d, "IPPROTO_UDP", 17); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2586 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2587 #ifdef IPPROTO_IDP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2588 insint(d, "IPPROTO_IDP", IPPROTO_IDP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2589 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2590 #ifdef IPPROTO_HELLO |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2591 insint(d, "IPPROTO_HELLO", IPPROTO_HELLO); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2592 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2593 #ifdef IPPROTO_ND |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2594 insint(d, "IPPROTO_ND", IPPROTO_ND); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2595 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2596 #ifdef IPPROTO_TP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2597 insint(d, "IPPROTO_TP", IPPROTO_TP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2598 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2599 #ifdef IPPROTO_XTP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2600 insint(d, "IPPROTO_XTP", IPPROTO_XTP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2601 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2602 #ifdef IPPROTO_EON |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2603 insint(d, "IPPROTO_EON", IPPROTO_EON); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2604 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2605 #ifdef IPPROTO_BIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2606 insint(d, "IPPROTO_BIP", IPPROTO_BIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2607 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2608 /**/ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2609 #ifdef IPPROTO_RAW |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2610 insint(d, "IPPROTO_RAW", IPPROTO_RAW); |
|
8439
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2611 #else |
|
534602746079
Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents:
7942
diff
changeset
|
2612 insint(d, "IPPROTO_RAW", 255); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2613 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2614 #ifdef IPPROTO_MAX |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2615 insint(d, "IPPROTO_MAX", IPPROTO_MAX); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2616 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2617 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2618 /* Some port configuration */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2619 #ifdef IPPORT_RESERVED |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2620 insint(d, "IPPORT_RESERVED", IPPORT_RESERVED); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2621 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2622 insint(d, "IPPORT_RESERVED", 1024); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2623 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2624 #ifdef IPPORT_USERRESERVED |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2625 insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2626 #else |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2627 insint(d, "IPPORT_USERRESERVED", 5000); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2628 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2629 |
| 2369 | 2630 /* Some reserved IP v.4 addresses */ |
| 2631 #ifdef INADDR_ANY | |
| 2632 insint(d, "INADDR_ANY", INADDR_ANY); | |
| 2633 #else | |
| 2634 insint(d, "INADDR_ANY", 0x00000000); | |
| 2635 #endif | |
| 2636 #ifdef INADDR_BROADCAST | |
| 2637 insint(d, "INADDR_BROADCAST", INADDR_BROADCAST); | |
| 2638 #else | |
| 2639 insint(d, "INADDR_BROADCAST", 0xffffffff); | |
| 2640 #endif | |
| 2641 #ifdef INADDR_LOOPBACK | |
| 2642 insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK); | |
| 2643 #else | |
| 2644 insint(d, "INADDR_LOOPBACK", 0x7F000001); | |
| 2645 #endif | |
| 2646 #ifdef INADDR_UNSPEC_GROUP | |
| 2647 insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); | |
| 2648 #else | |
| 2649 insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000); | |
| 2650 #endif | |
| 2651 #ifdef INADDR_ALLHOSTS_GROUP | |
| 2652 insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP); | |
| 2653 #else | |
| 2654 insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001); | |
| 2655 #endif | |
| 2656 #ifdef INADDR_MAX_LOCAL_GROUP | |
| 2657 insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP); | |
| 2658 #else | |
| 2659 insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); | |
| 2660 #endif | |
| 2661 #ifdef INADDR_NONE | |
| 2662 insint(d, "INADDR_NONE", INADDR_NONE); | |
| 2663 #else | |
| 2664 insint(d, "INADDR_NONE", 0xffffffff); | |
| 2665 #endif | |
| 2666 | |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2667 /* IP [gs]etsockopt options */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2668 #ifdef IP_OPTIONS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2669 insint(d, "IP_OPTIONS", IP_OPTIONS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2670 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2671 #ifdef IP_HDRINCL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2672 insint(d, "IP_HDRINCL", IP_HDRINCL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2673 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2674 #ifdef IP_TOS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2675 insint(d, "IP_TOS", IP_TOS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2676 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2677 #ifdef IP_TTL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2678 insint(d, "IP_TTL", IP_TTL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2679 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2680 #ifdef IP_RECVOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2681 insint(d, "IP_RECVOPTS", IP_RECVOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2682 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2683 #ifdef IP_RECVRETOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2684 insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2685 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2686 #ifdef IP_RECVDSTADDR |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2687 insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2688 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2689 #ifdef IP_RETOPTS |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2690 insint(d, "IP_RETOPTS", IP_RETOPTS); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2691 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2692 #ifdef IP_MULTICAST_IF |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2693 insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2694 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2695 #ifdef IP_MULTICAST_TTL |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2696 insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2697 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2698 #ifdef IP_MULTICAST_LOOP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2699 insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2700 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2701 #ifdef IP_ADD_MEMBERSHIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2702 insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2703 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2704 #ifdef IP_DROP_MEMBERSHIP |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2705 insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2706 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2707 #ifdef IP_DEFAULT_MULTICAST_TTL |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2708 insint(d, "IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2709 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2710 #ifdef IP_DEFAULT_MULTICAST_LOOP |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2711 insint(d, "IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2712 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2713 #ifdef IP_MAX_MEMBERSHIPS |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2714 insint(d, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2715 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2716 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2717 /* TCP options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2718 #ifdef TCP_NODELAY |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2719 insint(d, "TCP_NODELAY", TCP_NODELAY); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2720 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2721 #ifdef TCP_MAXSEG |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2722 insint(d, "TCP_MAXSEG", TCP_MAXSEG); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2723 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2724 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2725 /* IPX options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2726 #ifdef IPX_TYPE |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2727 insint(d, "IPX_TYPE", IPX_TYPE); |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2728 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2729 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2730 /* Initialize gethostbyname lock */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2731 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
2732 gethostbyname_lock = PyThread_allocate_lock(); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2733 #endif |
| 294 | 2734 } |
