Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.c @ 23295:6fa76b4e59fe legacy-trunk
Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs. The
most common usage error is of this form (often spread out across gotos):
if (_PyString_Resize(&s, n) < 0) {
Py_DECREF(s);
s = NULL;
goto outtahere;
}
The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL. So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s): s is already
NULL! A correct way to write the above is the simpler (and intended)
if (_PyString_Resize(&s, n) < 0)
goto outtahere;
Bugfix candidate.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Sat, 27 Apr 2002 18:44:32 +0000 |
| parents | 72778ec94dec |
| children | 565032b48f50 |
| rev | line source |
|---|---|
| 294 | 1 /* Socket module */ |
| 2 | |
| 3 /* | |
| 4 This module provides an interface to Berkeley socket IPC. | |
| 5 | |
| 6 Limitations: | |
| 7 | |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
8 - only AF_INET, AF_INET6 and AF_UNIX address families are supported in a |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
9 portable manner, though AF_PACKET is supported under Linux. |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
10 - no read/write operations (use sendall/recv or makefile instead) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
11 - additional restrictions apply on Windows (compensated for by socket.py) |
| 294 | 12 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
13 Module interface: |
| 294 | 14 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
15 - socket.error: exception raised for socket specific errors |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
16 - socket.gaierror: exception raised for getaddrinfo/getnameinfo errors, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
17 a subclass of socket.error |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
18 - socket.herror: exception raised for gethostby* errors, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
19 a subclass of socket.error |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
20 - 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
|
21 - 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
|
22 - 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
|
23 - socket.getprotobyname(protocolname) --> protocol number |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
24 - 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
|
25 - 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
|
26 - 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
|
27 - 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
|
28 - 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
|
29 - socket.htonl(32 bit value) --> new int object |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
30 - socket.getaddrinfo(host, port [, family, socktype, proto, flags]) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
31 --> List of (family, socktype, proto, canonname, sockaddr) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
32 - socket.getnameinfo(sockaddr, flags) --> (host, port) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
33 - 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
|
34 - 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
|
35 - socket.inet_ntoa(packed IP) -> IP address string |
| 294 | 36 - an Internet socket address is a pair (hostname, port) |
| 37 where hostname can be anything recognized by gethostbyname() | |
| 38 (including the dd.dd.dd.dd notation) and port is in host byte order | |
| 39 - 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
|
40 - a UNIX domain socket address is a string specifying the pathname |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
41 - an AF_PACKET socket address is a tuple containing a string |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
42 specifying the ethernet interface and an integer specifying |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
43 the Ethernet protocol number to be received. For example: |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
44 ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple |
|
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
45 specify packet-type and ha-type/addr -- these are ignored by |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
46 networking code, but accepted since they are returned by the |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
47 getsockname() method. |
| 294 | 48 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
49 Socket methods: |
| 294 | 50 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
51 - 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
|
52 - s.bind(sockaddr) --> None |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
53 - s.close() --> None |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
54 - s.connect(sockaddr) --> None |
|
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
55 - 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
|
56 - 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
|
57 - 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
|
58 - s.getpeername() --> sockaddr |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
59 - s.getsockname() --> sockaddr |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
60 - s.getsockopt(level, optname[, buflen]) --> int or string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
61 - s.listen(backlog) --> None |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
62 - s.makefile([mode[, bufsize]]) --> file object |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
63 - s.recv(buflen [,flags]) --> string |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
64 - 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
|
65 - s.send(string [,flags]) --> nbytes |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
66 - s.sendall(string [,flags]) # tries to send everything in a loop |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
67 - s.sendto(string, [flags,] sockaddr) --> nbytes |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
68 - s.setblocking(0 | 1) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
69 - s.setsockopt(level, optname, value) --> None |
|
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
70 - s.shutdown(how) --> None |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
71 - 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
|
72 |
| 294 | 73 */ |
| 74 | |
| 1970 | 75 #include "Python.h" |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
76 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
77 /* XXX This is a terrible mess of of platform-dependent preprocessor hacks. |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
78 I hope some day someone can clean this up please... */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
79 |
|
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
|
80 /* 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
|
81 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
|
82 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
|
83 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
|
84 |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
85 #ifndef linux |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
86 # undef HAVE_GETHOSTBYNAME_R_3_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
87 # undef HAVE_GETHOSTBYNAME_R_5_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
88 # 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
|
89 #endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
90 |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
91 #ifndef WITH_THREAD |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
92 # undef 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
|
93 #endif |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
94 |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
95 #ifdef HAVE_GETHOSTBYNAME_R |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
96 # if defined(_AIX) || defined(__osf__) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
97 # define HAVE_GETHOSTBYNAME_R_3_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
98 # elif defined(__sun) || defined(__sgi) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
99 # define HAVE_GETHOSTBYNAME_R_5_ARG |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
100 # 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
|
101 /* Rely on the configure script */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
102 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
103 # undef HAVE_GETHOSTBYNAME_R |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
104 # endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
105 #endif |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
106 |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
107 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
108 # define USE_GETHOSTBYNAME_LOCK |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
109 #endif |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
110 |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
111 #ifdef USE_GETHOSTBYNAME_LOCK |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
112 # include "pythread.h" |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
113 #endif |
| 294 | 114 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
115 #if defined(PYCC_VACPP) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
116 # include <types.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
117 # include <io.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
118 # include <sys/ioctl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
119 # include <utils.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
120 # include <ctype.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
121 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
122 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
123 #if defined(PYOS_OS2) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
124 # define INCL_DOS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
125 # define INCL_DOSERRORS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
126 # define INCL_NOPMAPI |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
127 # include <os2.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
128 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
129 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
130 /* Generic includes */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
131 #include <sys/types.h> |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
132 #include <signal.h> |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
133 |
|
21961
ea23e6e49290
Also fix the comment.
Marc-André Lemburg <mal@egenix.com>
parents:
21960
diff
changeset
|
134 /* Generic socket object definitions and includes */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
135 #define PySocket_BUILDING_SOCKET |
|
21960
7a917ad8f442
Fix the name of the header file.
Marc-André Lemburg <mal@egenix.com>
parents:
21959
diff
changeset
|
136 #include "socketmodule.h" |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
137 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
138 /* Addressing includes */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
139 |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
140 #ifndef MS_WINDOWS |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
141 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
142 /* Non-MS WINDOWS includes */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
143 # include <netdb.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
|
144 |
|
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
|
145 /* Headers needed for inet_ntoa() and inet_addr() */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
146 # ifdef __BEOS__ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
147 # include <net/netdb.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
148 # elif defined(PYOS_OS2) && defined(PYCC_VACPP) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
149 # include <netdb.h> |
|
20871
f576ffd57966
SF patch 473749 compile under OS/2 VA C++, from Michael Muller.
Tim Peters <tim.peters@gmail.com>
parents:
20853
diff
changeset
|
150 typedef size_t socklen_t; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
151 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
152 # include <arpa/inet.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
153 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
154 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
155 # ifndef RISCOS |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
156 # include <fcntl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
157 # else |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
158 # include <sys/fcntl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
159 # define NO_DUP |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
160 int h_errno; /* not used */ |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
161 # endif |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
162 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
163 #else |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
164 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
165 /* MS_WINDOWS includes */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
166 # include <fcntl.h> |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
167 |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
168 #endif |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
169 |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
170 #ifdef HAVE_STDDEF_H |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
171 # include <stddef.h> |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
172 #endif |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
173 |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
174 #ifndef offsetof |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
175 # define offsetof(type, member) ((size_t)(&((type *)0)->member)) |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
176 #endif |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
177 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
178 #ifndef O_NDELAY |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
179 # define O_NDELAY O_NONBLOCK /* For QNX only? */ |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
180 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
181 |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
182 #include "addrinfo.h" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
183 |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
184 #ifndef HAVE_INET_PTON |
|
18790
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
185 int inet_pton (int af, const char *src, void *dst); |
|
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
186 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
187 #endif |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
188 |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
189 #ifdef __APPLE__ |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
190 /* On OS X, getaddrinfo returns no error indication of lookup |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
191 failure, so we must use the emulation instead of the libinfo |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
192 implementation. Unfortunately, performing an autoconf test |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
193 for this bug would require DNS access for the machine performing |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
194 the configuration, which is not acceptable. Therefore, we |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
195 determine the bug just by checking for __APPLE__. If this bug |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
196 gets ever fixed, perhaps checking for sys/version.h would be |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
197 appropriate, which is 10/0 on the system with the bug. */ |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
198 #undef HAVE_GETADDRINFO |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
199 /* avoid clashes with the C library definition of the symbol. */ |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
200 #define getaddrinfo fake_getaddrinfo |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
201 #endif |
|
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
202 |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
203 /* I know this is a bad practice, but it is the easiest... */ |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
204 #if !defined(HAVE_GETADDRINFO) |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
205 #include "getaddrinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
206 #endif |
|
18954
fefcc1e80cee
Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents:
18915
diff
changeset
|
207 #if !defined(HAVE_GETNAMEINFO) |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
208 #include "getnameinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
209 #endif |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
210 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
211 #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
|
212 /* 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
|
213 /* 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
|
214 #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
|
215 #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
|
216 #endif |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
217 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
218 #ifdef MS_WIN32 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
219 # define EAFNOSUPPORT WSAEAFNOSUPPORT |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
220 # define snprintf _snprintf |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
221 #endif |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
222 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
223 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
224 #define SOCKETCLOSE soclose |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
225 #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
|
226 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
227 |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
228 #ifndef SOCKETCLOSE |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
229 #define SOCKETCLOSE close |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
230 #endif |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
231 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
232 /* XXX There's a problem here: *static* functions are not supposed to have |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
233 a Py prefix (or use CapitalizedWords). Later... */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
234 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
235 /* 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
|
236 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
|
237 |
| 1970 | 238 static PyObject *PySocket_Error; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
239 static PyObject *PyH_Error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
240 static PyObject *PyGAI_Error; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
241 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
242 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
243 /* Global variable which is !=0 if Python is running in a RISC OS taskwindow */ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
244 static int taskwindow; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
245 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
246 |
|
21970
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
247 /* A forward reference to the socket type object. |
|
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
248 The PySocketSock_Type variable contains pointers to various functions, |
|
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
249 some of which call PySocketSock_New(), which uses PySocketSock_Type, so |
|
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
250 there has to be a circular reference. */ |
|
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
251 staticforward PyTypeObject PySocketSock_Type; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
252 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
253 /* 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
|
254 and return a NULL pointer from a function. */ |
| 294 | 255 |
| 1970 | 256 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
257 PySocket_Err(void) |
| 294 | 258 { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
259 #ifdef MS_WINDOWS |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
260 int err_no = WSAGetLastError(); |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
261 if (err_no) { |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
262 static struct { int no; const char *msg; } *msgp, msgs[] = { |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
263 { WSAEINTR, "Interrupted system call" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
264 { WSAEBADF, "Bad file descriptor" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
265 { WSAEACCES, "Permission denied" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
266 { WSAEFAULT, "Bad address" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
267 { WSAEINVAL, "Invalid argument" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
268 { WSAEMFILE, "Too many open files" }, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
269 { WSAEWOULDBLOCK, |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
270 "The socket operation could not complete " |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
271 "without blocking" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
272 { WSAEINPROGRESS, "Operation now in progress" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
273 { WSAEALREADY, "Operation already in progress" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
274 { WSAENOTSOCK, "Socket operation on non-socket" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
275 { WSAEDESTADDRREQ, "Destination address required" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
276 { WSAEMSGSIZE, "Message too long" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
277 { WSAEPROTOTYPE, "Protocol wrong type for socket" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
278 { WSAENOPROTOOPT, "Protocol not available" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
279 { WSAEPROTONOSUPPORT, "Protocol not supported" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
280 { WSAESOCKTNOSUPPORT, "Socket type not supported" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
281 { WSAEOPNOTSUPP, "Operation not supported" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
282 { WSAEPFNOSUPPORT, "Protocol family not supported" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
283 { WSAEAFNOSUPPORT, "Address family not supported" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
284 { WSAEADDRINUSE, "Address already in use" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
285 { WSAEADDRNOTAVAIL, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
286 "Can't assign requested address" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
287 { WSAENETDOWN, "Network is down" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
288 { WSAENETUNREACH, "Network is unreachable" }, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
289 { WSAENETRESET, |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
290 "Network dropped connection on reset" }, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
291 { WSAECONNABORTED, |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
292 "Software caused connection abort" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
293 { WSAECONNRESET, "Connection reset by peer" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
294 { WSAENOBUFS, "No buffer space available" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
295 { WSAEISCONN, "Socket is already connected" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
296 { WSAENOTCONN, "Socket is not connected" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
297 { WSAESHUTDOWN, "Can't send after socket shutdown" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
298 { WSAETOOMANYREFS, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
299 "Too many references: can't splice" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
300 { WSAETIMEDOUT, "Operation timed out" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
301 { WSAECONNREFUSED, "Connection refused" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
302 { WSAELOOP, "Too many levels of symbolic links" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
303 { WSAENAMETOOLONG, "File name too long" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
304 { WSAEHOSTDOWN, "Host is down" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
305 { WSAEHOSTUNREACH, "No route to host" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
306 { WSAENOTEMPTY, "Directory not empty" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
307 { WSAEPROCLIM, "Too many processes" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
308 { WSAEUSERS, "Too many users" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
309 { WSAEDQUOT, "Disc quota exceeded" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
310 { WSAESTALE, "Stale NFS file handle" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
311 { WSAEREMOTE, "Too many levels of remote in path" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
312 { WSASYSNOTREADY, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
313 "Network subsystem is unvailable" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
314 { WSAVERNOTSUPPORTED, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
315 "WinSock version is not supported" }, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
316 { WSANOTINITIALISED, |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
317 "Successful WSAStartup() not yet performed" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
318 { WSAEDISCON, "Graceful shutdown in progress" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
319 /* Resolver errors */ |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
320 { WSAHOST_NOT_FOUND, "No such host is known" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
321 { WSATRY_AGAIN, "Host not found, or server failed" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
322 { WSANO_RECOVERY, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
323 "Unexpected server error encountered" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
324 { WSANO_DATA, "Valid name without requested data" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
325 { WSANO_ADDRESS, "No address, look for MX record" }, |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
326 { 0, NULL } |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
327 }; |
| 1970 | 328 PyObject *v; |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
329 const char *msg = "winsock error"; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
330 |
|
13680
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
331 for (msgp = msgs; msgp->msg; msgp++) { |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
332 if (err_no == msgp->no) { |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
333 msg = msgp->msg; |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
334 break; |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
335 } |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
336 } |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
337 |
|
9f6189e89212
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents:
13667
diff
changeset
|
338 v = Py_BuildValue("(is)", err_no, msg); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
339 if (v != NULL) { |
| 1970 | 340 PyErr_SetObject(PySocket_Error, v); |
| 341 Py_DECREF(v); | |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
342 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
343 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
344 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
345 else |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
346 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
347 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
348 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
349 if (sock_errno() != NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
350 APIRET rc; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
351 ULONG msglen; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
352 char outbuf[100]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
353 int myerrorcode = sock_errno(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
354 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
355 /* 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
|
356 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
357 myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
358 if (rc == NO_ERROR) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
359 PyObject *v; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
360 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
361 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
|
362 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
|
363 char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
364 while (lastc > outbuf && isspace(*lastc)) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
365 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
366 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
367 v = Py_BuildValue("(is)", myerrorcode, outbuf); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
368 if (v != NULL) { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
369 PyErr_SetObject(PySocket_Error, v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
370 Py_DECREF(v); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
371 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
372 return NULL; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
373 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
374 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
375 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
376 |
| 1970 | 377 return PyErr_SetFromErrno(PySocket_Error); |
| 294 | 378 } |
| 379 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
380 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
381 static PyObject * |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
382 PyH_Err(int h_error) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
383 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
384 PyObject *v; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
385 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
386 #ifdef HAVE_HSTRERROR |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
387 v = Py_BuildValue("(is)", h_error, (char *)hstrerror(h_error)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
388 #else |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
389 v = Py_BuildValue("(is)", h_error, "host not found"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
390 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
391 if (v != NULL) { |
|
18996
9059e7c1d8b0
Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the three
Martin v. Löwis <martin@v.loewis.de>
parents:
18954
diff
changeset
|
392 PyErr_SetObject(PyH_Error, v); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
393 Py_DECREF(v); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
394 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
395 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
396 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
397 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
398 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
399 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
400 static PyObject * |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
401 PyGAI_Err(int error) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
402 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
403 PyObject *v; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
404 |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
405 #ifdef EAI_SYSTEM |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
406 /* EAI_SYSTEM is not available on Windows XP. */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
407 if (error == EAI_SYSTEM) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
408 return PySocket_Err(); |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
409 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
410 |
|
19278
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
411 #ifdef HAVE_GAI_STRERROR |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
412 v = Py_BuildValue("(is)", error, gai_strerror(error)); |
|
19278
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
413 #else |
|
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
414 v = Py_BuildValue("(is)", error, "getaddrinfo failed"); |
|
1afc3116c602
Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents:
19197
diff
changeset
|
415 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
416 if (v != NULL) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
417 PyErr_SetObject(PyGAI_Error, v); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
418 Py_DECREF(v); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
419 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
420 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
421 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
422 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
423 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
424 /* Initialize a new socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
425 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
426 static void |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
427 init_sockobject(PySocketSockObject *s, |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
428 SOCKET_T fd, int family, int type, int proto) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
429 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
430 #ifdef RISCOS |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
431 int block = 1; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
432 #endif |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
433 s->sock_fd = fd; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
434 s->sock_family = family; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
435 s->sock_type = type; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
436 s->sock_proto = proto; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
437 s->errorhandler = &PySocket_Err; |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
438 #ifdef RISCOS |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
439 if(taskwindow) { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
440 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
441 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
442 #endif |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
443 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
444 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
445 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
446 /* Create a new socket object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
447 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
|
448 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
|
449 in NEWOBJ()). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
450 |
| 1970 | 451 static PySocketSockObject * |
| 13470 | 452 PySocketSock_New(SOCKET_T fd, int family, int type, int proto) |
| 294 | 453 { |
| 1970 | 454 PySocketSockObject *s; |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
455 s = (PySocketSockObject *) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
456 PyType_GenericNew(&PySocketSock_Type, NULL, NULL); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
457 if (s != NULL) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
458 init_sockobject(s, fd, family, type, proto); |
| 294 | 459 return s; |
| 460 } | |
| 461 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
462 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
463 /* Lock to allow python interpreter to continue, but only allow one |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
464 thread to be in gethostbyname */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
465 #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
|
466 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
|
467 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
468 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
469 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
470 /* 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
|
471 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
|
472 to do the work; the names "" and "<broadcast>" are special. |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
473 Return the length (IPv4 should be 4 bytes), or negative if |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
474 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
|
475 |
| 294 | 476 static int |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
477 setipaddr(char* name, struct sockaddr * addr_ret, int af) |
| 294 | 478 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
479 struct addrinfo hints, *res; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
480 int error; |
| 294 | 481 |
| 4600 | 482 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
|
483 if (name[0] == '\0') { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
484 int siz; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
485 memset(&hints, 0, sizeof(hints)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
486 hints.ai_family = af; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
487 hints.ai_socktype = SOCK_DGRAM; /*dummy*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
488 hints.ai_flags = AI_PASSIVE; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
489 error = getaddrinfo(NULL, "0", &hints, &res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
490 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
491 PyGAI_Err(error); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
492 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
493 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
494 switch (res->ai_family) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
495 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
496 siz = 4; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
497 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
498 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
499 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
500 siz = 16; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
501 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
502 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
503 default: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
504 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
505 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
506 "unsupported address family"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
507 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
508 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
509 if (res->ai_next) { |
|
20912
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
510 freeaddrinfo(res); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
511 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
512 "wildcard resolved to multiple address"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
513 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
514 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
515 memcpy(addr_ret, res->ai_addr, res->ai_addrlen); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
516 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
517 return siz; |
| 294 | 518 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
519 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
520 struct sockaddr_in *sin; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
521 if (af != PF_INET && af != PF_UNSPEC) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
522 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
523 "address family mismatched"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
524 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
525 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
526 sin = (struct sockaddr_in *)addr_ret; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
527 memset((void *) sin, '\0', sizeof(*sin)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
528 sin->sin_family = AF_INET; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
529 #ifdef HAVE_SOCKADDR_SA_LEN |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
530 sin->sin_len = sizeof(*sin); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
531 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
532 sin->sin_addr.s_addr = INADDR_BROADCAST; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
533 return sizeof(sin->sin_addr); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
534 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
535 memset(&hints, 0, sizeof(hints)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
536 hints.ai_family = af; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
537 error = getaddrinfo(name, NULL, &hints, &res); |
|
20661
f7009167dd67
After discussion with itojun, it was clarified that Tru64 is in error,
Martin v. Löwis <martin@v.loewis.de>
parents:
20654
diff
changeset
|
538 #if defined(__digital__) && defined(__unix__) |
|
20648
fec950d8c25d
Fix typo. Thanks to Jack Jansen for spotting it.
Martin v. Löwis <martin@v.loewis.de>
parents:
20646
diff
changeset
|
539 if (error == EAI_NONAME && af == AF_UNSPEC) { |
|
20661
f7009167dd67
After discussion with itojun, it was clarified that Tru64 is in error,
Martin v. Löwis <martin@v.loewis.de>
parents:
20654
diff
changeset
|
540 /* On Tru64 V5.1, numeric-to-addr conversion |
|
20646
cabb568a558b
Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents:
20564
diff
changeset
|
541 fails if no address family is given. Assume IPv4 for now.*/ |
|
cabb568a558b
Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents:
20564
diff
changeset
|
542 hints.ai_family = AF_INET; |
|
cabb568a558b
Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents:
20564
diff
changeset
|
543 error = getaddrinfo(name, NULL, &hints, &res); |
|
cabb568a558b
Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents:
20564
diff
changeset
|
544 } |
|
20661
f7009167dd67
After discussion with itojun, it was clarified that Tru64 is in error,
Martin v. Löwis <martin@v.loewis.de>
parents:
20654
diff
changeset
|
545 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
546 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
547 PyGAI_Err(error); |
| 294 | 548 return -1; |
| 549 } | |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
550 memcpy((char *) addr_ret, res->ai_addr, res->ai_addrlen); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
551 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
552 switch (addr_ret->sa_family) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
553 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
554 return 4; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
555 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
556 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
557 return 16; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
558 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
559 default: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
560 PyErr_SetString(PySocket_Error, "unknown address family"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
561 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
562 } |
| 294 | 563 } |
| 564 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
565 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
566 /* 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
|
567 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
|
568 size numbers). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
569 |
| 1970 | 570 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
571 makeipaddr(struct sockaddr *addr, int addrlen) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
572 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
573 char buf[NI_MAXHOST]; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
574 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
575 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
576 error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
577 NI_NUMERICHOST); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
578 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
579 PyGAI_Err(error); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
580 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
581 } |
| 1970 | 582 return PyString_FromString(buf); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
583 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
584 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
585 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
586 /* 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
|
587 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
|
588 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
|
589 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
|
590 |
| 294 | 591 /*ARGSUSED*/ |
| 1970 | 592 static PyObject * |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
593 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen) |
| 294 | 594 { |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
595 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
|
596 /* No address -- may be recvfrom() from known socket */ |
| 1970 | 597 Py_INCREF(Py_None); |
| 598 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
|
599 } |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
600 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
601 #ifdef __BEOS__ |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
602 /* 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
|
603 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
|
604 #endif |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
605 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
606 switch (addr->sa_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
607 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
608 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
609 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
610 struct sockaddr_in *a; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
611 PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
612 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
613 if (addrobj) { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
614 a = (struct sockaddr_in *)addr; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
615 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
|
616 Py_DECREF(addrobj); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
617 } |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
618 return ret; |
| 294 | 619 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
620 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
621 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
622 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
623 { |
| 294 | 624 struct sockaddr_un *a = (struct sockaddr_un *) addr; |
| 1970 | 625 return PyString_FromString(a->sun_path); |
| 294 | 626 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
627 #endif /* AF_UNIX */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
628 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
629 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
630 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
631 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
632 struct sockaddr_in6 *a; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
633 PyObject *addrobj = makeipaddr(addr, sizeof(*a)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
634 PyObject *ret = NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
635 if (addrobj) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
636 a = (struct sockaddr_in6 *)addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
637 ret = Py_BuildValue("Oiii", addrobj, ntohs(a->sin6_port), |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
638 a->sin6_flowinfo, a->sin6_scope_id); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
639 Py_DECREF(addrobj); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
640 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
641 return ret; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
642 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
643 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
644 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
645 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
646 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
647 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
648 struct sockaddr_ll *a = (struct sockaddr_ll *)addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
649 char *ifname = ""; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
650 struct ifreq ifr; |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
651 /* need to look up interface name give index */ |
|
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
652 if (a->sll_ifindex) { |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
653 ifr.ifr_ifindex = a->sll_ifindex; |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
654 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
655 ifname = ifr.ifr_name; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
656 } |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
657 return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol), |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
658 a->sll_pkttype, a->sll_hatype, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
659 a->sll_addr, a->sll_halen); |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
660 } |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
661 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
662 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
663 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
664 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
665 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
|
666 /* 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
673 } |
| 294 | 674 } |
| 675 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
676 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
677 /* 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
|
678 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
|
679 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
|
680 through len_ret. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
681 |
| 294 | 682 static int |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
683 getsockaddrarg(PySocketSockObject *s, PyObject *args, |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
684 struct sockaddr **addr_ret, int *len_ret) |
| 294 | 685 { |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
686 switch (s->sock_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
687 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
688 #ifdef AF_UNIX |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
689 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
690 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
691 struct sockaddr_un* addr; |
| 926 | 692 char *path; |
| 294 | 693 int len; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
694 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
|
695 if (!PyArg_Parse(args, "t#", &path, &len)) |
| 294 | 696 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
697 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
|
698 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
699 "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
|
700 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
701 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
702 addr->sun_family = s->sock_family; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
703 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
|
704 addr->sun_path[len] = 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
705 *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
|
706 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path); |
| 294 | 707 return 1; |
| 708 } | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
709 #endif /* AF_UNIX */ |
| 294 | 710 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
711 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
712 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
713 struct sockaddr_in* addr; |
| 926 | 714 char *host; |
| 294 | 715 int port; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
716 addr=(struct sockaddr_in*)&(s->sock_addr).in; |
|
15466
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
717 if (!PyTuple_Check(args)) { |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
718 PyErr_Format(PyExc_TypeError, |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
719 "getsockaddrarg: AF_INET address must be tuple, not %.500s", |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
720 args->ob_type->tp_name); |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
721 return 0; |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
722 } |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
723 if (!PyArg_ParseTuple(args, "si:getsockaddrarg", &host, &port)) |
| 294 | 724 return 0; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
725 if (setipaddr(host, (struct sockaddr *)addr, AF_INET) < 0) |
| 294 | 726 return 0; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
727 addr->sin_family = AF_INET; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
728 addr->sin_port = htons((short)port); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
729 *addr_ret = (struct sockaddr *) addr; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
730 *len_ret = sizeof *addr; |
| 294 | 731 return 1; |
| 732 } | |
| 733 | |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
734 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
735 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
736 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
737 struct sockaddr_in6* addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
738 char *host; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
739 int port, flowinfo, scope_id; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
740 addr = (struct sockaddr_in6*)&(s->sock_addr).in6; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
741 flowinfo = scope_id = 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
742 if (!PyArg_ParseTuple(args, "si|ii", &host, &port, &flowinfo, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
743 &scope_id)) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
744 return 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
745 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
746 if (setipaddr(host, (struct sockaddr *)addr, AF_INET6) < 0) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
747 return 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
748 addr->sin6_family = s->sock_family; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
749 addr->sin6_port = htons((short)port); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
750 addr->sin6_flowinfo = flowinfo; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
751 addr->sin6_scope_id = scope_id; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
752 *addr_ret = (struct sockaddr *) addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
753 *len_ret = sizeof *addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
754 return 1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
755 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
756 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
757 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
758 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
759 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
760 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
761 struct sockaddr_ll* addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
762 struct ifreq ifr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
763 char *interfaceName; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
764 int protoNumber; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
765 int hatype = 0; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
766 int pkttype = 0; |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
767 char *haddr; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
768 |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
769 if (!PyArg_ParseTuple(args, "si|iis", &interfaceName, |
|
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
770 &protoNumber, &pkttype, &hatype, &haddr)) |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
771 return 0; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
772 strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
773 ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
774 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
775 s->errorhandler(); |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
776 return 0; |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
777 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
778 addr = &(s->sock_addr.ll); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
779 addr->sll_family = AF_PACKET; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
780 addr->sll_protocol = htons((short)protoNumber); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
781 addr->sll_ifindex = ifr.ifr_ifindex; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
782 addr->sll_pkttype = pkttype; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
783 addr->sll_hatype = hatype; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
784 *addr_ret = (struct sockaddr *) addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
785 *len_ret = sizeof *addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
786 return 1; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
787 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
788 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
789 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
790 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
791 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
792 default: |
| 1970 | 793 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
|
794 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
795 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
796 } |
| 294 | 797 } |
| 798 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
799 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
800 /* Get the address length according to the socket object's address family. |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
801 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
|
802 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
|
803 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
804 static int |
|
13554
906efc1da247
Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13538
diff
changeset
|
805 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
|
806 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
807 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
|
808 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
809 #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
|
810 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
|
811 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
812 *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
|
813 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
814 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
815 #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
|
816 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
817 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
|
818 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
819 *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
|
820 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
821 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
822 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
823 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
824 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
825 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
826 *len_ret = sizeof (struct sockaddr_in6); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
827 return 1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
828 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
829 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
830 |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
831 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
832 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
833 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
834 *len_ret = sizeof (struct sockaddr_ll); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
835 return 1; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
836 } |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
837 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
838 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
839 /* 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
|
840 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
841 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
|
842 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
|
843 return 0; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
844 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
845 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
846 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
847 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
848 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
849 /* s.accept() method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
850 |
| 1970 | 851 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
852 PySocketSock_accept(PySocketSockObject *s) |
| 294 | 853 { |
| 854 char addrbuf[256]; | |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
855 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
|
856 socklen_t addrlen; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
857 PyObject *sock = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
858 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
859 PyObject *res = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
860 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
861 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
|
862 return NULL; |
|
17737
0ebfe9a1eb43
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents:
17537
diff
changeset
|
863 memset(addrbuf, 0, addrlen); |
| 1970 | 864 Py_BEGIN_ALLOW_THREADS |
| 294 | 865 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 866 Py_END_ALLOW_THREADS |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
867 #ifdef MS_WINDOWS |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
868 if (newfd == INVALID_SOCKET) |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
869 #else |
| 294 | 870 if (newfd < 0) |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
871 #endif |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
872 return s->errorhandler(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
873 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
874 /* 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
|
875 to avoid calls to bind() etc. on it. */ |
| 1970 | 876 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
|
877 s->sock_family, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
878 s->sock_type, |
|
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
879 s->sock_proto); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
880 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
|
881 SOCKETCLOSE(newfd); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
882 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
883 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
884 addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
885 addrlen); |
|
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
886 if (addr == NULL) |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
887 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
888 |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
889 res = Py_BuildValue("OO", sock, addr); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
890 |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
891 finally: |
| 1970 | 892 Py_XDECREF(sock); |
| 893 Py_XDECREF(addr); | |
| 294 | 894 return res; |
| 895 } | |
| 896 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
897 static char accept_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
898 "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
|
899 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
900 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
|
901 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
|
902 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
|
903 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
904 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
905 /* 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
|
906 |
| 1970 | 907 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
908 PySocketSock_setblocking(PySocketSockObject *s, PyObject *arg) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
909 { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
910 int block; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
911 #ifndef RISCOS |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
912 #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
|
913 int delay_flag; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
914 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
915 #endif |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
916 block = PyInt_AsLong(arg); |
|
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
917 if (block == -1 && PyErr_Occurred()) |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
918 return NULL; |
| 1970 | 919 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
|
920 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
921 block = !block; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
922 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
|
923 (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
|
924 #else |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
925 #ifndef RISCOS |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
926 #ifndef MS_WINDOWS |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
927 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
928 block = !block; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
929 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
|
930 #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
|
931 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
|
932 if (block) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
933 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
|
934 else |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
935 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
|
936 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
|
937 #endif /* !PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
938 #else /* MS_WINDOWS */ |
|
2736
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
939 block = !block; |
|
37c48fde61b8
add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents:
2565
diff
changeset
|
940 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
|
941 #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
|
942 #endif /* __BEOS__ */ |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
943 #endif /* RISCOS */ |
| 1970 | 944 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
|
945 |
| 1970 | 946 Py_INCREF(Py_None); |
| 947 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
|
948 } |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
949 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
950 static char setblocking_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
951 "setblocking(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
952 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
953 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
|
954 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
|
955 |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
956 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
957 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
958 /* s.sleeptaskw(1 | 0) method */ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
959 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
960 static PyObject * |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
961 PySocketSock_sleeptaskw(PySocketSockObject *s,PyObject *args) |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
962 { |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
963 int block; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
964 int delay_flag; |
|
22568
6a1c8752a65f
Remove last occurrance of PyArg_GetInt. It is deprecated,
Neal Norwitz <nnorwitz@gmail.com>
parents:
22547
diff
changeset
|
965 if (!PyArg_Parse(args, "i", &block)) |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
966 return NULL; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
967 Py_BEGIN_ALLOW_THREADS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
968 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
969 Py_END_ALLOW_THREADS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
970 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
971 Py_INCREF(Py_None); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
972 return Py_None; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
973 } |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
974 static char sleeptaskw_doc[] = |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
975 "sleeptaskw(flag)\n\ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
976 \n\ |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
977 Allow sleeps in taskwindows."; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
978 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
979 |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
980 |
|
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
|
981 /* 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
|
982 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
|
983 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
|
984 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
|
985 |
| 1970 | 986 static PyObject * |
| 13470 | 987 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
|
988 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
989 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
990 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
|
991 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
|
992 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
|
993 int buflen; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
994 int flag; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
995 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
996 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
|
997 &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
|
998 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
|
999 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
|
1000 } |
|
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
|
1001 else { |
| 1970 | 1002 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
|
1003 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
|
1004 &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
|
1005 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
|
1006 } |
|
13709
4e2aaf1e722a
Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents:
13695
diff
changeset
|
1007 res = setsockopt(s->sock_fd, level, optname, (void *)buf, buflen); |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1008 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1009 return s->errorhandler(); |
| 1970 | 1010 Py_INCREF(Py_None); |
| 1011 return Py_None; | |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1012 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1013 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1014 static char setsockopt_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1015 "setsockopt(level, option, value)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1016 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1017 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
|
1018 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
|
1019 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1020 |
|
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
|
1021 /* 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
|
1022 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
|
1023 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
|
1024 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
|
1025 |
| 1970 | 1026 static PyObject * |
| 13470 | 1027 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
|
1028 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1029 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1030 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
|
1031 int res; |
| 1970 | 1032 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
|
1033 socklen_t buflen = 0; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1034 |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1035 #ifdef __BEOS__ |
|
17806
3380279612a3
Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents:
17737
diff
changeset
|
1036 /* We have incomplete socket support. */ |
|
3380279612a3
Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents:
17737
diff
changeset
|
1037 PyErr_SetString(PySocket_Error, "getsockopt not supported"); |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1038 return NULL; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1039 #else |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1040 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1041 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
|
1042 &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
|
1043 return NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1044 |
|
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
|
1045 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
|
1046 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
|
1047 socklen_t flagsize = sizeof flag; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
1048 res = getsockopt(s->sock_fd, level, optname, |
|
13709
4e2aaf1e722a
Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents:
13695
diff
changeset
|
1049 (void *)&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
|
1050 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1051 return s->errorhandler(); |
| 1970 | 1052 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
|
1053 } |
|
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
|
1054 if (buflen <= 0 || buflen > 1024) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1055 PyErr_SetString(PySocket_Error, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1056 "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
|
1057 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
|
1058 } |
| 1970 | 1059 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
|
1060 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
|
1061 return NULL; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
1062 res = getsockopt(s->sock_fd, level, optname, |
|
17806
3380279612a3
Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents:
17737
diff
changeset
|
1063 (void *)PyString_AS_STRING(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
|
1064 if (res < 0) { |
| 1970 | 1065 Py_DECREF(buf); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1066 return s->errorhandler(); |
|
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
|
1067 } |
| 1970 | 1068 _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
|
1069 return buf; |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
1070 #endif /* __BEOS__ */ |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1071 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1072 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1073 static char getsockopt_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1074 "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
|
1075 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1076 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
|
1077 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
|
1078 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
|
1079 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1080 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1081 /* s.bind(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1082 |
| 1970 | 1083 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1084 PySocketSock_bind(PySocketSockObject *s, PyObject *addro) |
| 294 | 1085 { |
| 1086 struct sockaddr *addr; | |
| 1087 int addrlen; | |
| 926 | 1088 int res; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1089 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1090 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 1091 return NULL; |
| 1970 | 1092 Py_BEGIN_ALLOW_THREADS |
| 926 | 1093 res = bind(s->sock_fd, addr, addrlen); |
| 1970 | 1094 Py_END_ALLOW_THREADS |
| 926 | 1095 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1096 return s->errorhandler(); |
| 1970 | 1097 Py_INCREF(Py_None); |
| 1098 return Py_None; | |
| 294 | 1099 } |
| 1100 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1101 static char bind_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1102 "bind(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1103 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1104 Bind the socket to a local address. For IP sockets, the address is a\n\ |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1105 pair (host, port); the host must refer to the local host. For raw packet\n\ |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1106 sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])"; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1107 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1108 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1109 /* s.close() method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1110 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
|
1111 will surely fail. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1112 |
| 1970 | 1113 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1114 PySocketSock_close(PySocketSockObject *s) |
| 294 | 1115 { |
|
15604
15e1eb1019b8
Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
Guido van Rossum <guido@python.org>
parents:
15466
diff
changeset
|
1116 SOCKET_T fd; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1117 |
|
15604
15e1eb1019b8
Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
Guido van Rossum <guido@python.org>
parents:
15466
diff
changeset
|
1118 if ((fd = s->sock_fd) != -1) { |
|
15e1eb1019b8
Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
Guido van Rossum <guido@python.org>
parents:
15466
diff
changeset
|
1119 s->sock_fd = -1; |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1120 Py_BEGIN_ALLOW_THREADS |
|
15604
15e1eb1019b8
Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
Guido van Rossum <guido@python.org>
parents:
15466
diff
changeset
|
1121 (void) SOCKETCLOSE(fd); |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1122 Py_END_ALLOW_THREADS |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1123 } |
| 1970 | 1124 Py_INCREF(Py_None); |
| 1125 return Py_None; | |
| 294 | 1126 } |
| 1127 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1128 static char close_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1129 "close()\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1130 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1131 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
|
1132 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1133 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1134 /* s.connect(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1135 |
| 1970 | 1136 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1137 PySocketSock_connect(PySocketSockObject *s, PyObject *addro) |
| 294 | 1138 { |
| 1139 struct sockaddr *addr; | |
| 1140 int addrlen; | |
| 926 | 1141 int res; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1142 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1143 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 1144 return NULL; |
| 1970 | 1145 Py_BEGIN_ALLOW_THREADS |
| 926 | 1146 res = connect(s->sock_fd, addr, addrlen); |
| 1970 | 1147 Py_END_ALLOW_THREADS |
| 926 | 1148 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1149 return s->errorhandler(); |
| 1970 | 1150 Py_INCREF(Py_None); |
| 1151 return Py_None; | |
| 294 | 1152 } |
| 1153 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1154 static char connect_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1155 "connect(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1156 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1157 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
|
1158 is a pair (host, port)."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1159 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1160 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1161 /* 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
|
1162 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1163 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1164 PySocketSock_connect_ex(PySocketSockObject *s, PyObject *addro) |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1165 { |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1166 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
|
1167 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
|
1168 int res; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1169 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1170 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
|
1171 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
|
1172 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
|
1173 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
|
1174 Py_END_ALLOW_THREADS |
|
20756
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1175 if (res != 0) { |
|
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1176 #ifdef MS_WINDOWS |
|
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1177 res = WSAGetLastError(); |
|
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1178 #else |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1179 res = errno; |
|
20756
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1180 #endif |
|
828bf317880a
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
Tim Peters <tim.peters@gmail.com>
parents:
20730
diff
changeset
|
1181 } |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1182 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
|
1183 } |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1184 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1185 static char connect_ex_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1186 "connect_ex(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1187 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1188 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
|
1189 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
|
1190 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1191 |
|
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
|
1192 /* 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
|
1193 |
| 1970 | 1194 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1195 PySocketSock_fileno(PySocketSockObject *s) |
|
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
|
1196 { |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1197 #if SIZEOF_SOCKET_T <= SIZEOF_LONG |
| 1970 | 1198 return PyInt_FromLong((long) s->sock_fd); |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1199 #else |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1200 return PyLong_FromLongLong((LONG_LONG)s->sock_fd); |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1201 #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
|
1202 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
1203 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1204 static char fileno_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1205 "fileno() -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1206 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1207 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
|
1208 |
|
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
|
1209 |
|
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
|
1210 #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
|
1211 /* 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
|
1212 |
|
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
|
1213 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1214 PySocketSock_dup(PySocketSockObject *s) |
|
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
|
1215 { |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1216 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
|
1217 PyObject *sock; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1218 |
|
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
|
1219 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
|
1220 if (newfd < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1221 return s->errorhandler(); |
|
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
|
1222 sock = (PyObject *) PySocketSock_New(newfd, |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1223 s->sock_family, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1224 s->sock_type, |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1230 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1231 static char dup_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1232 "dup() -> socket object\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1233 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1234 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
|
1235 |
|
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
|
1236 #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
|
1237 |
|
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
|
1238 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1239 /* s.getsockname() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1240 |
| 1970 | 1241 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1242 PySocketSock_getsockname(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1243 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1244 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
|
1245 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
|
1246 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
|
1247 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1248 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1249 return NULL; |
|
3335
9bd1e41d6b11
clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents:
3091
diff
changeset
|
1250 memset(addrbuf, 0, addrlen); |
| 1970 | 1251 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1252 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 1253 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1254 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1255 return s->errorhandler(); |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
1256 return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1257 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1258 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1259 static char getsockname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1260 "getsockname() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1261 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1262 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
|
1263 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
|
1264 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1265 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1266 #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
|
1267 /* s.getpeername() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1268 |
| 1970 | 1269 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1270 PySocketSock_getpeername(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1271 { |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1272 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
|
1273 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
|
1274 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
|
1275 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1276 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1277 return NULL; |
|
17737
0ebfe9a1eb43
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents:
17537
diff
changeset
|
1278 memset(addrbuf, 0, addrlen); |
| 1970 | 1279 Py_BEGIN_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1280 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); |
| 1970 | 1281 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1282 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1283 return s->errorhandler(); |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
1284 return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1285 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1286 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1287 static char getpeername_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1288 "getpeername() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1289 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1290 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
|
1291 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
|
1292 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1293 #endif /* HAVE_GETPEERNAME */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1294 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
1295 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1296 /* s.listen(n) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1297 |
| 1970 | 1298 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1299 PySocketSock_listen(PySocketSockObject *s, PyObject *arg) |
| 294 | 1300 { |
| 1301 int backlog; | |
| 926 | 1302 int res; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1303 |
|
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1304 backlog = PyInt_AsLong(arg); |
|
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1305 if (backlog == -1 && PyErr_Occurred()) |
| 294 | 1306 return NULL; |
| 1970 | 1307 Py_BEGIN_ALLOW_THREADS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1308 if (backlog < 1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1309 backlog = 1; |
| 926 | 1310 res = listen(s->sock_fd, backlog); |
| 1970 | 1311 Py_END_ALLOW_THREADS |
| 926 | 1312 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1313 return s->errorhandler(); |
| 1970 | 1314 Py_INCREF(Py_None); |
| 1315 return Py_None; | |
| 294 | 1316 } |
| 1317 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1318 static char listen_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1319 "listen(backlog)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1320 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1321 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
|
1322 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
|
1323 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
|
1324 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1325 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1326 #ifndef NO_DUP |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1327 /* s.makefile(mode) method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1328 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
|
1329 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
|
1330 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
|
1331 of each other.) |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1332 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
|
1333 |
| 1970 | 1334 static PyObject * |
| 13470 | 1335 PySocketSock_makefile(PySocketSockObject *s, PyObject *args) |
| 294 | 1336 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13403
diff
changeset
|
1337 extern int fclose(FILE *); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1338 char *mode = "r"; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1339 int bufsize = -1; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1340 #ifdef MS_WIN32 |
|
19568
b0f5278a2ab4
SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents:
19415
diff
changeset
|
1341 Py_intptr_t fd; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1342 #else |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1343 int fd; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1344 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1345 FILE *fp; |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1346 PyObject *f; |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1347 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11527
diff
changeset
|
1348 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
|
1349 return NULL; |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1350 #ifdef MS_WIN32 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1351 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
|
1352 ((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
|
1353 #else |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1354 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
|
1355 #endif |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1356 { |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1357 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
|
1358 SOCKETCLOSE(fd); |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1359 return s->errorhandler(); |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1360 } |
|
22547
0922c919cedb
Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents:
22115
diff
changeset
|
1361 #ifdef USE_GUSI2 |
|
0922c919cedb
Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents:
22115
diff
changeset
|
1362 /* Workaround for bug in Metrowerks MSL vs. GUSI I/O library */ |
|
0922c919cedb
Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents:
22115
diff
changeset
|
1363 if (strchr(mode, 'b') != NULL ) |
|
0922c919cedb
Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents:
22115
diff
changeset
|
1364 bufsize = 0; |
|
0922c919cedb
Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents:
22115
diff
changeset
|
1365 #endif |
|
2532
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1366 f = PyFile_FromFile(fp, "<socket>", mode, fclose); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1367 if (f != NULL) |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1368 PyFile_SetBufSize(f, bufsize); |
|
9e5a09841781
mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents:
2369
diff
changeset
|
1369 return f; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1370 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1371 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1372 static char makefile_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1373 "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
|
1374 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1375 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
|
1376 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
|
1377 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1378 #endif /* NO_DUP */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1379 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1380 |
|
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
|
1381 /* 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
|
1382 |
| 1970 | 1383 static PyObject * |
| 13470 | 1384 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
|
1385 { |
|
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
|
1386 int len, n, flags = 0; |
| 1970 | 1387 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
|
1388 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
|
1389 return NULL; |
|
21022
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
1390 if (len < 0) { |
|
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
1391 PyErr_SetString(PyExc_ValueError, |
|
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
1392 "negative buffersize in connect"); |
|
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
1393 return NULL; |
|
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
1394 } |
| 1970 | 1395 buf = PyString_FromStringAndSize((char *) 0, len); |
| 294 | 1396 if (buf == NULL) |
| 1397 return NULL; | |
| 1970 | 1398 Py_BEGIN_ALLOW_THREADS |
|
19401
8607bc890b1f
It will always be a string, because it is created just before this call.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19278
diff
changeset
|
1399 n = recv(s->sock_fd, PyString_AS_STRING(buf), len, flags); |
| 1970 | 1400 Py_END_ALLOW_THREADS |
| 3091 | 1401 if (n < 0) { |
| 1402 Py_DECREF(buf); | |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1403 return s->errorhandler(); |
| 3091 | 1404 } |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
22974
diff
changeset
|
1405 if (n != len) |
|
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
22974
diff
changeset
|
1406 _PyString_Resize(&buf, n); |
| 294 | 1407 return buf; |
| 1408 } | |
| 1409 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1410 static char recv_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1411 "recv(buffersize[, flags]) -> data\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 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
|
1414 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
|
1415 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
|
1416 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
|
1417 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1418 |
|
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
|
1419 /* 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
|
1420 |
| 1970 | 1421 static PyObject * |
| 13470 | 1422 PySocketSock_recvfrom(PySocketSockObject *s, PyObject *args) |
| 294 | 1423 { |
| 1424 char addrbuf[256]; | |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1425 PyObject *buf = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1426 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1427 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1428 |
|
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
|
1429 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
|
1430 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
|
1431 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
|
1432 return NULL; |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1433 if (!getsockaddrlen(s, &addrlen)) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1434 return NULL; |
| 1970 | 1435 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
|
1436 if (buf == NULL) |
|
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
1437 return NULL; |
| 1970 | 1438 Py_BEGIN_ALLOW_THREADS |
|
17737
0ebfe9a1eb43
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents:
17537
diff
changeset
|
1439 memset(addrbuf, 0, addrlen); |
|
0ebfe9a1eb43
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents:
17537
diff
changeset
|
1440 n = recvfrom(s->sock_fd, PyString_AS_STRING(buf), len, flags, |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
1441 #ifndef MS_WINDOWS |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
1442 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
1443 (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
|
1444 #else |
|
13709
4e2aaf1e722a
Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents:
13695
diff
changeset
|
1445 (void *)addrbuf, &addrlen |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
1446 #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
|
1447 #else |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1448 (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
|
1449 #endif |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1450 ); |
| 1970 | 1451 Py_END_ALLOW_THREADS |
| 3091 | 1452 if (n < 0) { |
| 1453 Py_DECREF(buf); | |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1454 return s->errorhandler(); |
| 3091 | 1455 } |
|
3665
5188374377ae
Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents:
3594
diff
changeset
|
1456 if (n != len && _PyString_Resize(&buf, n) < 0) |
| 294 | 1457 return NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1458 |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
1459 if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addrlen))) |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1460 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1461 |
| 1970 | 1462 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
|
1463 finally: |
| 1970 | 1464 Py_XDECREF(addr); |
| 1465 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
|
1466 return ret; |
| 294 | 1467 } |
| 1468 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1469 static char recvfrom_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1470 "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
|
1471 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1472 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
|
1473 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1474 |
|
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
|
1475 /* 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
|
1476 |
| 1970 | 1477 static PyObject * |
| 13470 | 1478 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
|
1479 { |
| 926 | 1480 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
|
1481 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
|
1482 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
|
1483 return NULL; |
| 1970 | 1484 Py_BEGIN_ALLOW_THREADS |
| 926 | 1485 n = send(s->sock_fd, buf, len, flags); |
| 1970 | 1486 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1487 if (n < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1488 return s->errorhandler(); |
| 1970 | 1489 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
|
1490 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1491 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1492 static char send_doc[] = |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1493 "send(data[, flags]) -> count\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1494 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1495 Send a data string to the socket. For the optional flags\n\ |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1496 argument, see the Unix manual. Return the number of bytes\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1497 sent; this may be less than len(data) if the network is busy."; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1498 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1499 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1500 /* s.sendall(data [,flags]) method */ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1501 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1502 static PyObject * |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1503 PySocketSock_sendall(PySocketSockObject *s, PyObject *args) |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1504 { |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1505 char *buf; |
|
21964
94b90cdd6e0f
Remove extraneous variable 'total', as reported by James Rucker.
Martin v. Löwis <martin@v.loewis.de>
parents:
21961
diff
changeset
|
1506 int len, n, flags = 0; |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1507 if (!PyArg_ParseTuple(args, "s#|i:sendall", &buf, &len, &flags)) |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1508 return NULL; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1509 Py_BEGIN_ALLOW_THREADS |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1510 do { |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1511 n = send(s->sock_fd, buf, len, flags); |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1512 if (n < 0) |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1513 break; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1514 buf += n; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1515 len -= n; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1516 } while (len > 0); |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1517 Py_END_ALLOW_THREADS |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1518 if (n < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1519 return s->errorhandler(); |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1520 Py_INCREF(Py_None); |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1521 return Py_None; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1522 } |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1523 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1524 static char sendall_doc[] = |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1525 "sendall(data[, flags])\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1526 \n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1527 Send a data string to the socket. For the optional flags\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1528 argument, see the Unix manual. This calls send() repeatedly\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1529 until all data is sent. If an error occurs, it's impossible\n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1530 to tell how much data has been sent."; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1531 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1532 |
|
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
|
1533 /* 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
|
1534 |
| 1970 | 1535 static PyObject * |
| 13470 | 1536 PySocketSock_sendto(PySocketSockObject *s, PyObject *args) |
| 294 | 1537 { |
| 1970 | 1538 PyObject *addro; |
| 926 | 1539 char *buf; |
| 294 | 1540 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
|
1541 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
|
1542 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
|
1543 if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) { |
| 1970 | 1544 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
|
1545 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
|
1546 &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
|
1547 return NULL; |
| 294 | 1548 } |
|
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
|
1549 if (!getsockaddrarg(s, addro, &addr, &addrlen)) |
| 294 | 1550 return NULL; |
| 1970 | 1551 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
|
1552 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen); |
| 1970 | 1553 Py_END_ALLOW_THREADS |
| 294 | 1554 if (n < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1555 return s->errorhandler(); |
| 1970 | 1556 return PyInt_FromLong((long)n); |
| 294 | 1557 } |
| 1558 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1559 static char sendto_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1560 "sendto(data[, flags], address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1561 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1562 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
|
1563 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
|
1564 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1565 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1566 /* s.shutdown(how) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1567 |
| 1970 | 1568 static PyObject * |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1569 PySocketSock_shutdown(PySocketSockObject *s, PyObject *arg) |
| 294 | 1570 { |
| 1571 int how; | |
| 926 | 1572 int res; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1573 |
|
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1574 how = PyInt_AsLong(arg); |
|
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1575 if (how == -1 && PyErr_Occurred()) |
| 294 | 1576 return NULL; |
| 1970 | 1577 Py_BEGIN_ALLOW_THREADS |
| 926 | 1578 res = shutdown(s->sock_fd, how); |
| 1970 | 1579 Py_END_ALLOW_THREADS |
| 926 | 1580 if (res < 0) |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
1581 return s->errorhandler(); |
| 1970 | 1582 Py_INCREF(Py_None); |
| 1583 return Py_None; | |
| 294 | 1584 } |
| 1585 | |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1586 static char shutdown_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1587 "shutdown(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1588 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1589 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
|
1590 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
|
1591 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1592 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1593 /* List of methods for socket objects */ |
| 294 | 1594 |
| 1970 | 1595 static PyMethodDef PySocketSock_methods[] = { |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1596 {"accept", (PyCFunction)PySocketSock_accept, METH_NOARGS, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1597 accept_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1598 {"bind", (PyCFunction)PySocketSock_bind, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1599 bind_doc}, |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1600 {"close", (PyCFunction)PySocketSock_close, METH_NOARGS, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1601 close_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1602 {"connect", (PyCFunction)PySocketSock_connect, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1603 connect_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1604 {"connect_ex", (PyCFunction)PySocketSock_connect_ex, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1605 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
|
1606 #ifndef NO_DUP |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1607 {"dup", (PyCFunction)PySocketSock_dup, METH_NOARGS, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1608 dup_doc}, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1609 #endif |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1610 {"fileno", (PyCFunction)PySocketSock_fileno, METH_NOARGS, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1611 fileno_doc}, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1612 #ifdef HAVE_GETPEERNAME |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1613 {"getpeername", (PyCFunction)PySocketSock_getpeername, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1614 METH_NOARGS, 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
|
1615 #endif |
|
20440
9be2cc6b9959
Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents:
20412
diff
changeset
|
1616 {"getsockname", (PyCFunction)PySocketSock_getsockname, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1617 METH_NOARGS, getsockname_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1618 {"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1619 getsockopt_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1620 {"listen", (PyCFunction)PySocketSock_listen, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1621 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
|
1622 #ifndef NO_DUP |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1623 {"makefile", (PyCFunction)PySocketSock_makefile, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1624 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
|
1625 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1626 {"recv", (PyCFunction)PySocketSock_recv, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1627 recv_doc}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1628 {"recvfrom", (PyCFunction)PySocketSock_recvfrom, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1629 recvfrom_doc}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1630 {"send", (PyCFunction)PySocketSock_send, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1631 send_doc}, |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1632 {"sendall", (PyCFunction)PySocketSock_sendall, METH_VARARGS, |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
1633 sendall_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1634 {"sendto", (PyCFunction)PySocketSock_sendto, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1635 sendto_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1636 {"setblocking", (PyCFunction)PySocketSock_setblocking, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1637 setblocking_doc}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1638 {"setsockopt", (PyCFunction)PySocketSock_setsockopt, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1639 setsockopt_doc}, |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1640 {"shutdown", (PyCFunction)PySocketSock_shutdown, METH_O, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1641 shutdown_doc}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1642 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1643 {"sleeptaskw", (PyCFunction)PySocketSock_sleeptaskw, METH_VARARGS, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1644 sleeptaskw_doc}, |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1645 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1646 {NULL, NULL} /* sentinel */ |
| 294 | 1647 }; |
| 1648 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1649 |
| 1970 | 1650 /* 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
|
1651 First close the file description. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1652 |
| 294 | 1653 static void |
| 13470 | 1654 PySocketSock_dealloc(PySocketSockObject *s) |
| 294 | 1655 { |
|
12319
57f34e162e67
In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents:
12229
diff
changeset
|
1656 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
|
1657 (void) SOCKETCLOSE(s->sock_fd); |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1658 s->ob_type->tp_free((PyObject *)s); |
| 294 | 1659 } |
| 1660 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1661 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1662 static PyObject * |
| 13470 | 1663 PySocketSock_repr(PySocketSockObject *s) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1664 { |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1665 char buf[512]; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1666 #if SIZEOF_SOCKET_T > SIZEOF_LONG |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1667 if (s->sock_fd > LONG_MAX) { |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1668 /* 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
|
1669 ugly printf formatter for decimal pointer length integer |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1670 printing, only bother if necessary*/ |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1671 PyErr_SetString(PyExc_OverflowError, |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1672 "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
|
1673 return NULL; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1674 } |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1675 #endif |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
1676 PyOS_snprintf(buf, sizeof(buf), |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
1677 "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>", |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
1678 (long)s->sock_fd, s->sock_family, |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
1679 s->sock_type, |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
1680 s->sock_proto); |
|
3421
90b54312661a
remove unused variables
Guido van Rossum <guido@python.org>
parents:
3390
diff
changeset
|
1681 return PyString_FromString(buf); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1682 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1683 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1684 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1685 /* Create a new, uninitialized socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1686 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1687 static PyObject * |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1688 PySocketSock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1689 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1690 PyObject *new; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1691 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1692 new = type->tp_alloc(type, 0); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1693 if (new != NULL) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1694 ((PySocketSockObject *)new)->sock_fd = -1; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1695 return new; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1696 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1697 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1698 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1699 /* Initialize a new socket object. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1700 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1701 /*ARGSUSED*/ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1702 static int |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1703 PySocketSock_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1704 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1705 PySocketSockObject *s = (PySocketSockObject *)self; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1706 SOCKET_T fd; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1707 int family = AF_INET, type = SOCK_STREAM, proto = 0; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1708 static char *keywords[] = {"family", "type", "proto", 0}; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1709 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1710 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1711 "|iii:socket", keywords, |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1712 &family, &type, &proto)) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1713 return -1; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1714 Py_BEGIN_ALLOW_THREADS |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1715 fd = socket(family, type, proto); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1716 Py_END_ALLOW_THREADS |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1717 #ifdef MS_WINDOWS |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1718 if (fd == INVALID_SOCKET) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1719 #else |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1720 if (fd < 0) |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1721 #endif |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1722 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1723 PySocket_Err(); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1724 return -1; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1725 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1726 init_sockobject(s, fd, family, type, proto); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1727 /* From now on, ignore SIGPIPE and let the error checking |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1728 do the work. */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1729 #ifdef SIGPIPE |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1730 (void) signal(SIGPIPE, SIG_IGN); |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1731 #endif |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1732 return 0; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1733 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1734 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1735 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1736 /* 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
|
1737 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1738 static char socket_doc[] = |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1739 "socket([family[, type[, proto]]]) -> socket object\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1740 \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1741 Open a socket of the given type. The family argument specifies the\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1742 address family; it defaults to AF_INET. The type argument specifies\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1743 whether this is a stream (SOCK_STREAM, this is the default)\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1744 or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1745 specifying the default protocol.\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1746 \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1747 A socket represents one endpoint of a network connection.\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1748 \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1749 Methods:\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1750 \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1751 accept() -- accept a connection, returning new socket and client address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1752 bind() -- bind the socket to a local address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1753 close() -- close the socket\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1754 connect() -- connect the socket to a remote address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1755 connect_ex() -- connect, return an error code instead of an exception \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1756 dup() -- return a new socket object identical to the current one (*)\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1757 fileno() -- return underlying file descriptor\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1758 getpeername() -- return remote address (*)\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1759 getsockname() -- return local address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1760 getsockopt() -- get socket options\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1761 listen() -- start listening for incoming connections\n\ |
| 21060 | 1762 makefile() -- return a file object corresponding to the socket (*)\n\ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1763 recv() -- receive data\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1764 recvfrom() -- receive data and sender's address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1765 send() -- send data, may not send all of it\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1766 sendall() -- send all data\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1767 sendto() -- send data to a given address\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1768 setblocking() -- set or clear the blocking I/O flag\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1769 setsockopt() -- set socket options\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1770 shutdown() -- shut down traffic in one or both directions\n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1771 \n\ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1772 (*) not available on all platforms!)"; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1773 |
| 1970 | 1774 static PyTypeObject PySocketSock_Type = { |
| 3594 | 1775 PyObject_HEAD_INIT(0) /* Must fill in type value later */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1776 0, /* ob_size */ |
|
20730
73cabe664c11
Oops. In the tp_name field, the name should be "_socket.socket", not
Guido van Rossum <guido@python.org>
parents:
20727
diff
changeset
|
1777 "_socket.socket", /* tp_name */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1778 sizeof(PySocketSockObject), /* tp_basicsize */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1779 0, /* tp_itemsize */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1780 (destructor)PySocketSock_dealloc, /* tp_dealloc */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1781 0, /* tp_print */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1782 0, /* tp_getattr */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1783 0, /* tp_setattr */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1784 0, /* tp_compare */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1785 (reprfunc)PySocketSock_repr, /* tp_repr */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1786 0, /* tp_as_number */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1787 0, /* tp_as_sequence */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1788 0, /* tp_as_mapping */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1789 0, /* tp_hash */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1790 0, /* tp_call */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1791 0, /* tp_str */ |
|
20920
90871fa43f4e
Fixes to compile cPickle.c & socketmodule.c on cygwin and possibly
Michael W. Hudson <mwh@python.net>
parents:
20912
diff
changeset
|
1792 0, /* set below */ /* tp_getattro */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1793 0, /* tp_setattro */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1794 0, /* tp_as_buffer */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1795 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1796 socket_doc, /* tp_doc */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1797 0, /* tp_traverse */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1798 0, /* tp_clear */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1799 0, /* tp_richcompare */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1800 0, /* tp_weaklistoffset */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1801 0, /* tp_iter */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1802 0, /* tp_iternext */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1803 PySocketSock_methods, /* tp_methods */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1804 0, /* tp_members */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1805 0, /* tp_getset */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1806 0, /* tp_base */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1807 0, /* tp_dict */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1808 0, /* tp_descr_get */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1809 0, /* tp_descr_set */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1810 0, /* tp_dictoffset */ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1811 PySocketSock_init, /* tp_init */ |
|
20920
90871fa43f4e
Fixes to compile cPickle.c & socketmodule.c on cygwin and possibly
Michael W. Hudson <mwh@python.net>
parents:
20912
diff
changeset
|
1812 0, /* set below */ /* tp_alloc */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
1813 PySocketSock_new, /* tp_new */ |
|
20920
90871fa43f4e
Fixes to compile cPickle.c & socketmodule.c on cygwin and possibly
Michael W. Hudson <mwh@python.net>
parents:
20912
diff
changeset
|
1814 0, /* set below */ /* tp_free */ |
| 294 | 1815 }; |
| 1816 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1817 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1818 /* Python interface to gethostname(). */ |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1819 |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1820 /*ARGSUSED*/ |
| 1970 | 1821 static PyObject * |
| 13470 | 1822 PySocket_gethostname(PyObject *self, PyObject *args) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1823 { |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1824 char buf[1024]; |
| 926 | 1825 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
|
1826 if (!PyArg_ParseTuple(args, ":gethostname")) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1827 return NULL; |
| 1970 | 1828 Py_BEGIN_ALLOW_THREADS |
| 926 | 1829 res = gethostname(buf, (int) sizeof buf - 1); |
| 1970 | 1830 Py_END_ALLOW_THREADS |
| 926 | 1831 if (res < 0) |
| 1970 | 1832 return PySocket_Err(); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1833 buf[sizeof buf - 1] = '\0'; |
| 1970 | 1834 return PyString_FromString(buf); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
1835 } |
| 926 | 1836 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1837 static char gethostname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1838 "gethostname() -> string\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1839 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1840 Return the current host name."; |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1841 |
| 926 | 1842 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1843 /* Python interface to gethostbyname(name). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1844 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1845 /*ARGSUSED*/ |
| 1970 | 1846 static PyObject * |
| 13470 | 1847 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
|
1848 { |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
1849 char *name; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1850 struct sockaddr_storage addrbuf; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1851 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1852 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
|
1853 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1854 if (setipaddr(name, (struct sockaddr *)&addrbuf, AF_INET) < 0) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1855 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1856 return makeipaddr((struct sockaddr *)&addrbuf, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1857 sizeof(struct sockaddr_in)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1858 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1859 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1860 static char gethostbyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1861 "gethostbyname(host) -> address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1862 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1863 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
|
1864 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1865 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1866 /* 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
|
1867 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1868 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1869 gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1870 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1871 char **pch; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1872 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
|
1873 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
|
1874 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
|
1875 PyObject *tmp; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1876 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1877 if (h == NULL) { |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1878 /* Let's get real error message to return */ |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
1879 #ifndef RISCOS |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1880 PyH_Err(h_errno); |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
1881 #else |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
1882 PyErr_SetString(PySocket_Error, "host not found"); |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
1883 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1884 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1885 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1886 if (h->h_addrtype != af) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1887 #ifdef HAVE_STRERROR |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1888 /* Let's get real error message to return */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1889 PyErr_SetString(PySocket_Error, (char *)strerror(EAFNOSUPPORT)); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1890 #else |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1891 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1892 "Address family not supported by protocol family"); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1893 #endif |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1894 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1895 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1896 switch (af) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1897 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1898 if (alen < sizeof(struct sockaddr_in)) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1899 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1900 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1901 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1902 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1903 if (alen < sizeof(struct sockaddr_in6)) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1904 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1905 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1906 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1907 } |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1908 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
|
1909 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1910 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
|
1911 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1912 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
|
1913 int status; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1914 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
|
1915 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
|
1916 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1917 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
|
1918 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
|
1919 if (status) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1920 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1921 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1922 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
|
1923 int status; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1924 switch (af) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1925 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1926 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1927 struct sockaddr_in sin; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1928 memset(&sin, 0, sizeof(sin)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1929 sin.sin_family = af; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1930 #ifdef HAVE_SOCKADDR_SA_LEN |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1931 sin.sin_len = sizeof(sin); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1932 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1933 memcpy(&sin.sin_addr, *pch, sizeof(sin.sin_addr)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1934 tmp = makeipaddr((struct sockaddr *)&sin, sizeof(sin)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1935 if (pch == h->h_addr_list && alen >= sizeof(sin)) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1936 memcpy((char *) addr, &sin, sizeof(sin)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1937 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1938 } |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1939 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1940 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1941 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1942 struct sockaddr_in6 sin6; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1943 memset(&sin6, 0, sizeof(sin6)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1944 sin6.sin6_family = af; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1945 #ifdef HAVE_SOCKADDR_SA_LEN |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1946 sin6.sin6_len = sizeof(sin6); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1947 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1948 memcpy(&sin6.sin6_addr, *pch, sizeof(sin6.sin6_addr)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1949 tmp = makeipaddr((struct sockaddr *)&sin6, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1950 sizeof(sin6)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1951 if (pch == h->h_addr_list && alen >= sizeof(sin6)) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1952 memcpy((char *) addr, &sin6, sizeof(sin6)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1953 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1954 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1955 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1956 default: /* can't happen */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1957 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1958 "unsupported address family"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1959 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1960 } |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1961 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
|
1962 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1963 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
|
1964 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
|
1965 if (status) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1966 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1967 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1968 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
|
1969 err: |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1970 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
|
1971 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
|
1972 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
|
1973 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1974 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1975 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1976 /* 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
|
1977 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1978 /*ARGSUSED*/ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1979 static PyObject * |
| 13470 | 1980 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
|
1981 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1982 char *name; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1983 struct hostent *h; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1984 struct sockaddr_storage addr; |
|
18798
d591a96aed06
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents:
18794
diff
changeset
|
1985 struct sockaddr *sa; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
1986 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
|
1987 #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
|
1988 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
|
1989 #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
|
1990 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
|
1991 #else |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1992 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
|
1993 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
|
1994 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1995 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
1996 #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
|
1997 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
1998 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
1999 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2000 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2001 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
|
2002 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2003 if (setipaddr(name, (struct sockaddr *)&addr, PF_INET) < 0) |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2004 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2005 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
|
2006 #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
|
2007 #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
|
2008 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
|
2009 #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
|
2010 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
|
2011 #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
|
2012 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
|
2013 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
|
2014 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
|
2015 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2016 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2017 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2018 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
|
2019 #endif |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2020 h = gethostbyname(name); |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
2021 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
2022 Py_END_ALLOW_THREADS |
|
18798
d591a96aed06
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents:
18794
diff
changeset
|
2023 /* Some C libraries would require addr.__ss_family instead of addr.ss_family. |
|
d591a96aed06
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents:
18794
diff
changeset
|
2024 Therefore, we cast the sockaddr_storage into sockaddr to access sa_family. */ |
|
d591a96aed06
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents:
18794
diff
changeset
|
2025 sa = (struct sockaddr*)&addr; |
|
d591a96aed06
Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents:
18794
diff
changeset
|
2026 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), sa->sa_family); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2027 #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
|
2028 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
|
2029 #endif |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
2030 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
|
2031 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2032 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2033 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
|
2034 "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
|
2035 \n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2036 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
|
2037 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
|
2038 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2039 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2040 /* Python interface to gethostbyaddr(IP). */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2041 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2042 /*ARGSUSED*/ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2043 static PyObject * |
| 13470 | 2044 PySocket_gethostbyaddr(PyObject *self, PyObject *args) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2045 { |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
2046 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2047 struct sockaddr_storage addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2048 #else |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2049 struct sockaddr_in addr; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2050 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2051 struct sockaddr *sa = (struct sockaddr *)&addr; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2052 char *ip_num; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2053 struct hostent *h; |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2054 PyObject *ret; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2055 #ifdef HAVE_GETHOSTBYNAME_R |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2056 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
|
2057 #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
|
2058 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
|
2059 #else |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2060 char buf[16384]; |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2061 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
|
2062 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
2063 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
2064 #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
|
2065 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2066 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2067 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2068 char *ap; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2069 int al; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2070 int af; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2071 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2072 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
|
2073 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2074 af = PF_UNSPEC; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2075 if (setipaddr(ip_num, sa, af) < 0) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2076 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2077 af = sa->sa_family; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2078 ap = NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2079 al = 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2080 switch (af) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2081 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2082 ap = (char *)&((struct sockaddr_in *)sa)->sin_addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2083 al = sizeof(((struct sockaddr_in *)sa)->sin_addr); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2084 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
2085 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2086 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2087 ap = (char *)&((struct sockaddr_in6 *)sa)->sin6_addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2088 al = sizeof(((struct sockaddr_in6 *)sa)->sin6_addr); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2089 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2090 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2091 default: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2092 PyErr_SetString(PySocket_Error, "unsupported address family"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2093 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2094 } |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2095 Py_BEGIN_ALLOW_THREADS |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2096 #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
|
2097 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2098 result = gethostbyaddr_r(ap, al, af, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2099 &hp_allocated, buf, buf_len, |
|
10401
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
2100 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
2101 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2102 h = gethostbyaddr_r(ap, al, af, |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2103 &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
|
2104 #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
|
2105 memset((void *) &data, '\0', sizeof(data)); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2106 result = gethostbyaddr_r(ap, al, af, &hp_allocated, &data); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
2107 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
|
2108 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
2109 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2110 #ifdef USE_GETHOSTBYNAME_LOCK |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2111 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
|
2112 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2113 h = gethostbyaddr(ap, al, af); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2114 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2115 Py_END_ALLOW_THREADS |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2116 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), af); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2117 #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
|
2118 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
|
2119 #endif |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
2120 return ret; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2121 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2122 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2123 static char gethostbyaddr_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2124 "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
|
2125 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2126 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
|
2127 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
|
2128 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2129 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2130 /* Python interface to getservbyname(name). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2131 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
|
2132 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
|
2133 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2134 /*ARGSUSED*/ |
| 1970 | 2135 static PyObject * |
| 13470 | 2136 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
|
2137 { |
| 926 | 2138 char *name, *proto; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2139 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
|
2140 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
|
2141 return NULL; |
| 1970 | 2142 Py_BEGIN_ALLOW_THREADS |
| 926 | 2143 sp = getservbyname(name, proto); |
| 1970 | 2144 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2145 if (sp == NULL) { |
| 1970 | 2146 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
|
2147 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2148 } |
| 1970 | 2149 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
|
2150 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2151 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2152 static char getservbyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2153 "getservbyname(servicename, protocolname) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2154 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2155 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
|
2156 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
|
2157 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2158 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2159 /* Python interface to getprotobyname(name). |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2160 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
|
2161 already known or not useful (like the list of aliases). */ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2162 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2163 /*ARGSUSED*/ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2164 static PyObject * |
| 13470 | 2165 PySocket_getprotobyname(PyObject *self, PyObject *args) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2166 { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2167 char *name; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2168 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
|
2169 #ifdef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2170 /* 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
|
2171 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
|
2172 return NULL; |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2173 #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
|
2174 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name)) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2175 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2176 Py_BEGIN_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2177 sp = getprotobyname(name); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2178 Py_END_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2179 if (sp == NULL) { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2180 PyErr_SetString(PySocket_Error, "protocol not found"); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2181 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2182 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2183 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
|
2184 #endif |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2185 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2186 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2187 static char getprotobyname_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2188 "getprotobyname(name) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2189 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2190 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
|
2191 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
2192 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2193 #ifndef NO_DUP |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
2194 /* 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
|
2195 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
|
2196 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
|
2197 |
|
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
2198 /*ARGSUSED*/ |
| 1970 | 2199 static PyObject * |
| 13470 | 2200 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
|
2201 { |
| 1970 | 2202 PySocketSockObject *s; |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2203 SOCKET_T fd; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2204 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
|
2205 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
|
2206 &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
|
2207 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
|
2208 /* 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
|
2209 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
|
2210 if (fd < 0) |
| 1970 | 2211 return PySocket_Err(); |
| 2212 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
|
2213 /* 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
|
2214 do the work. */ |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2215 #ifdef SIGPIPE |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
2216 (void) signal(SIGPIPE, SIG_IGN); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2217 #endif |
| 1970 | 2218 return (PyObject *) s; |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
2219 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2220 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2221 static char fromfd_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2222 "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
|
2223 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2224 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
|
2225 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
|
2226 |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2227 #endif /* NO_DUP */ |
|
1099
3dd7b8255619
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents:
1094
diff
changeset
|
2228 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2229 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2230 static PyObject * |
| 13470 | 2231 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
|
2232 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2233 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2234 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2235 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
|
2236 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2237 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2238 x2 = (int)ntohs((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2239 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2240 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2241 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2242 static char ntohs_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2243 "ntohs(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2244 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2245 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
|
2246 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2247 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2248 static PyObject * |
| 13470 | 2249 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
|
2250 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2251 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2252 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2253 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
|
2254 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2255 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2256 x2 = ntohl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2257 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2258 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2259 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2260 static char ntohl_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2261 "ntohl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2262 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2263 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
|
2264 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2265 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2266 static PyObject * |
| 13470 | 2267 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
|
2268 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2269 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2270 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2271 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
|
2272 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2273 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2274 x2 = (int)htons((short)x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2275 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2276 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2277 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2278 static char htons_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2279 "htons(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2280 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2281 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
|
2282 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2283 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2284 static PyObject * |
| 13470 | 2285 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
|
2286 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2287 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2288 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2289 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
|
2290 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2291 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2292 x2 = htonl(x1); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2293 return PyInt_FromLong(x2); |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2294 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
2295 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2296 static char htonl_doc[] = |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2297 "htonl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2298 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2299 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
|
2300 |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2301 /* |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2302 * 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
|
2303 * |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2304 * 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
|
2305 * |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2306 */ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2307 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2308 static char inet_aton_doc[] = |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2309 "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
|
2310 \n\ |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2311 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
|
2312 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
|
2313 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2314 static PyObject* |
| 13470 | 2315 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
|
2316 { |
|
11268
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
2317 #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
|
2318 #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
|
2319 #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
|
2320 |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2321 /* 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
|
2322 char *ip_addr; |
|
18753
01692bf02f97
Clean up some warnings from the SGI compiler.
Fred Drake <fdrake@acm.org>
parents:
18743
diff
changeset
|
2323 unsigned long packed_addr; |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2324 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2325 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
|
2326 return NULL; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2327 } |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2328 packed_addr = inet_addr(ip_addr); |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2329 |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2330 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
|
2331 PyErr_SetString(PySocket_Error, |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2332 "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
|
2333 return NULL; |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2334 } |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2335 |
|
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2336 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
|
2337 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
|
2338 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2339 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2340 static char inet_ntoa_doc[] = |
| 11937 | 2341 "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
|
2342 \n\ |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2343 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
|
2344 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2345 static PyObject* |
| 13470 | 2346 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
|
2347 { |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2348 char *packed_str; |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
2349 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
|
2350 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
|
2351 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2352 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
|
2353 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
|
2354 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2355 |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2356 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
|
2357 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
|
2358 "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
|
2359 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
|
2360 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2361 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2362 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
|
2363 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
2364 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
|
2365 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2366 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2367 /* Python interface to getaddrinfo(host, port). */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2368 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2369 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2370 static PyObject * |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2371 PySocket_getaddrinfo(PyObject *self, PyObject *args) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2372 { |
|
20912
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
2373 struct addrinfo hints, *res; |
|
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
2374 struct addrinfo *res0 = NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2375 PyObject *pobj = (PyObject *)NULL; |
|
19197
01a9b7807160
Bump size of sprintf buffer. Suggested by Alex Coventry.
Martin v. Löwis <martin@v.loewis.de>
parents:
19151
diff
changeset
|
2376 char pbuf[30]; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2377 char *hptr, *pptr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2378 int family, socktype, protocol, flags; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2379 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2380 PyObject *all = (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2381 PyObject *single = (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2382 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2383 family = socktype = protocol = flags = 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2384 family = PF_UNSPEC; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2385 if (!PyArg_ParseTuple(args, "zO|iiii:getaddrinfo", |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2386 &hptr, &pobj, &family, &socktype, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2387 &protocol, &flags)) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2388 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2389 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2390 if (PyInt_Check(pobj)) { |
|
18915
510f7f6a877e
Enable PyOS_snprintf() et al. during alpha phase of 2.2.0 and
Marc-André Lemburg <mal@egenix.com>
parents:
18879
diff
changeset
|
2391 PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj)); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2392 pptr = pbuf; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2393 } else if (PyString_Check(pobj)) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2394 pptr = PyString_AsString(pobj); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2395 } else if (pobj == Py_None) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2396 pptr = (char *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2397 } else { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2398 PyErr_SetString(PySocket_Error, "Int or String expected"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2399 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2400 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2401 memset(&hints, 0, sizeof(hints)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2402 hints.ai_family = family; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2403 hints.ai_socktype = socktype; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2404 hints.ai_protocol = protocol; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2405 hints.ai_flags = flags; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2406 error = getaddrinfo(hptr, pptr, &hints, &res0); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2407 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2408 PyGAI_Err(error); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2409 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2410 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2411 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2412 if ((all = PyList_New(0)) == NULL) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2413 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2414 for (res = res0; res; res = res->ai_next) { |
|
20389
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2415 PyObject *addr = |
|
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2416 makesockaddr(-1, res->ai_addr, res->ai_addrlen); |
|
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2417 if (addr == NULL) |
|
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2418 goto err; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2419 single = Py_BuildValue("iiisO", res->ai_family, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2420 res->ai_socktype, res->ai_protocol, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2421 res->ai_canonname ? res->ai_canonname : "", |
|
20389
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2422 addr); |
|
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
2423 Py_DECREF(addr); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2424 if (single == NULL) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2425 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2426 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2427 if (PyList_Append(all, single)) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2428 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2429 Py_XDECREF(single); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2430 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2431 return all; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2432 err: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2433 Py_XDECREF(single); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2434 Py_XDECREF(all); |
|
20912
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
2435 if (res0) |
|
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
2436 freeaddrinfo(res0); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2437 return (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2438 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2439 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2440 static char getaddrinfo_doc[] = |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2441 "socket.getaddrinfo(host, port [, family, socktype, proto, flags])\n\ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2442 --> List of (family, socktype, proto, canonname, sockaddr)\n\ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2443 \n\ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2444 Resolve host and port into addrinfo struct."; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2445 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2446 /* Python interface to getnameinfo(sa, flags). */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2447 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2448 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2449 static PyObject * |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2450 PySocket_getnameinfo(PyObject *self, PyObject *args) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2451 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2452 PyObject *sa = (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2453 int flags; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2454 char *hostp; |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
2455 int port, flowinfo, scope_id; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2456 char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2457 struct addrinfo hints, *res = NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2458 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2459 PyObject *ret = (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2460 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2461 flags = flowinfo = scope_id = 0; |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
2462 if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags)) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2463 return NULL; |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
2464 if (!PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, &scope_id)) |
|
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
2465 return NULL; |
|
18915
510f7f6a877e
Enable PyOS_snprintf() et al. during alpha phase of 2.2.0 and
Marc-André Lemburg <mal@egenix.com>
parents:
18879
diff
changeset
|
2466 PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2467 memset(&hints, 0, sizeof(hints)); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2468 hints.ai_family = PF_UNSPEC; |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2469 hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2470 error = getaddrinfo(hostp, pbuf, &hints, &res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2471 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2472 PyGAI_Err(error); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2473 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2474 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2475 if (res->ai_next) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2476 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2477 "sockaddr resolved to multiple addresses"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2478 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2479 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2480 switch (res->ai_family) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2481 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2482 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2483 char *t1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2484 int t2; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2485 if (PyArg_ParseTuple(sa, "si", &t1, &t2) == 0) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2486 PyErr_SetString(PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2487 "IPv4 sockaddr must be 2 tuple"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2488 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2489 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2490 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2491 } |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
2492 #ifdef ENABLE_IPV6 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2493 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2494 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2495 struct sockaddr_in6 *sin6; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2496 sin6 = (struct sockaddr_in6 *)res->ai_addr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2497 sin6->sin6_flowinfo = flowinfo; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2498 sin6->sin6_scope_id = scope_id; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2499 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2500 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2501 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2502 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2503 error = getnameinfo(res->ai_addr, res->ai_addrlen, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2504 hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), flags); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2505 if (error) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2506 PyGAI_Err(error); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2507 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2508 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2509 ret = Py_BuildValue("ss", hbuf, pbuf); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2510 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2511 fail: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2512 if (res) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2513 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2514 return ret; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2515 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2516 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2517 static char getnameinfo_doc[] = |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2518 "socket.getnameinfo(sockaddr, flags) --> (host, port)\n\ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2519 \n\ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2520 Get host and port for a sockaddr."; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2521 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2522 /* 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
|
2523 |
| 1970 | 2524 static PyMethodDef PySocket_methods[] = { |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2525 {"gethostbyname", PySocket_gethostbyname, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2526 METH_VARARGS, gethostbyname_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2527 {"gethostbyname_ex", PySocket_gethostbyname_ex, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2528 METH_VARARGS, ghbn_ex_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2529 {"gethostbyaddr", PySocket_gethostbyaddr, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2530 METH_VARARGS, gethostbyaddr_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2531 {"gethostname", PySocket_gethostname, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2532 METH_VARARGS, gethostname_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2533 {"getservbyname", PySocket_getservbyname, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2534 METH_VARARGS, getservbyname_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2535 {"getprotobyname", PySocket_getprotobyname, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2536 METH_VARARGS,getprotobyname_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
|
2537 #ifndef NO_DUP |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2538 {"fromfd", PySocket_fromfd, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2539 METH_VARARGS, 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
|
2540 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2541 {"ntohs", PySocket_ntohs, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2542 METH_VARARGS, ntohs_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2543 {"ntohl", PySocket_ntohl, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2544 METH_VARARGS, ntohl_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2545 {"htons", PySocket_htons, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2546 METH_VARARGS, htons_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2547 {"htonl", PySocket_htonl, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2548 METH_VARARGS, htonl_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2549 {"inet_aton", PySocket_inet_aton, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2550 METH_VARARGS, inet_aton_doc}, |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2551 {"inet_ntoa", PySocket_inet_ntoa, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13761
diff
changeset
|
2552 METH_VARARGS, inet_ntoa_doc}, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2553 {"getaddrinfo", PySocket_getaddrinfo, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2554 METH_VARARGS, getaddrinfo_doc}, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2555 {"getnameinfo", PySocket_getnameinfo, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2556 METH_VARARGS, getnameinfo_doc}, |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2557 {NULL, NULL} /* Sentinel */ |
| 294 | 2558 }; |
| 2559 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2560 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2561 /* 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
|
2562 * |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2563 * 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
|
2564 */ |
| 294 | 2565 static void |
| 13470 | 2566 insint(PyObject *d, char *name, int value) |
| 294 | 2567 { |
| 1970 | 2568 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
|
2569 if (!v || PyDict_SetItemString(d, name, v)) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2570 PyErr_Clear(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2571 |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2572 Py_XDECREF(v); |
| 294 | 2573 } |
| 2574 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2575 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2576 #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
|
2577 |
|
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
|
2578 /* 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
|
2579 |
|
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
|
2580 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2581 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
|
2582 { |
|
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
|
2583 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
|
2584 } |
|
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
|
2585 |
|
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
|
2586 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2587 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
|
2588 { |
|
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
|
2589 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
|
2590 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
|
2591 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
|
2592 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
|
2593 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
|
2594 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
|
2595 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
|
2596 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
|
2597 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
|
2598 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
|
2599 "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
|
2600 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
|
2601 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
|
2602 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
|
2603 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
|
2604 "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
|
2605 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
|
2606 default: |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
2607 PyOS_snprintf(buf, sizeof(buf), |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21060
diff
changeset
|
2608 "WSAStartup failed: error code %d", ret); |
|
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
|
2609 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
|
2610 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
|
2611 } |
|
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
|
2612 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
|
2613 } |
|
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
|
2614 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2615 #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
|
2616 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2617 #if defined(PYOS_OS2) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2618 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2619 /* Additional initialization and cleanup for OS/2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2620 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2621 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2622 OS2cleanup(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2623 { |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2624 /* No cleanup is necessary for OS/2 Sockets */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2625 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2626 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2627 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13554
diff
changeset
|
2628 OS2init(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2629 { |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2630 #if !defined(PYCC_GCC) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2631 char reason[64]; |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2632 int rc = sock_init(); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2633 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2634 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
|
2635 atexit(OS2cleanup); |
|
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2636 return 1; /* Indicate Success */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2637 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2638 |
|
21094
c2150313d9d1
More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
21073
diff
changeset
|
2639 PyOS_snprintf(reason, sizeof(reason), |
|
c2150313d9d1
More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
21073
diff
changeset
|
2640 "OS/2 TCP/IP Error# %d", sock_errno()); |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2641 PyErr_SetString(PyExc_ImportError, reason); |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2642 |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2643 return 0; /* Indicate Failure */ |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2644 #else |
|
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2645 /* no need to initialise sockets with GCC/EMX */ |
|
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2646 return 1; |
|
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2647 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2648 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2649 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2650 #endif /* PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2651 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2652 /* C API table - always add new things to the end for binary |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2653 compatibility. */ |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2654 static |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2655 PySocketModule_APIObject PySocketModuleAPI = |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2656 { |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2657 &PySocketSock_Type, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2658 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2659 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2660 /* Initialize this module. |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2661 * 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
|
2662 * 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
|
2663 * defined. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2664 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2665 * 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
|
2666 * 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
|
2667 * which implements some missing functionality (such as makefile(), |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2668 * 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
|
2669 * ImportError exception if initialization of WINSOCK fails. When |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2670 * 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
|
2671 * scheduled to be made at exit time. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2672 * |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2673 * 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
|
2674 * "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
|
2675 * 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
|
2676 * operating system's filesystem layer. |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2677 */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2678 |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2679 static char module_doc[] = |
|
14008
6c91ad9c0e06
Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents:
13830
diff
changeset
|
2680 "Implementation module for socket operations. See the socket module\n\ |
|
6c91ad9c0e06
Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents:
13830
diff
changeset
|
2681 for documentation."; |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2682 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9307
diff
changeset
|
2683 DL_EXPORT(void) |
|
13694
b54f11ada91e
Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents:
13680
diff
changeset
|
2684 init_socket(void) |
| 294 | 2685 { |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2686 PyObject *m; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2687 #ifdef RISCOS |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2688 _kernel_swi_regs r; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2689 r.r[0]=0; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2690 _kernel_swi(0x43380, &r, &r); |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2691 taskwindow = r.r[0]; |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2692 #else |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2693 #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
|
2694 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
|
2695 return; |
|
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
|
2696 #else |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2697 #if defined(PYOS_OS2) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2698 if (!OS2init()) |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
2699 return; |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
2700 #endif /* PYOS_OS2 */ |
|
14008
6c91ad9c0e06
Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents:
13830
diff
changeset
|
2701 #endif /* MS_WINDOWS */ |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2702 #endif /* RISCOS */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2703 PySocketSock_Type.ob_type = &PyType_Type; |
|
20920
90871fa43f4e
Fixes to compile cPickle.c & socketmodule.c on cygwin and possibly
Michael W. Hudson <mwh@python.net>
parents:
20912
diff
changeset
|
2704 PySocketSock_Type.tp_getattro = PyObject_GenericGetAttr; |
|
90871fa43f4e
Fixes to compile cPickle.c & socketmodule.c on cygwin and possibly
Michael W. Hudson <mwh@python.net>
parents:
20912
diff
changeset
|
2705 PySocketSock_Type.tp_alloc = PyType_GenericAlloc; |
|
22974
72778ec94dec
PyObject_Del can now be used as a function designator.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22957
diff
changeset
|
2706 PySocketSock_Type.tp_free = PyObject_Del; |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2707 m = Py_InitModule3(PySocket_MODULE_NAME, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2708 PySocket_methods, |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2709 module_doc); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2710 |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2711 PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2712 if (PySocket_Error == NULL) |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2713 return; |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2714 Py_INCREF(PySocket_Error); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2715 PyModule_AddObject(m, "error", PySocket_Error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2716 PyH_Error = PyErr_NewException("socket.herror", PySocket_Error, NULL); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2717 if (PyH_Error == NULL) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2718 return; |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2719 Py_INCREF(PyH_Error); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2720 PyModule_AddObject(m, "herror", PyH_Error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2721 PyGAI_Error = PyErr_NewException("socket.gaierror", PySocket_Error, |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2722 NULL); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2723 if (PyGAI_Error == NULL) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2724 return; |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2725 Py_INCREF(PyGAI_Error); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2726 PyModule_AddObject(m, "gaierror", PyGAI_Error); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2727 Py_INCREF((PyObject *)&PySocketSock_Type); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2728 if (PyModule_AddObject(m, "SocketType", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2729 (PyObject *)&PySocketSock_Type) != 0) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5697
diff
changeset
|
2730 return; |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2731 Py_INCREF((PyObject *)&PySocketSock_Type); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2732 if (PyModule_AddObject(m, "socket", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2733 (PyObject *)&PySocketSock_Type) != 0) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2734 return; |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2735 |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2736 /* Export C API */ |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2737 if (PyModule_AddObject(m, PySocket_CAPI_NAME, |
|
21959
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2738 PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2739 ) != 0) |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2740 return; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
2741 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2742 /* 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
|
2743 #ifdef AF_UNSPEC |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2744 PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2745 #endif |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2746 PyModule_AddIntConstant(m, "AF_INET", AF_INET); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2747 #ifdef AF_INET6 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2748 PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2749 #endif /* AF_INET6 */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2750 #ifdef AF_UNIX |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2751 PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2752 #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
|
2753 #ifdef AF_AX25 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2754 /* Amateur Radio AX.25 */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2755 PyModule_AddIntConstant(m, "AF_AX25", AF_AX25); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2756 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2757 #ifdef AF_IPX |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2758 PyModule_AddIntConstant(m, "AF_IPX", AF_IPX); /* Novell IPX */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2759 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2760 #ifdef AF_APPLETALK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2761 /* Appletalk DDP */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2762 PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2763 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2764 #ifdef AF_NETROM |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2765 /* Amateur radio NetROM */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2766 PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2767 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2768 #ifdef AF_BRIDGE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2769 /* Multiprotocol bridge */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2770 PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2771 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2772 #ifdef AF_AAL5 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2773 /* Reserved for Werner's ATM */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2774 PyModule_AddIntConstant(m, "AF_AAL5", AF_AAL5); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2775 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2776 #ifdef AF_X25 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2777 /* Reserved for X.25 project */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2778 PyModule_AddIntConstant(m, "AF_X25", AF_X25); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2779 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2780 #ifdef AF_INET6 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2781 PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); /* IP version 6 */ |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2782 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2783 #ifdef AF_ROSE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2784 /* Amateur Radio X.25 PLP */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2785 PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2786 #endif |
|
19151
cd44254360b6
Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents:
18997
diff
changeset
|
2787 #ifdef HAVE_NETPACKET_PACKET_H |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2788 PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2789 PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2790 PyModule_AddIntConstant(m, "PACKET_HOST", PACKET_HOST); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2791 PyModule_AddIntConstant(m, "PACKET_BROADCAST", PACKET_BROADCAST); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2792 PyModule_AddIntConstant(m, "PACKET_MULTICAST", PACKET_MULTICAST); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2793 PyModule_AddIntConstant(m, "PACKET_OTHERHOST", PACKET_OTHERHOST); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2794 PyModule_AddIntConstant(m, "PACKET_OUTGOING", PACKET_OUTGOING); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2795 PyModule_AddIntConstant(m, "PACKET_LOOPBACK", PACKET_LOOPBACK); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2796 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2797 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2798 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2799 /* Socket types */ |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2800 PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2801 PyModule_AddIntConstant(m, "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
|
2802 #ifndef __BEOS__ |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8821
diff
changeset
|
2803 /* We have incomplete socket support. */ |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2804 PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2805 PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2806 PyModule_AddIntConstant(m, "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
|
2807 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2808 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2809 #ifdef SO_DEBUG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2810 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2811 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2812 #ifdef SO_ACCEPTCONN |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2813 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2814 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2815 #ifdef SO_REUSEADDR |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2816 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2817 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2818 #ifdef SO_KEEPALIVE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2819 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2820 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2821 #ifdef SO_DONTROUTE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2822 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2823 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2824 #ifdef SO_BROADCAST |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2825 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2826 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2827 #ifdef SO_USELOOPBACK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2828 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2829 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2830 #ifdef SO_LINGER |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2831 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2832 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2833 #ifdef SO_OOBINLINE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2834 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2835 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2836 #ifdef SO_REUSEPORT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2837 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2838 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2839 #ifdef SO_SNDBUF |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2840 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2841 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2842 #ifdef SO_RCVBUF |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2843 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2844 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2845 #ifdef SO_SNDLOWAT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2846 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2847 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2848 #ifdef SO_RCVLOWAT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2849 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2850 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2851 #ifdef SO_SNDTIMEO |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2852 PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2853 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2854 #ifdef SO_RCVTIMEO |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2855 PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2856 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2857 #ifdef SO_ERROR |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2858 PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2859 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2860 #ifdef SO_TYPE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2861 PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2862 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2863 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2864 /* Maximum number of connections for "listen" */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2865 #ifdef SOMAXCONN |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2866 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2867 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2868 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2869 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2870 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2871 /* Flags for send, recv */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2872 #ifdef MSG_OOB |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2873 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2874 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2875 #ifdef MSG_PEEK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2876 PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2877 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2878 #ifdef MSG_DONTROUTE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2879 PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2880 #endif |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
2881 #ifdef MSG_DONTWAIT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2882 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT); |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
2883 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2884 #ifdef MSG_EOR |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2885 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2886 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2887 #ifdef MSG_TRUNC |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2888 PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2889 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2890 #ifdef MSG_CTRUNC |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2891 PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2892 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2893 #ifdef MSG_WAITALL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2894 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2895 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2896 #ifdef MSG_BTAG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2897 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2898 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2899 #ifdef MSG_ETAG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2900 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2901 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2902 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2903 /* Protocol level and numbers, usable for [gs]etsockopt */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2904 #ifdef SOL_SOCKET |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2905 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2906 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2907 #ifdef SOL_IP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2908 PyModule_AddIntConstant(m, "SOL_IP", SOL_IP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2909 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2910 PyModule_AddIntConstant(m, "SOL_IP", 0); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2911 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2912 #ifdef SOL_IPX |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2913 PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2914 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2915 #ifdef SOL_AX25 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2916 PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2917 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2918 #ifdef SOL_ATALK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2919 PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2920 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2921 #ifdef SOL_NETROM |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2922 PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2923 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2924 #ifdef SOL_ROSE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2925 PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2926 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2927 #ifdef SOL_TCP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2928 PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2929 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2930 PyModule_AddIntConstant(m, "SOL_TCP", 6); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2931 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2932 #ifdef SOL_UDP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2933 PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2934 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2935 PyModule_AddIntConstant(m, "SOL_UDP", 17); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
2936 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2937 #ifdef IPPROTO_IP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2938 PyModule_AddIntConstant(m, "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
|
2939 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2940 PyModule_AddIntConstant(m, "IPPROTO_IP", 0); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2941 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2942 #ifdef IPPROTO_HOPOPTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2943 PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2944 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2945 #ifdef IPPROTO_ICMP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2946 PyModule_AddIntConstant(m, "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
|
2947 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2948 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2949 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2950 #ifdef IPPROTO_IGMP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2951 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2952 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2953 #ifdef IPPROTO_GGP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2954 PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2955 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2956 #ifdef IPPROTO_IPV4 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2957 PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV4); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2958 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2959 #ifdef IPPROTO_IPIP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2960 PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2961 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2962 #ifdef IPPROTO_TCP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2963 PyModule_AddIntConstant(m, "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
|
2964 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2965 PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2966 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2967 #ifdef IPPROTO_EGP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2968 PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2969 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2970 #ifdef IPPROTO_PUP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2971 PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2972 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2973 #ifdef IPPROTO_UDP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2974 PyModule_AddIntConstant(m, "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
|
2975 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2976 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2977 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2978 #ifdef IPPROTO_IDP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2979 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2980 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2981 #ifdef IPPROTO_HELLO |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2982 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2983 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2984 #ifdef IPPROTO_ND |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2985 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2986 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2987 #ifdef IPPROTO_TP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2988 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
2989 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2990 #ifdef IPPROTO_IPV6 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2991 PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2992 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2993 #ifdef IPPROTO_ROUTING |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2994 PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2995 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2996 #ifdef IPPROTO_FRAGMENT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
2997 PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2998 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
2999 #ifdef IPPROTO_RSVP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3000 PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3001 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3002 #ifdef IPPROTO_GRE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3003 PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3004 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3005 #ifdef IPPROTO_ESP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3006 PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3007 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3008 #ifdef IPPROTO_AH |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3009 PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3010 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3011 #ifdef IPPROTO_MOBILE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3012 PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3013 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3014 #ifdef IPPROTO_ICMPV6 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3015 PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3016 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3017 #ifdef IPPROTO_NONE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3018 PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3019 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3020 #ifdef IPPROTO_DSTOPTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3021 PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3022 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3023 #ifdef IPPROTO_XTP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3024 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3025 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3026 #ifdef IPPROTO_EON |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3027 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3028 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3029 #ifdef IPPROTO_PIM |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3030 PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3031 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3032 #ifdef IPPROTO_IPCOMP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3033 PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3034 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3035 #ifdef IPPROTO_VRRP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3036 PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3037 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3038 #ifdef IPPROTO_BIP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3039 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3040 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3041 /**/ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3042 #ifdef IPPROTO_RAW |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3043 PyModule_AddIntConstant(m, "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
|
3044 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3045 PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3046 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3047 #ifdef IPPROTO_MAX |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3048 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3049 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3050 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3051 /* Some port configuration */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3052 #ifdef IPPORT_RESERVED |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3053 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3054 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3055 PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3056 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3057 #ifdef IPPORT_USERRESERVED |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3058 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3059 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3060 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3061 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3062 |
| 2369 | 3063 /* Some reserved IP v.4 addresses */ |
| 3064 #ifdef INADDR_ANY | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3065 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY); |
| 2369 | 3066 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3067 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); |
| 2369 | 3068 #endif |
| 3069 #ifdef INADDR_BROADCAST | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3070 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST); |
| 2369 | 3071 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3072 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); |
| 2369 | 3073 #endif |
| 3074 #ifdef INADDR_LOOPBACK | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3075 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK); |
| 2369 | 3076 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3077 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); |
| 2369 | 3078 #endif |
| 3079 #ifdef INADDR_UNSPEC_GROUP | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3080 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); |
| 2369 | 3081 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3082 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); |
| 2369 | 3083 #endif |
| 3084 #ifdef INADDR_ALLHOSTS_GROUP | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3085 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3086 INADDR_ALLHOSTS_GROUP); |
| 2369 | 3087 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3088 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); |
| 2369 | 3089 #endif |
| 3090 #ifdef INADDR_MAX_LOCAL_GROUP | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3091 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3092 INADDR_MAX_LOCAL_GROUP); |
| 2369 | 3093 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3094 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); |
| 2369 | 3095 #endif |
| 3096 #ifdef INADDR_NONE | |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3097 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE); |
| 2369 | 3098 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3099 PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); |
| 2369 | 3100 #endif |
| 3101 | |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3102 /* IPv4 [gs]etsockopt options */ |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3103 #ifdef IP_OPTIONS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3104 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3105 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3106 #ifdef IP_HDRINCL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3107 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3108 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3109 #ifdef IP_TOS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3110 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3111 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3112 #ifdef IP_TTL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3113 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3114 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3115 #ifdef IP_RECVOPTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3116 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3117 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3118 #ifdef IP_RECVRETOPTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3119 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3120 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3121 #ifdef IP_RECVDSTADDR |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3122 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3123 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3124 #ifdef IP_RETOPTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3125 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3126 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3127 #ifdef IP_MULTICAST_IF |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3128 PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3129 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3130 #ifdef IP_MULTICAST_TTL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3131 PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3132 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3133 #ifdef IP_MULTICAST_LOOP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3134 PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3135 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3136 #ifdef IP_ADD_MEMBERSHIP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3137 PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3138 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3139 #ifdef IP_DROP_MEMBERSHIP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3140 PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
3141 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3142 #ifdef IP_DEFAULT_MULTICAST_TTL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3143 PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_TTL", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3144 IP_DEFAULT_MULTICAST_TTL); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3145 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3146 #ifdef IP_DEFAULT_MULTICAST_LOOP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3147 PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_LOOP", |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3148 IP_DEFAULT_MULTICAST_LOOP); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3149 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3150 #ifdef IP_MAX_MEMBERSHIPS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3151 PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3152 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3153 |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3154 /* IPv6 [gs]etsockopt options, defined in RFC2553 */ |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3155 #ifdef IPV6_JOIN_GROUP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3156 PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3157 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3158 #ifdef IPV6_LEAVE_GROUP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3159 PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3160 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3161 #ifdef IPV6_MULTICAST_HOPS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3162 PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3163 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3164 #ifdef IPV6_MULTICAST_IF |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3165 PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3166 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3167 #ifdef IPV6_MULTICAST_LOOP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3168 PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3169 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3170 #ifdef IPV6_UNICAST_HOPS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3171 PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3172 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3173 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3174 /* TCP options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3175 #ifdef TCP_NODELAY |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3176 PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3177 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3178 #ifdef TCP_MAXSEG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3179 PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3180 #endif |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3181 #ifdef TCP_CORK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3182 PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3183 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3184 #ifdef TCP_KEEPIDLE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3185 PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3186 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3187 #ifdef TCP_KEEPINTVL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3188 PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3189 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3190 #ifdef TCP_KEEPCNT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3191 PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3192 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3193 #ifdef TCP_SYNCNT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3194 PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3195 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3196 #ifdef TCP_LINGER2 |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3197 PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3198 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3199 #ifdef TCP_DEFER_ACCEPT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3200 PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3201 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3202 #ifdef TCP_WINDOW_CLAMP |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3203 PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3204 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3205 #ifdef TCP_INFO |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3206 PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3207 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3208 #ifdef TCP_QUICKACK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3209 PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); |
|
21526
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3210 #endif |
|
349d66cd874c
Add TCP socket options from glibc 2.2.4. Fixes #495680.
Martin v. Löwis <martin@v.loewis.de>
parents:
21128
diff
changeset
|
3211 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3212 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3213 /* IPX options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3214 #ifdef IPX_TYPE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3215 PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE); |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
3216 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3217 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3218 /* get{addr,name}info parameters */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3219 #ifdef EAI_ADDRFAMILY |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3220 PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3221 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3222 #ifdef EAI_AGAIN |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3223 PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3224 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3225 #ifdef EAI_BADFLAGS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3226 PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3227 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3228 #ifdef EAI_FAIL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3229 PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3230 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3231 #ifdef EAI_FAMILY |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3232 PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3233 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3234 #ifdef EAI_MEMORY |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3235 PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3236 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3237 #ifdef EAI_NODATA |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3238 PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3239 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3240 #ifdef EAI_NONAME |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3241 PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3242 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3243 #ifdef EAI_SERVICE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3244 PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3245 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3246 #ifdef EAI_SOCKTYPE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3247 PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3248 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3249 #ifdef EAI_SYSTEM |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3250 PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3251 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3252 #ifdef EAI_BADHINTS |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3253 PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3254 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3255 #ifdef EAI_PROTOCOL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3256 PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3257 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3258 #ifdef EAI_MAX |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3259 PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3260 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3261 #ifdef AI_PASSIVE |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3262 PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3263 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3264 #ifdef AI_CANONNAME |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3265 PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3266 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3267 #ifdef AI_NUMERICHOST |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3268 PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3269 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3270 #ifdef AI_MASK |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3271 PyModule_AddIntConstant(m, "AI_MASK", AI_MASK); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3272 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3273 #ifdef AI_ALL |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3274 PyModule_AddIntConstant(m, "AI_ALL", AI_ALL); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3275 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3276 #ifdef AI_V4MAPPED_CFG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3277 PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3278 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3279 #ifdef AI_ADDRCONFIG |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3280 PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3281 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3282 #ifdef AI_V4MAPPED |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3283 PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3284 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3285 #ifdef AI_DEFAULT |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3286 PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3287 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3288 #ifdef NI_MAXHOST |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3289 PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3290 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3291 #ifdef NI_MAXSERV |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3292 PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3293 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3294 #ifdef NI_NOFQDN |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3295 PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3296 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3297 #ifdef NI_NUMERICHOST |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3298 PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3299 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3300 #ifdef NI_NAMEREQD |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3301 PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3302 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3303 #ifdef NI_NUMERICSERV |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3304 PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3305 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3306 #ifdef NI_DGRAM |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
3307 PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3308 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3309 |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3310 /* Initialize gethostbyname lock */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3311 #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
|
3312 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
|
3313 #endif |
| 294 | 3314 } |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3315 |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3316 /* Simplistic emulation code for inet_pton that only works for IPv4 */ |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3317 #ifndef HAVE_INET_PTON |
|
18264
3d9164d95e78
Fix typos in inet_pton/inet_ntop.
Martin v. Löwis <martin@v.loewis.de>
parents:
18263
diff
changeset
|
3318 int |
|
18790
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
3319 inet_pton (int af, const char *src, void *dst) |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3320 { |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3321 if(af == AF_INET){ |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3322 long packed_addr; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3323 packed_addr = inet_addr(src); |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3324 if (packed_addr == INADDR_NONE) |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3325 return 0; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3326 memcpy(dst, &packed_addr, 4); |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3327 return 1; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3328 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3329 /* Should set errno to EAFNOSUPPORT */ |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3330 return -1; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3331 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3332 |
|
18790
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
3333 const char * |
|
7cd22bf56d7b
Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents:
18753
diff
changeset
|
3334 inet_ntop(int af, const void *src, char *dst, socklen_t size) |
|
18262
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3335 { |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3336 if (af == AF_INET) { |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3337 struct in_addr packed_addr; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3338 if (size < 16) |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3339 /* Should set errno to ENOSPC. */ |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3340 return NULL; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3341 memcpy(&packed_addr, src, sizeof(packed_addr)); |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3342 return strncpy(dst, inet_ntoa(packed_addr), size); |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3343 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3344 /* Should set errno to EAFNOSUPPORT */ |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3345 return NULL; |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3346 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
3347 #endif |
