Mercurial > cpython-lru_cache-weakref
annotate Modules/socketmodule.c @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | c9bd62efe6ce |
| children | 32e0f1aa34bc |
| rev | line source |
|---|---|
| 294 | 1 /* Socket module */ |
| 2 | |
| 3 /* | |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4 |
| 294 | 5 This module provides an interface to Berkeley socket IPC. |
| 6 | |
| 7 Limitations: | |
| 8 | |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
11 under Linux. |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
12 - No read/write operations (use sendall/recv or makefile instead). |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
13 - Additional restrictions apply on some non-Unix platforms (compensated |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
14 for by socket.py). |
| 294 | 15 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
16 Module interface: |
| 294 | 17 |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
18 - 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
|
19 - 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
|
20 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
|
21 - 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
|
22 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
|
23 - 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
|
24 - 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
|
25 - 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
|
26 - socket.getprotobyname(protocolname) --> protocol number |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
27 - socket.getservbyname(servicename[, protocolname]) --> port number |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
28 - socket.getservbyport(portnumber[, protocolname]) --> service name |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
29 - socket.socket([family[, type [, proto, fileno]]]) --> new socket object |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
30 (fileno specifies a pre-existing socket file descriptor) |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
31 - socket.socketpair([family[, type [, proto]]]) --> (socket, socket) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
32 - 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
|
33 - 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
|
34 - 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
|
35 - 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
|
36 - 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
|
37 --> 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
|
38 - socket.getnameinfo(sockaddr, flags) --> (host, port) |
|
2565
912813d573b4
fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents:
2532
diff
changeset
|
39 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h> |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
40 - socket.has_ipv6: boolean value indicating if IPv6 is supported |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
41 - 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
|
42 - socket.inet_ntoa(packed IP) -> IP address string |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
43 - socket.getdefaulttimeout() -> None | float |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
44 - socket.setdefaulttimeout(None | float) |
| 294 | 45 - an Internet socket address is a pair (hostname, port) |
| 46 where hostname can be anything recognized by gethostbyname() | |
| 47 (including the dd.dd.dd.dd notation) and port is in host byte order | |
| 48 - 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
|
49 - 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
|
50 - 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
|
51 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
|
52 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
|
53 ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple |
|
32611
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
54 specify packet-type and ha-type/addr. |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
55 - an AF_TIPC socket address is expressed as |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
56 (addr_type, v1, v2, v3 [, scope]); where addr_type can be one of: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
57 TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, and TIPC_ADDR_ID; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
58 and scope can be one of: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
59 TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE. |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
60 The meaning of v1, v2 and v3 depends on the value of addr_type: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
61 if addr_type is TIPC_ADDR_NAME: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
62 v1 is the server type |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
63 v2 is the port identifier |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
64 v3 is ignored |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
65 if addr_type is TIPC_ADDR_NAMESEQ: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
66 v1 is the server type |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
67 v2 is the lower port number |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
68 v3 is the upper port number |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
69 if addr_type is TIPC_ADDR_ID: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
70 v1 is the node |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
71 v2 is the ref |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
72 v3 is ignored |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
73 |
| 294 | 74 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
75 Local naming conventions: |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
76 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
77 - names starting with sock_ are socket object methods |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
78 - names starting with socket_ are module-level functions |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
79 - names starting with PySocket are exported through socketmodule.h |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
80 |
| 294 | 81 */ |
| 82 | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
83 #ifdef __APPLE__ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
84 /* |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
85 * inet_aton is not available on OSX 10.3, yet we want to use a binary |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
86 * that was build on 10.4 or later to work on that release, weak linking |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
87 * comes to the rescue. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
88 */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
89 # pragma weak inet_aton |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
90 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
91 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
92 #include "Python.h" |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
93 #include "structmember.h" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
94 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
95 #undef MAX |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
96 #define MAX(x, y) ((x) < (y) ? (y) : (x)) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
97 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
98 /* Socket object documentation */ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
99 PyDoc_STRVAR(sock_doc, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
100 "socket([family[, type[, proto]]]) -> socket object\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
101 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
102 Open a socket of the given type. The family argument specifies the\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
103 address family; it defaults to AF_INET. The type argument specifies\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
104 whether this is a stream (SOCK_STREAM, this is the default)\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
105 or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
106 specifying the default protocol. Keyword arguments are accepted.\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
107 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
108 A socket object represents one endpoint of a network connection.\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
109 \n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
110 Methods of socket objects (keyword arguments not allowed):\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
111 \n\ |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
112 _accept() -- accept connection, returning new socket fd and client address\n\ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
113 bind(addr) -- bind the socket to a local address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
114 close() -- close the socket\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
115 connect(addr) -- connect the socket to a remote address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
116 connect_ex(addr) -- connect, return an error code instead of an exception\n\ |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
117 _dup() -- return a new socket fd duplicated from fileno()\n\ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
118 fileno() -- return underlying file descriptor\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
119 getpeername() -- return remote address [*]\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
120 getsockname() -- return local address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
121 getsockopt(level, optname[, buflen]) -- get socket options\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
122 gettimeout() -- return timeout or None\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
123 listen(n) -- start listening for incoming connections\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
124 recv(buflen[, flags]) -- receive data\n\ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
125 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
126 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
127 recvfrom_into(buffer[, nbytes, [, flags])\n\ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
128 -- receive data and sender\'s address (into a buffer)\n\ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
129 sendall(data[, flags]) -- send all data\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
130 send(data[, flags]) -- send data, may not send all of it\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
131 sendto(data[, flags], addr) -- send data to a given address\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
132 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
133 setsockopt(level, optname, value) -- set socket options\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
134 settimeout(None | float) -- set or clear the timeout\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
135 shutdown(how) -- shut down traffic in one or both directions\n\ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
136 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
137 [*] not available on all platforms!"); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
138 |
|
30722
651fc8d98d99
Fix a bunch of typos in documentation, docstrings and comments.
Walter Dörwald <walter@livinglogic.de>
parents:
30683
diff
changeset
|
139 /* XXX This is a terrible mess of platform-dependent preprocessor hacks. |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
140 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
|
141 |
|
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
|
142 /* 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
|
143 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
|
144 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
|
145 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
|
146 |
|
adf87d13a0c1
(1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents:
11268
diff
changeset
|
147 #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
|
148 # 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
|
149 # 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
|
150 # 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
|
151 #endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
152 |
|
10579
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
153 #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
|
154 # 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
|
155 #endif |
|
1ed1eb5bc6ec
Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents:
10561
diff
changeset
|
156 |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
157 #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
|
158 # 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
|
159 # 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
|
160 # 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
|
161 # 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
|
162 # 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
|
163 /* 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
|
164 # 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
|
165 # 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
|
166 # endif |
|
10454
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
167 #endif |
|
dad14ffe1c22
Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents:
10453
diff
changeset
|
168 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
169 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && \ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
170 !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
|
171 # define USE_GETHOSTBYNAME_LOCK |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
172 #endif |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
173 |
|
35635
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
174 /* To use __FreeBSD_version */ |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
175 #ifdef HAVE_SYS_PARAM_H |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
176 #include <sys/param.h> |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
177 #endif |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
178 /* On systems on which getaddrinfo() is believed to not be thread-safe, |
|
29036
ccf7e138a126
Addition to [731644]: also use the lock when using the getaddrinfo
Just van Rossum <just@letterror.com>
parents:
29035
diff
changeset
|
179 (this includes the getaddrinfo emulation) protect access with a lock. */ |
|
35635
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
180 #if defined(WITH_THREAD) && (defined(__APPLE__) || \ |
|
27e1426b7f31
Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35551
diff
changeset
|
181 (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
182 defined(__OpenBSD__) || defined(__NetBSD__) || \ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
183 defined(__VMS) || !defined(HAVE_GETADDRINFO)) |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
184 #define USE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
185 #endif |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
186 |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
187 #ifdef USE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
188 #define ACQUIRE_GETADDRINFO_LOCK PyThread_acquire_lock(netdb_lock, 1); |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
189 #define RELEASE_GETADDRINFO_LOCK PyThread_release_lock(netdb_lock); |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
190 #else |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
191 #define ACQUIRE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
192 #define RELEASE_GETADDRINFO_LOCK |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
193 #endif |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
194 |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
195 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_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
|
196 # include "pythread.h" |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
197 #endif |
| 294 | 198 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
199 #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
|
200 # 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
|
201 # 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
|
202 # 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
|
203 # 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
|
204 # include <ctype.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
205 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
206 |
|
26551
0c995cd07026
Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
26550
diff
changeset
|
207 #if defined(__VMS) |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
208 # include <ioctl.h> |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
209 #endif |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
210 |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
211 #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
|
212 # 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
|
213 # 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
|
214 # 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
|
215 # include <os2.h> |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
216 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
217 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
218 #if defined(__sgi) && _COMPILER_VERSION>700 && !_SGIAPI |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
219 /* make sure that the reentrant (gethostbyaddr_r etc) |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
220 functions are declared correctly if compiling with |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
221 MIPSPro 7.x in ANSI C mode (default) */ |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
222 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
223 /* XXX Using _SGIAPI is the wrong thing, |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
224 but I don't know what the right thing is. */ |
|
33478
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
225 #undef _SGIAPI /* to avoid warning */ |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
226 #define _SGIAPI 1 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
227 |
|
33478
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
228 #undef _XOPEN_SOURCE |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
229 #include <sys/socket.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
230 #include <sys/types.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
231 #include <netinet/in.h> |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
232 #ifdef _SS_ALIGNSIZE |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
233 #define HAVE_GETADDRINFO 1 |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
234 #define HAVE_GETNAMEINFO 1 |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
235 #endif |
|
1b3ac674a57c
Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents:
33427
diff
changeset
|
236 |
|
29929
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
237 #define HAVE_INET_PTON |
|
08d2636b8e58
Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29790
diff
changeset
|
238 #include <netdb.h> |
|
25327
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
239 #endif |
|
337fcc24985b
Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents:
25105
diff
changeset
|
240 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
241 /* Irix 6.5 fails to define this variable at all. This is needed |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
242 for both GCC and SGI's compiler. I'd say that the SGI headers |
|
36610
0671f3c462d5
Bug #854823: socketmodule now builds on Sun platforms even when
Georg Brandl <georg@python.org>
parents:
36476
diff
changeset
|
243 are just busted. Same thing for Solaris. */ |
|
0671f3c462d5
Bug #854823: socketmodule now builds on Sun platforms even when
Georg Brandl <georg@python.org>
parents:
36476
diff
changeset
|
244 #if (defined(__sgi) || defined(sun)) && !defined(INET_ADDRSTRLEN) |
|
30646
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
245 #define INET_ADDRSTRLEN 16 |
|
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
246 #endif |
|
a6fb6822814a
made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
Anthony Baxter <anthonybaxter@gmail.com>
parents:
30630
diff
changeset
|
247 |
|
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
|
248 /* Generic includes */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
249 #ifdef HAVE_SYS_TYPES_H |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
250 #include <sys/types.h> |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
251 #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
|
252 |
|
21961
ea23e6e49290
Also fix the comment.
Marc-André Lemburg <mal@egenix.com>
parents:
21960
diff
changeset
|
253 /* 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
|
254 #define PySocket_BUILDING_SOCKET |
|
21960
7a917ad8f442
Fix the name of the header file.
Marc-André Lemburg <mal@egenix.com>
parents:
21959
diff
changeset
|
255 #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
|
256 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
257 /* 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
|
258 |
|
3738
ce74bba8a6a6
Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents:
3702
diff
changeset
|
259 #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
|
260 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
261 /* 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
|
262 # 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
|
263 |
|
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
|
264 /* Headers needed for inet_ntoa() and inet_addr() */ |
| 42645 | 265 # if defined(PYOS_OS2) && 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
|
266 # 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
|
267 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
|
268 # 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
|
269 # 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
|
270 # 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
|
271 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
272 # 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
|
273 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20648
diff
changeset
|
274 #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
|
275 |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
276 /* MS_WINDOWS includes */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
277 # ifdef HAVE_FCNTL_H |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
278 # include <fcntl.h> |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
279 # 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
|
280 |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
281 #endif |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
282 |
|
31504
2abc52c3d4c2
remove support for missing ANSI C header files (limits.h, stddef.h, etc).
Skip Montanaro <skip@pobox.com>
parents:
31443
diff
changeset
|
283 #include <stddef.h> |
|
18263
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
284 |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
285 #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
|
286 # 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
|
287 #endif |
|
41491d196748
Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents:
18262
diff
changeset
|
288 |
|
25994
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
289 #ifndef O_NONBLOCK |
|
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
290 # define O_NONBLOCK O_NDELAY |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
291 #endif |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
292 |
|
33427
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
293 /* include Python's addrinfo.h unless it causes trouble */ |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
294 #if defined(__sgi) && _COMPILER_VERSION>700 && defined(_SS_ALIGNSIZE) |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
295 /* Do not include addinfo.h on some newer IRIX versions. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
296 * _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21, |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
297 * for example, but not by 6.5.10. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
298 */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
299 #elif defined(_MSC_VER) && _MSC_VER>1201 |
|
33427
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
300 /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
301 * EAI_* constants are defined in (the already included) ws2tcpip.h. |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
302 */ |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
303 #else |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
304 # include "addrinfo.h" |
|
8480b72aa624
Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions.
Trent Mick <trentm@activestate.com>
parents:
33280
diff
changeset
|
305 #endif |
|
33066
cda0455bd0a0
Bug #1001857: socketmodule does not build under cygwin
Jason Tishler <jason@tishler.net>
parents:
33063
diff
changeset
|
306 |
|
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
|
307 #ifndef HAVE_INET_PTON |
|
43926
2de7d00fbf19
The patch from weck does a better job than my original idea. Thanks!
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
308 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
309 int inet_pton(int af, const char *src, void *dst); |
|
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
|
310 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
|
311 #endif |
| 43874 | 312 #endif |
|
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
|
313 |
|
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
|
314 #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
|
315 /* 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 appropriate, which is 10/0 on the system with the bug. */ |
|
24078
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
323 #ifndef HAVE_GETNAMEINFO |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
324 /* This bug seems to be fixed in Jaguar. Ths easiest way I could |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
325 Find to check for Jaguar is that it has getnameinfo(), which |
|
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
326 older releases don't have */ |
|
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
|
327 #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
|
328 #endif |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
329 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
330 #ifdef HAVE_INET_ATON |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
331 #define USE_INET_ATON_WEAKLINK |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
332 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
333 |
|
24078
702a5900df7d
Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents:
23832
diff
changeset
|
334 #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
|
335 |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
336 /* 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
|
337 #if !defined(HAVE_GETADDRINFO) |
|
28913
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
338 /* avoid clashes with the C library definition of the symbol. */ |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
339 #define getaddrinfo fake_getaddrinfo |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
340 #define gai_strerror fake_gai_strerror |
|
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
341 #define freeaddrinfo fake_freeaddrinfo |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
342 #include "getaddrinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
343 #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
|
344 #if !defined(HAVE_GETNAMEINFO) |
|
28913
b04c074586aa
Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents:
28818
diff
changeset
|
345 #define getnameinfo fake_getnameinfo |
|
18246
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
346 #include "getnameinfo.c" |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
347 #endif |
|
c4db09b87424
Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents:
17806
diff
changeset
|
348 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
349 #ifdef MS_WINDOWS |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
350 /* On Windows a socket is really a handle not an fd */ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
351 static SOCKET |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
352 dup_socket(SOCKET handle) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
353 { |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
354 HANDLE newhandle; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
355 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
356 if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle, |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
357 GetCurrentProcess(), &newhandle, |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
358 0, FALSE, DUPLICATE_SAME_ACCESS)) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
359 { |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
360 WSASetLastError(GetLastError()); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
361 return INVALID_SOCKET; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
362 } |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
363 return (SOCKET)newhandle; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
364 } |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
365 #define SOCKETCLOSE closesocket |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
366 #else |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
367 /* On Unix we can use dup to duplicate the file descriptor of a socket*/ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
368 #define dup_socket(fd) dup(fd) |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
369 #endif |
|
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
370 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
371 #ifdef MS_WIN32 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
372 #define EAFNOSUPPORT WSAEAFNOSUPPORT |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
373 #define snprintf _snprintf |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
374 #endif |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
375 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
376 #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
|
377 #define SOCKETCLOSE soclose |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
378 #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
|
379 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
380 |
|
12436
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
381 #ifndef SOCKETCLOSE |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
382 #define SOCKETCLOSE close |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
383 #endif |
|
dff7b26116de
Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents:
12319
diff
changeset
|
384 |
|
52561
8f51dd09f3f2
Merged revisions 70849,70852 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents:
51579
diff
changeset
|
385 #if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H) && !defined(__NetBSD__) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
386 #define USE_BLUETOOTH 1 |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
387 #if defined(__FreeBSD__) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
388 #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
389 #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
390 #define BTPROTO_HCI BLUETOOTH_PROTO_HCI |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41943
diff
changeset
|
391 #define SOL_HCI SOL_HCI_RAW |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41943
diff
changeset
|
392 #define HCI_FILTER SO_HCI_RAW_FILTER |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
393 #define sockaddr_l2 sockaddr_l2cap |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
394 #define sockaddr_rc sockaddr_rfcomm |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41943
diff
changeset
|
395 #define hci_dev hci_node |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
396 #define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
397 #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb) |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
398 #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
399 #elif defined(__NetBSD__) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
400 #define sockaddr_l2 sockaddr_bt |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
401 #define sockaddr_rc sockaddr_bt |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
402 #define sockaddr_hci sockaddr_bt |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
403 #define sockaddr_sco sockaddr_bt |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
404 #define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
405 #define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb) |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
406 #define _BT_HCI_MEMB(sa, memb) ((sa)->bt_##memb) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
407 #define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
408 #else |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
409 #define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
410 #define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb) |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
411 #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb) |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
412 #define _BT_SCO_MEMB(sa, memb) ((sa)->sco_##memb) |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
413 #endif |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
414 #endif |
|
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
415 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
416 #ifdef __VMS |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
417 /* TCP/IP Services for VMS uses a maximum send/recv buffer length */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
418 #define SEGMENT_SIZE (32 * 1024 -1) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
419 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
420 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
421 #define SAS2SA(x) ((struct sockaddr *)(x)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
422 |
|
28953
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
423 /* |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
424 * Constants for getnameinfo() |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
425 */ |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
426 #if !defined(NI_MAXHOST) |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
427 #define NI_MAXHOST 1025 |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
428 #endif |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
429 #if !defined(NI_MAXSERV) |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
430 #define NI_MAXSERV 32 |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
431 #endif |
|
09422c301826
Patch #724588: Check whether the address of hstrerror and inet_pton can
Martin v. Löwis <martin@v.loewis.de>
parents:
28949
diff
changeset
|
432 |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
433 #ifndef INVALID_SOCKET /* MS defines this */ |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
434 #define INVALID_SOCKET (-1) |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
435 #endif |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
436 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
437 /* 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
|
438 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
|
439 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
440 /* 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
|
441 by this module (but not argument type or memory errors, etc.). */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
442 static PyObject *socket_error; |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
443 static PyObject *socket_herror; |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
444 static PyObject *socket_gaierror; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
445 static PyObject *socket_timeout; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
446 |
|
21970
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
447 /* A forward reference to the socket type object. |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
448 The sock_type variable contains pointers to various functions, |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
449 some of which call new_sockobject(), which uses sock_type, so |
|
21970
b1a871dc5196
Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents:
21964
diff
changeset
|
450 there has to be a circular reference. */ |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24078
diff
changeset
|
451 static PyTypeObject sock_type; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
452 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
453 #if defined(HAVE_POLL_H) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
454 #include <poll.h> |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
455 #elif defined(HAVE_SYS_POLL_H) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
456 #include <sys/poll.h> |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
457 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
458 |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
459 #ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
460 /* Platform can select file descriptors beyond FD_SETSIZE */ |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
461 #define IS_SELECTABLE(s) 1 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
462 #elif defined(HAVE_POLL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
463 /* Instead of select(), we'll use poll() since poll() works on any fd. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
464 #define IS_SELECTABLE(s) 1 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
465 /* Can we call select() with this socket without a buffer overrun? */ |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
466 #else |
|
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
467 /* POSIX says selecting file descriptors beyond FD_SETSIZE |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
468 has undefined behaviour. If there's no timeout left, we don't have to |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
469 call select, so it's a safe, little white lie. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
470 #define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0) |
|
36476
c073dffbe70e
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents:
36452
diff
changeset
|
471 #endif |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
472 |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
473 static PyObject* |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
474 select_error(void) |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
475 { |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
476 PyErr_SetString(socket_error, "unable to select on socket"); |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
477 return NULL; |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
478 } |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
479 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
480 /* 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
|
481 and return a NULL pointer from a function. */ |
| 294 | 482 |
| 1970 | 483 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
484 set_error(void) |
| 294 | 485 { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
486 #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
|
487 int err_no = WSAGetLastError(); |
|
43877
1165d261fb05
Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43874
diff
changeset
|
488 /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which |
|
1165d261fb05
Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43874
diff
changeset
|
489 recognizes the error codes used by both GetLastError() and |
|
1165d261fb05
Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43874
diff
changeset
|
490 WSAGetLastError */ |
|
1165d261fb05
Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43874
diff
changeset
|
491 if (err_no) |
|
1165d261fb05
Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43874
diff
changeset
|
492 return PyErr_SetExcFromWindowsErr(socket_error, err_no); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1867
diff
changeset
|
493 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
494 |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
495 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
496 if (sock_errno() != NO_ERROR) { |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
497 APIRET rc; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
498 ULONG msglen; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
499 char outbuf[100]; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
500 int myerrorcode = sock_errno(); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
501 |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
502 /* Retrieve socket-related error message from MPTN.MSG file */ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
503 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf), |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
504 myerrorcode - SOCBASEERR + 26, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
505 "mptn.msg", |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
506 &msglen); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
507 if (rc == NO_ERROR) { |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
508 PyObject *v; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
509 |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
510 /* OS/2 doesn't guarantee a terminator */ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
511 outbuf[msglen] = '\0'; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
512 if (strlen(outbuf) > 0) { |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
513 /* If non-empty msg, trim CRLF */ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
514 char *lastc = &outbuf[ strlen(outbuf)-1 ]; |
|
36090
8cb686dd6e64
Fix SF bug #1072182, problems with signed characters.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35999
diff
changeset
|
515 while (lastc > outbuf && |
|
8cb686dd6e64
Fix SF bug #1072182, problems with signed characters.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35999
diff
changeset
|
516 isspace(Py_CHARMASK(*lastc))) { |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
517 /* Trim trailing whitespace (CRLF) */ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
518 *lastc-- = '\0'; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
519 } |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
520 } |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
521 v = Py_BuildValue("(is)", myerrorcode, outbuf); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
522 if (v != NULL) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
523 PyErr_SetObject(socket_error, v); |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
524 Py_DECREF(v); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
525 } |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
526 return NULL; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
527 } |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
528 } |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
529 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
530 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
531 return PyErr_SetFromErrno(socket_error); |
| 294 | 532 } |
| 533 | |
|
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 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
536 set_herror(int h_error) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
537 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
538 PyObject *v; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
539 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
540 #ifdef HAVE_HSTRERROR |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
541 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
|
542 #else |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
543 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
|
544 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
545 if (v != NULL) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
546 PyErr_SetObject(socket_herror, v); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
547 Py_DECREF(v); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
548 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
549 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
550 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
551 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
552 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
553 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
554 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
555 set_gaierror(int error) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
556 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
557 PyObject *v; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
558 |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
559 #ifdef EAI_SYSTEM |
|
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
560 /* 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
|
561 if (error == EAI_SYSTEM) |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
562 return set_error(); |
|
22096
9e5ff6747437
Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents:
21970
diff
changeset
|
563 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
564 |
|
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
|
565 #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
|
566 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
|
567 #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
|
568 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
|
569 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
570 if (v != NULL) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
571 PyErr_SetObject(socket_gaierror, v); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
572 Py_DECREF(v); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
573 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
574 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
575 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
576 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
577 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
578 #ifdef __VMS |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
579 /* Function to send in segments */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
580 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
581 sendsegmented(int sock_fd, char *buf, int len, int flags) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
582 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
583 int n = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
584 int remaining = len; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
585 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
586 while (remaining > 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
587 unsigned int segment; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
588 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
589 segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
590 n = send(sock_fd, buf, segment, flags); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
591 if (n < 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
592 return n; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
593 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
594 remaining -= segment; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
595 buf += segment; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
596 } /* end while */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
597 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
598 return len; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
599 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
600 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
601 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
602 /* Function to perform the setting of socket blocking mode |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
603 internally. block = (1 | 0). */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
604 static int |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
605 internal_setblocking(PySocketSockObject *s, int block) |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
606 { |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
607 #ifndef MS_WINDOWS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
608 int delay_flag; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
609 #endif |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
610 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
611 Py_BEGIN_ALLOW_THREADS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
612 #ifndef MS_WINDOWS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
613 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
614 block = !block; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
615 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
616 #elif defined(__VMS) |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
617 block = !block; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
618 ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
619 #else /* !PYOS_OS2 && !__VMS */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
620 delay_flag = fcntl(s->sock_fd, F_GETFL, 0); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
621 if (block) |
|
25994
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
622 delay_flag &= (~O_NONBLOCK); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
623 else |
|
25994
bb813346b227
Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25327
diff
changeset
|
624 delay_flag |= O_NONBLOCK; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
625 fcntl(s->sock_fd, F_SETFL, delay_flag); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
626 #endif /* !PYOS_OS2 */ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
627 #else /* MS_WINDOWS */ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
628 block = !block; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
629 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
630 #endif /* MS_WINDOWS */ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
631 Py_END_ALLOW_THREADS |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
632 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
633 /* Since these don't return anything */ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
634 return 1; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
635 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
636 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
637 /* Do a select()/poll() on the socket, if necessary (sock_timeout > 0). |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
638 The argument writing indicates the direction. |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
639 This does not raise an exception; we'll let our caller do that |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
640 after they've reacquired the interpreter lock. |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
641 Returns 1 on timeout, -1 on error, 0 otherwise. */ |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
642 static int |
|
23722
75c51999c8d5
Correct several blunders in the timeout code, mostly my own fault (for
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
643 internal_select(PySocketSockObject *s, int writing) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
644 { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
645 int n; |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
646 |
|
24317
29ae8e89153b
Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents:
24305
diff
changeset
|
647 /* Nothing to do unless we're in timeout mode (not non-blocking) */ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
648 if (s->sock_timeout <= 0.0) |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
649 return 0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
650 |
|
24317
29ae8e89153b
Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents:
24305
diff
changeset
|
651 /* Guard against closed socket */ |
|
29ae8e89153b
Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents:
24305
diff
changeset
|
652 if (s->sock_fd < 0) |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
653 return 0; |
|
24317
29ae8e89153b
Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents:
24305
diff
changeset
|
654 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
655 /* Prefer poll, if available, since you can poll() any fd |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
656 * which can't be done with select(). */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
657 #ifdef HAVE_POLL |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
658 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
659 struct pollfd pollfd; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
660 int timeout; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
661 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
662 pollfd.fd = s->sock_fd; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
663 pollfd.events = writing ? POLLOUT : POLLIN; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
664 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
665 /* s->sock_timeout is in seconds, timeout in ms */ |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
666 timeout = (int)(s->sock_timeout * 1000 + 0.5); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
667 n = poll(&pollfd, 1, timeout); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
668 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
669 #else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
670 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
671 /* Construct the arguments to select */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
672 fd_set fds; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
673 struct timeval tv; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
674 tv.tv_sec = (int)s->sock_timeout; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
675 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
676 FD_ZERO(&fds); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
677 FD_SET(s->sock_fd, &fds); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
678 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
679 /* See if the socket is ready */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
680 if (writing) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
681 n = select(s->sock_fd+1, NULL, &fds, NULL, &tv); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
682 else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
683 n = select(s->sock_fd+1, &fds, NULL, NULL, &tv); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
684 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
685 #endif |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
686 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
687 if (n < 0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
688 return -1; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
689 if (n == 0) |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
690 return 1; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
691 return 0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
692 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
693 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
694 /* 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
|
695 |
|
24305
428cbbf05639
A Python float is a C double; redeclare defaulttimeout as such; stops
Tim Peters <tim.peters@gmail.com>
parents:
24303
diff
changeset
|
696 static double defaulttimeout = -1.0; /* Default timeout for new sockets */ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
697 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
698 static void |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
699 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
|
700 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
|
701 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 s->sock_proto = proto; |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
706 s->sock_timeout = defaulttimeout; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
707 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
708 s->errorhandler = &set_error; |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
709 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
710 if (defaulttimeout >= 0.0) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
711 internal_setblocking(s, 0); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
712 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
713 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
714 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
715 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
716 /* Create a new socket object. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
717 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
|
718 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
|
719 in NEWOBJ()). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
720 |
| 1970 | 721 static PySocketSockObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
722 new_sockobject(SOCKET_T fd, int family, int type, int proto) |
| 294 | 723 { |
| 1970 | 724 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
|
725 s = (PySocketSockObject *) |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
726 PyType_GenericNew(&sock_type, NULL, NULL); |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
727 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
|
728 init_sockobject(s, fd, family, type, proto); |
| 294 | 729 return s; |
| 730 } | |
| 731 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
732 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
733 /* Lock to allow python interpreter to continue, but only allow one |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
734 thread to be in gethostbyname or getaddrinfo */ |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
735 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
736 PyThread_type_lock netdb_lock; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
737 #endif |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
738 |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
739 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
740 /* 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 |
| 294 | 746 static int |
|
24411
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
747 setipaddr(char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int af) |
| 294 | 748 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
749 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
|
750 int error; |
|
28925
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
751 int d1, d2, d3, d4; |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
752 char ch; |
| 294 | 753 |
| 4600 | 754 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
|
755 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
|
756 int siz; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
757 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
|
758 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
|
759 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
|
760 hints.ai_flags = AI_PASSIVE; |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
761 Py_BEGIN_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
762 ACQUIRE_GETADDRINFO_LOCK |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
763 error = getaddrinfo(NULL, "0", &hints, &res); |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
764 Py_END_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
765 /* We assume that those thread-unsafe getaddrinfo() versions |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
766 *are* safe regarding their return value, ie. that a |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
767 subsequent call to getaddrinfo() does not destroy the |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
768 outcome of the first call. */ |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
769 RELEASE_GETADDRINFO_LOCK |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
770 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
771 set_gaierror(error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
772 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
773 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
774 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
|
775 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
776 siz = 4; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
777 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
778 #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
|
779 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
780 siz = 16; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
781 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
782 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
783 default: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
784 freeaddrinfo(res); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
785 PyErr_SetString(socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
786 "unsupported address family"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
787 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
788 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
789 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
|
790 freeaddrinfo(res); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
791 PyErr_SetString(socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
792 "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
|
793 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
794 } |
|
24411
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
795 if (res->ai_addrlen < addr_ret_size) |
|
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
796 addr_ret_size = res->ai_addrlen; |
|
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
797 memcpy(addr_ret, res->ai_addr, addr_ret_size); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
798 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
799 return siz; |
| 294 | 800 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
801 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
|
802 struct sockaddr_in *sin; |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
803 if (af != AF_INET && af != AF_UNSPEC) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
804 PyErr_SetString(socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
805 "address family mismatched"); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
806 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
807 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 #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
|
812 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
|
813 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
814 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
|
815 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
|
816 } |
|
28925
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
817 if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
818 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
819 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
820 struct sockaddr_in *sin; |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
821 sin = (struct sockaddr_in *)addr_ret; |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
822 sin->sin_addr.s_addr = htonl( |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
823 ((long) d1 << 24) | ((long) d2 << 16) | |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
824 ((long) d3 << 8) | ((long) d4 << 0)); |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
825 sin->sin_family = AF_INET; |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
826 #ifdef HAVE_SOCKADDR_SA_LEN |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
827 sin->sin_len = sizeof(*sin); |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
828 #endif |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
829 return 4; |
|
a769e079bb12
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28913
diff
changeset
|
830 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
831 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
|
832 hints.ai_family = af; |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
833 Py_BEGIN_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
834 ACQUIRE_GETADDRINFO_LOCK |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
835 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
|
836 #if defined(__digital__) && defined(__unix__) |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
837 if (error == EAI_NONAME && af == AF_UNSPEC) { |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
838 /* On Tru64 V5.1, numeric-to-addr conversion fails |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
839 if no address family is given. Assume IPv4 for now.*/ |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
840 hints.ai_family = AF_INET; |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
841 error = getaddrinfo(name, NULL, &hints, &res); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
842 } |
|
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
|
843 #endif |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
844 Py_END_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
845 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
846 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
847 set_gaierror(error); |
| 294 | 848 return -1; |
| 849 } | |
|
24411
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
850 if (res->ai_addrlen < addr_ret_size) |
|
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
851 addr_ret_size = res->ai_addrlen; |
|
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
852 memcpy((char *) addr_ret, res->ai_addr, addr_ret_size); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
853 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
854 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
|
855 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
856 return 4; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
857 #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
|
858 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
859 return 16; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
860 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
861 default: |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
862 PyErr_SetString(socket_error, "unknown address family"); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
863 return -1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
864 } |
| 294 | 865 } |
| 866 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
867 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
868 /* 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
|
869 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
|
870 size numbers). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
871 |
| 1970 | 872 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
873 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
|
874 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
875 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
|
876 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
877 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
878 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
|
879 NI_NUMERICHOST); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
880 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
881 set_gaierror(error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
882 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
883 } |
| 42596 | 884 return PyUnicode_FromString(buf); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
885 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
886 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
887 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
888 #ifdef USE_BLUETOOTH |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
889 /* Convert a string representation of a Bluetooth address into a numeric |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
890 address. Returns the length (6), or raises an exception and returns -1 if |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
891 an error occurred. */ |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
892 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
893 static int |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
894 setbdaddr(char *name, bdaddr_t *bdaddr) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
895 { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
896 unsigned int b0, b1, b2, b3, b4, b5; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
897 char ch; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
898 int n; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
899 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
900 n = sscanf(name, "%X:%X:%X:%X:%X:%X%c", |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
901 &b5, &b4, &b3, &b2, &b1, &b0, &ch); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
902 if (n == 6 && (b0 | b1 | b2 | b3 | b4 | b5) < 256) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
903 bdaddr->b[0] = b0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
904 bdaddr->b[1] = b1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
905 bdaddr->b[2] = b2; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
906 bdaddr->b[3] = b3; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
907 bdaddr->b[4] = b4; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
908 bdaddr->b[5] = b5; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
909 return 6; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
910 } else { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
911 PyErr_SetString(socket_error, "bad bluetooth address"); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
912 return -1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
913 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
914 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
915 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
916 /* Create a string representation of the Bluetooth address. This is always a |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
917 string of the form 'XX:XX:XX:XX:XX:XX' where XX is a two digit hexadecimal |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
918 value (zero padded if necessary). */ |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
919 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
920 static PyObject * |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
921 makebdaddr(bdaddr_t *bdaddr) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
922 { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
923 char buf[(6 * 2) + 5 + 1]; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
924 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
925 sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
926 bdaddr->b[5], bdaddr->b[4], bdaddr->b[3], |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
927 bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]); |
| 42596 | 928 return PyUnicode_FromString(buf); |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
929 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
930 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
931 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
932 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
933 /* 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
|
934 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
|
935 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
|
936 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
|
937 |
| 294 | 938 /*ARGSUSED*/ |
| 1970 | 939 static PyObject * |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
940 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) |
| 294 | 941 { |
|
925
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
942 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
|
943 /* No address -- may be recvfrom() from known socket */ |
| 1970 | 944 Py_INCREF(Py_None); |
| 945 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
|
946 } |
|
61143bf03b44
Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
947 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
948 switch (addr->sa_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
949 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
950 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
951 { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
952 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
|
953 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
|
954 PyObject *ret = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
955 if (addrobj) { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
956 a = (struct sockaddr_in *)addr; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
957 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
|
958 Py_DECREF(addrobj); |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
959 } |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
960 return ret; |
| 294 | 961 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
962 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
963 #if defined(AF_UNIX) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
964 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
965 { |
| 294 | 966 struct sockaddr_un *a = (struct sockaddr_un *) addr; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
967 #ifdef linux |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
968 if (a->sun_path[0] == 0) { /* Linux abstract namespace */ |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44810
diff
changeset
|
969 addrlen -= offsetof(struct sockaddr_un, sun_path); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
970 return PyBytes_FromStringAndSize(a->sun_path, addrlen); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
971 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
972 else |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
973 #endif /* linux */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
974 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
975 /* regular NULL-terminated string */ |
| 42596 | 976 return PyUnicode_FromString(a->sun_path); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
977 } |
| 294 | 978 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
979 #endif /* AF_UNIX */ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
980 |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
981 #if defined(AF_NETLINK) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
982 case AF_NETLINK: |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
983 { |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
984 struct sockaddr_nl *a = (struct sockaddr_nl *) addr; |
|
36289
7ca51cb70c2e
Change build format of netlink addresses.
Martin v. Löwis <martin@v.loewis.de>
parents:
36286
diff
changeset
|
985 return Py_BuildValue("II", a->nl_pid, a->nl_groups); |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
986 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
987 #endif /* AF_NETLINK */ |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
988 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
989 #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
|
990 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
991 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
992 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
|
993 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
|
994 PyObject *ret = NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
995 if (addrobj) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
996 a = (struct sockaddr_in6 *)addr; |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
997 ret = Py_BuildValue("Oiii", |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
998 addrobj, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
999 ntohs(a->sin6_port), |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1000 a->sin6_flowinfo, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1001 a->sin6_scope_id); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1002 Py_DECREF(addrobj); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1003 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1004 return ret; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1005 } |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1006 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1007 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1008 #ifdef USE_BLUETOOTH |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1009 case AF_BLUETOOTH: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1010 switch (proto) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1011 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1012 case BTPROTO_L2CAP: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1013 { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1014 struct sockaddr_l2 *a = (struct sockaddr_l2 *) addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1015 PyObject *addrobj = makebdaddr(&_BT_L2_MEMB(a, bdaddr)); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1016 PyObject *ret = NULL; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1017 if (addrobj) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1018 ret = Py_BuildValue("Oi", |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1019 addrobj, |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1020 _BT_L2_MEMB(a, psm)); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1021 Py_DECREF(addrobj); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1022 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1023 return ret; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1024 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1025 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1026 case BTPROTO_RFCOMM: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1027 { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1028 struct sockaddr_rc *a = (struct sockaddr_rc *) addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1029 PyObject *addrobj = makebdaddr(&_BT_RC_MEMB(a, bdaddr)); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1030 PyObject *ret = NULL; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1031 if (addrobj) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1032 ret = Py_BuildValue("Oi", |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1033 addrobj, |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1034 _BT_RC_MEMB(a, channel)); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1035 Py_DECREF(addrobj); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1036 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1037 return ret; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1038 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1039 |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1040 case BTPROTO_HCI: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1041 { |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1042 struct sockaddr_hci *a = (struct sockaddr_hci *) addr; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1043 PyObject *ret = NULL; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1044 ret = Py_BuildValue("i", _BT_HCI_MEMB(a, dev)); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1045 return ret; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1046 } |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1047 |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1048 #if !defined(__FreeBSD__) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1049 case BTPROTO_SCO: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1050 { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1051 struct sockaddr_sco *a = (struct sockaddr_sco *) addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1052 return makebdaddr(&_BT_SCO_MEMB(a, bdaddr)); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1053 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1054 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1055 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1056 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1057 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1058 |
|
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
|
1059 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1060 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1061 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1062 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
|
1063 char *ifname = ""; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1064 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
|
1065 /* 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
|
1066 if (a->sll_ifindex) { |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1067 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
|
1068 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1069 ifname = ifr.ifr_name; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1070 } |
| 42596 | 1071 return Py_BuildValue("shbhy#", |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1072 ifname, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1073 ntohs(a->sll_protocol), |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1074 a->sll_pkttype, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1075 a->sll_hatype, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1076 a->sll_addr, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1077 a->sll_halen); |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1078 } |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1079 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1080 |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1081 #ifdef HAVE_LINUX_TIPC_H |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1082 case AF_TIPC: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1083 { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1084 struct sockaddr_tipc *a = (struct sockaddr_tipc *) addr; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1085 if (a->addrtype == TIPC_ADDR_NAMESEQ) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1086 return Py_BuildValue("IIIII", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1087 a->addrtype, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1088 a->addr.nameseq.type, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1089 a->addr.nameseq.lower, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1090 a->addr.nameseq.upper, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1091 a->scope); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1092 } else if (a->addrtype == TIPC_ADDR_NAME) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1093 return Py_BuildValue("IIIII", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1094 a->addrtype, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1095 a->addr.name.name.type, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1096 a->addr.name.name.instance, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1097 a->addr.name.name.instance, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1098 a->scope); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1099 } else if (a->addrtype == TIPC_ADDR_ID) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1100 return Py_BuildValue("IIIII", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1101 a->addrtype, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1102 a->addr.id.node, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1103 a->addr.id.ref, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1104 0, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1105 a->scope); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1106 } else { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1107 PyErr_SetString(PyExc_TypeError, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1108 "Invalid address type"); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1109 return NULL; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1110 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1111 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1112 #endif |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1113 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1114 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1115 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1116 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
|
1117 /* If we don't know the address family, don't raise an |
|
42509
043a102a170e
Fix two bugs in socket_getaddr():
Guido van Rossum <guido@python.org>
parents:
42439
diff
changeset
|
1118 exception -- return it as an (int, bytes) tuple. */ |
|
043a102a170e
Fix two bugs in socket_getaddr():
Guido van Rossum <guido@python.org>
parents:
42439
diff
changeset
|
1119 return Py_BuildValue("iy#", |
|
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
|
1120 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
|
1121 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
|
1122 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
|
1123 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1124 } |
| 294 | 1125 } |
| 1126 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1127 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1128 /* 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
|
1129 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
|
1130 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
|
1131 through len_ret. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1132 |
| 294 | 1133 static int |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1134 getsockaddrarg(PySocketSockObject *s, PyObject *args, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1135 struct sockaddr *addr_ret, int *len_ret) |
| 294 | 1136 { |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1137 switch (s->sock_family) { |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1138 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
1139 #if defined(AF_UNIX) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1140 case AF_UNIX: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1141 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1142 struct sockaddr_un* addr; |
| 926 | 1143 char *path; |
| 294 | 1144 int len; |
|
42918
9220931e4741
More changes needed to make things work once bytes and str are truly divorced.
Guido van Rossum <guido@python.org>
parents:
42709
diff
changeset
|
1145 if (!PyArg_Parse(args, "s#", &path, &len)) |
| 294 | 1146 return 0; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1147 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1148 addr = (struct sockaddr_un*)addr_ret; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1149 #ifdef linux |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1150 if (len > 0 && path[0] == 0) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1151 /* Linux abstract namespace extension */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1152 if (len > sizeof addr->sun_path) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1153 PyErr_SetString(socket_error, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1154 "AF_UNIX path too long"); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1155 return 0; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1156 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1157 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1158 else |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1159 #endif /* linux */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1160 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1161 /* regular NULL-terminated string */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1162 if (len >= sizeof addr->sun_path) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1163 PyErr_SetString(socket_error, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1164 "AF_UNIX path too long"); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1165 return 0; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1166 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
1167 addr->sun_path[len] = 0; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1168 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1169 addr->sun_family = s->sock_family; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1170 memcpy(addr->sun_path, path, len); |
|
31896
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1171 #if defined(PYOS_OS2) |
|
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1172 *len_ret = sizeof(*addr); |
|
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1173 #else |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44810
diff
changeset
|
1174 *len_ret = len + offsetof(struct sockaddr_un, sun_path); |
|
31896
ca2fb5cf2fd5
Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31867
diff
changeset
|
1175 #endif |
| 294 | 1176 return 1; |
| 1177 } | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1178 #endif /* AF_UNIX */ |
| 294 | 1179 |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1180 #if defined(AF_NETLINK) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1181 case AF_NETLINK: |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1182 { |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1183 struct sockaddr_nl* addr; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1184 int pid, groups; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1185 addr = (struct sockaddr_nl *)addr_ret; |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1186 if (!PyTuple_Check(args)) { |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1187 PyErr_Format( |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1188 PyExc_TypeError, |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1189 "getsockaddrarg: " |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1190 "AF_NETLINK address must be tuple, not %.500s", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
1191 Py_TYPE(args)->tp_name); |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1192 return 0; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1193 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1194 if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups)) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1195 return 0; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1196 addr->nl_family = AF_NETLINK; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1197 addr->nl_pid = pid; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1198 addr->nl_groups = groups; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1199 *len_ret = sizeof(*addr); |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1200 return 1; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1201 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1202 #endif |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1203 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1204 case AF_INET: |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1205 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1206 struct sockaddr_in* addr; |
| 926 | 1207 char *host; |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1208 int port, result; |
|
15466
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
1209 if (!PyTuple_Check(args)) { |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1210 PyErr_Format( |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1211 PyExc_TypeError, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1212 "getsockaddrarg: " |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1213 "AF_INET address must be tuple, not %.500s", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
1214 Py_TYPE(args)->tp_name); |
|
15466
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
1215 return 0; |
|
9731bbb52fb4
Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents:
15046
diff
changeset
|
1216 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1217 if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
1218 "idna", &host, &port)) |
| 294 | 1219 return 0; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1220 addr=(struct sockaddr_in*)addr_ret; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1221 result = setipaddr(host, (struct sockaddr *)addr, |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1222 sizeof(*addr), AF_INET); |
|
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1223 PyMem_Free(host); |
|
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1224 if (result < 0) |
| 294 | 1225 return 0; |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1226 if (port < 0 || port > 0xffff) { |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1227 PyErr_SetString( |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1228 PyExc_OverflowError, |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1229 "getsockaddrarg: port must be 0-65535."); |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1230 return 0; |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1231 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1232 addr->sin_family = AF_INET; |
|
5287
5af766a1b531
Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents:
4871
diff
changeset
|
1233 addr->sin_port = htons((short)port); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
1234 *len_ret = sizeof *addr; |
| 294 | 1235 return 1; |
| 1236 } | |
| 1237 | |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1238 #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
|
1239 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1240 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1241 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
|
1242 char *host; |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1243 int port, flowinfo, scope_id, result; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1244 flowinfo = scope_id = 0; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1245 if (!PyTuple_Check(args)) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1246 PyErr_Format( |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1247 PyExc_TypeError, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1248 "getsockaddrarg: " |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1249 "AF_INET6 address must be tuple, not %.500s", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
1250 Py_TYPE(args)->tp_name); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1251 return 0; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1252 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1253 if (!PyArg_ParseTuple(args, "eti|ii", |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
1254 "idna", &host, &port, &flowinfo, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1255 &scope_id)) { |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1256 return 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1257 } |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1258 addr = (struct sockaddr_in6*)addr_ret; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1259 result = setipaddr(host, (struct sockaddr *)addr, |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1260 sizeof(*addr), AF_INET6); |
|
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1261 PyMem_Free(host); |
|
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
1262 if (result < 0) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1263 return 0; |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1264 if (port < 0 || port > 0xffff) { |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1265 PyErr_SetString( |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1266 PyExc_OverflowError, |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1267 "getsockaddrarg: port must be 0-65535."); |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1268 return 0; |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1269 } |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1270 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
|
1271 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
|
1272 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
|
1273 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
|
1274 *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
|
1275 return 1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1276 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1277 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1278 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1279 #ifdef USE_BLUETOOTH |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1280 case AF_BLUETOOTH: |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1281 { |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1282 switch (s->sock_proto) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1283 case BTPROTO_L2CAP: |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1284 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1285 struct sockaddr_l2 *addr; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1286 char *straddr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1287 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1288 addr = (struct sockaddr_l2 *)addr_ret; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1289 _BT_L2_MEMB(addr, family) = AF_BLUETOOTH; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1290 if (!PyArg_ParseTuple(args, "si", &straddr, |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1291 &_BT_L2_MEMB(addr, psm))) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1292 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1293 "wrong format"); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1294 return 0; |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1295 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1296 if (setbdaddr(straddr, &_BT_L2_MEMB(addr, bdaddr)) < 0) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1297 return 0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1298 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1299 *len_ret = sizeof *addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1300 return 1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1301 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1302 case BTPROTO_RFCOMM: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1303 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1304 struct sockaddr_rc *addr; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1305 char *straddr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1306 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1307 addr = (struct sockaddr_rc *)addr_ret; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1308 _BT_RC_MEMB(addr, family) = AF_BLUETOOTH; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1309 if (!PyArg_ParseTuple(args, "si", &straddr, |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1310 &_BT_RC_MEMB(addr, channel))) { |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1311 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1312 "wrong format"); |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1313 return 0; |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1314 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1315 if (setbdaddr(straddr, &_BT_RC_MEMB(addr, bdaddr)) < 0) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1316 return 0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1317 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1318 *len_ret = sizeof *addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1319 return 1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1320 } |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1321 case BTPROTO_HCI: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1322 { |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1323 struct sockaddr_hci *addr = (struct sockaddr_hci *)addr_ret; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1324 _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1325 if (!PyArg_ParseTuple(args, "i", &_BT_HCI_MEMB(addr, dev))) { |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1326 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1327 "wrong format"); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1328 return 0; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1329 } |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1330 *len_ret = sizeof *addr; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1331 return 1; |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1332 } |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1333 #if !defined(__FreeBSD__) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1334 case BTPROTO_SCO: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1335 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1336 struct sockaddr_sco *addr; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1337 char *straddr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1338 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1339 addr = (struct sockaddr_sco *)addr_ret; |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1340 _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
1341 if (!PyBytes_Check(args)) { |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1342 PyErr_SetString(socket_error, "getsockaddrarg: " |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1343 "wrong format"); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1344 return 0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1345 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
1346 straddr = PyBytes_AS_STRING(args); |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1347 if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0) |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1348 return 0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1349 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1350 *len_ret = sizeof *addr; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1351 return 1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1352 } |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1353 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1354 default: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1355 PyErr_SetString(socket_error, "getsockaddrarg: unknown Bluetooth protocol"); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1356 return 0; |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1357 } |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1358 } |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1359 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1360 |
|
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
|
1361 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1362 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1363 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1364 struct sockaddr_ll* addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1365 struct ifreq ifr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1366 char *interfaceName; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1367 int protoNumber; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1368 int hatype = 0; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1369 int pkttype = 0; |
|
32611
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1370 char *haddr = NULL; |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1371 unsigned int halen = 0; |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1372 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1373 if (!PyTuple_Check(args)) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1374 PyErr_Format( |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1375 PyExc_TypeError, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1376 "getsockaddrarg: " |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1377 "AF_PACKET address must be tuple, not %.500s", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
1378 Py_TYPE(args)->tp_name); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1379 return 0; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1380 } |
|
43954
092b5306983f
Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents:
43926
diff
changeset
|
1381 if (!PyArg_ParseTuple(args, "si|iiy#", &interfaceName, |
|
32611
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1382 &protoNumber, &pkttype, &hatype, |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1383 &haddr, &halen)) |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1384 return 0; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1385 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
|
1386 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
|
1387 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
|
1388 s->errorhandler(); |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1389 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
|
1390 } |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1391 if (halen > 8) { |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1392 PyErr_SetString(PyExc_ValueError, |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1393 "Hardware address must be 8 bytes or less"); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1394 return 0; |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1395 } |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1396 if (protoNumber < 0 || protoNumber > 0xffff) { |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1397 PyErr_SetString( |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1398 PyExc_OverflowError, |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1399 "getsockaddrarg: protoNumber must be 0-65535."); |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1400 return 0; |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1401 } |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1402 addr = (struct sockaddr_ll*)addr_ret; |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1403 addr->sll_family = AF_PACKET; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1404 addr->sll_protocol = htons((short)protoNumber); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1405 addr->sll_ifindex = ifr.ifr_ifindex; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1406 addr->sll_pkttype = pkttype; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1407 addr->sll_hatype = hatype; |
|
32611
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1408 if (halen != 0) { |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1409 memcpy(&addr->sll_addr, haddr, halen); |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1410 } |
|
8b3288f607e1
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents:
32578
diff
changeset
|
1411 addr->sll_halen = halen; |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1412 *len_ret = sizeof *addr; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1413 return 1; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1414 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1415 #endif |
|
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1416 |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1417 #ifdef HAVE_LINUX_TIPC_H |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1418 case AF_TIPC: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1419 { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1420 unsigned int atype, v1, v2, v3; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1421 unsigned int scope = TIPC_CLUSTER_SCOPE; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1422 struct sockaddr_tipc *addr; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1423 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1424 if (!PyTuple_Check(args)) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1425 PyErr_Format( |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1426 PyExc_TypeError, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1427 "getsockaddrarg: " |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1428 "AF_TIPC address must be tuple, not %.500s", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1429 Py_TYPE(args)->tp_name); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1430 return 0; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1431 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1432 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1433 if (!PyArg_ParseTuple(args, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1434 "IIII|I;Invalid TIPC address format", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1435 &atype, &v1, &v2, &v3, &scope)) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1436 return 0; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1437 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1438 addr = (struct sockaddr_tipc *) addr_ret; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1439 memset(addr, 0, sizeof(struct sockaddr_tipc)); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1440 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1441 addr->family = AF_TIPC; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1442 addr->scope = scope; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1443 addr->addrtype = atype; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1444 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1445 if (atype == TIPC_ADDR_NAMESEQ) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1446 addr->addr.nameseq.type = v1; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1447 addr->addr.nameseq.lower = v2; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1448 addr->addr.nameseq.upper = v3; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1449 } else if (atype == TIPC_ADDR_NAME) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1450 addr->addr.name.name.type = v1; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1451 addr->addr.name.name.instance = v2; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1452 } else if (atype == TIPC_ADDR_ID) { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1453 addr->addr.id.node = v1; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1454 addr->addr.id.ref = v2; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1455 } else { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1456 /* Shouldn't happen */ |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1457 PyErr_SetString(PyExc_TypeError, "Invalid address type"); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1458 return 0; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1459 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1460 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1461 *len_ret = sizeof(*addr); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1462 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1463 return 1; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1464 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1465 #endif |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1466 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1467 /* More cases here... */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1468 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1469 default: |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1470 PyErr_SetString(socket_error, "getsockaddrarg: bad family"); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1471 return 0; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1472 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1473 } |
| 294 | 1474 } |
| 1475 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1476 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1477 /* 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
|
1478 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
|
1479 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
|
1480 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1481 static int |
|
13554
906efc1da247
Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13538
diff
changeset
|
1482 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
|
1483 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1484 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
|
1485 |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
1486 #if defined(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
|
1487 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
|
1488 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1489 *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
|
1490 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1491 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1492 #endif /* AF_UNIX */ |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1493 #if defined(AF_NETLINK) |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1494 case AF_NETLINK: |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1495 { |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1496 *len_ret = sizeof (struct sockaddr_nl); |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1497 return 1; |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1498 } |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
1499 #endif |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1500 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1501 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
|
1502 { |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1503 *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
|
1504 return 1; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1505 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1506 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
1507 #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
|
1508 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1509 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1510 *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
|
1511 return 1; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1512 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1513 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
1514 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1515 #ifdef USE_BLUETOOTH |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1516 case AF_BLUETOOTH: |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1517 { |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1518 switch(s->sock_proto) |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1519 { |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1520 |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1521 case BTPROTO_L2CAP: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1522 *len_ret = sizeof (struct sockaddr_l2); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1523 return 1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1524 case BTPROTO_RFCOMM: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1525 *len_ret = sizeof (struct sockaddr_rc); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1526 return 1; |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1527 case BTPROTO_HCI: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1528 *len_ret = sizeof (struct sockaddr_hci); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
1529 return 1; |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
1530 #if !defined(__FreeBSD__) |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1531 case BTPROTO_SCO: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1532 *len_ret = sizeof (struct sockaddr_sco); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1533 return 1; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1534 #endif |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1535 default: |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1536 PyErr_SetString(socket_error, "getsockaddrlen: " |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1537 "unknown BT protocol"); |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1538 return 0; |
|
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1539 |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1540 } |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1541 } |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1542 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
1543 |
|
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
|
1544 #ifdef HAVE_NETPACKET_PACKET_H |
|
16410
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1545 case AF_PACKET: |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1546 { |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1547 *len_ret = sizeof (struct sockaddr_ll); |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1548 return 1; |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1549 } |
|
3d4a7cd0bf17
SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16400
diff
changeset
|
1550 #endif |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1551 |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1552 #ifdef HAVE_LINUX_TIPC_H |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1553 case AF_TIPC: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1554 { |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1555 *len_ret = sizeof (struct sockaddr_tipc); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1556 return 1; |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1557 } |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1558 #endif |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
1559 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1560 /* 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
|
1561 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1562 default: |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1563 PyErr_SetString(socket_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
|
1564 return 0; |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1565 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1566 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1567 } |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1568 |
|
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1569 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1570 /* s._accept() -> (fd, address) */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1571 |
| 1970 | 1572 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1573 sock_accept(PySocketSockObject *s) |
| 294 | 1574 { |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
1575 sock_addr_t addrbuf; |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
1576 SOCKET_T newfd = INVALID_SOCKET; |
|
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
|
1577 socklen_t addrlen; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1578 PyObject *sock = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1579 PyObject *addr = NULL; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1580 PyObject *res = NULL; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1581 int timeout; |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1582 |
|
900
58a7438c2e7e
Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents:
896
diff
changeset
|
1583 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
|
1584 return NULL; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
1585 memset(&addrbuf, 0, addrlen); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1586 |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1587 if (!IS_SELECTABLE(s)) |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1588 return select_error(); |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1589 |
| 1970 | 1590 Py_BEGIN_ALLOW_THREADS |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1591 timeout = internal_select(s, 0); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1592 if (!timeout) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1593 newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
| 1970 | 1594 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1595 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1596 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1597 PyErr_SetString(socket_timeout, "timed out"); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1598 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1599 } |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1600 |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
1601 if (newfd == INVALID_SOCKET) |
|
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
|
1602 return s->errorhandler(); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1603 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1604 sock = PyLong_FromSocket_t(newfd); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1605 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
|
1606 SOCKETCLOSE(newfd); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1607 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1608 } |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1609 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1610 addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
1611 addrlen, s->sock_proto); |
|
16427
c8ef864ba861
fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16410
diff
changeset
|
1612 if (addr == NULL) |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1613 goto finally; |
|
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1614 |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30646
diff
changeset
|
1615 res = PyTuple_Pack(2, sock, addr); |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1616 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1617 finally: |
| 1970 | 1618 Py_XDECREF(sock); |
| 1619 Py_XDECREF(addr); | |
| 294 | 1620 return res; |
| 1621 } | |
| 1622 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1623 PyDoc_STRVAR(accept_doc, |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1624 "_accept() -> (integer, address info)\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1625 \n\ |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1626 Wait for an incoming connection. Return a new socket file descriptor\n\ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1627 representing the connection, and the address of the client.\n\ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
1628 For IP sockets, the address info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1629 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1630 /* s.setblocking(flag) method. Argument: |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1631 False -- non-blocking mode; same as settimeout(0) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1632 True -- blocking mode; same as settimeout(None) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1633 */ |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1634 |
| 1970 | 1635 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1636 sock_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
|
1637 { |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1638 int block; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1639 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
1640 block = PyLong_AsLong(arg); |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1641 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
|
1642 return NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1643 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1644 s->sock_timeout = block ? -1.0 : 0.0; |
|
23727
9d11f51860dd
I decided to change the interaction between setblocking() and
Guido van Rossum <guido@python.org>
parents:
23725
diff
changeset
|
1645 internal_setblocking(s, block); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1646 |
| 1970 | 1647 Py_INCREF(Py_None); |
| 1648 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
|
1649 } |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1650 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1651 PyDoc_STRVAR(setblocking_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1652 "setblocking(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1653 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1654 Set the socket to blocking (flag is true) or non-blocking (false).\n\ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1655 setblocking(True) is equivalent to settimeout(None);\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1656 setblocking(False) is equivalent to settimeout(0.0)."); |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1657 |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1658 /* s.settimeout(timeout) method. Argument: |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1659 None -- no timeout, blocking mode; same as setblocking(True) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1660 0.0 -- non-blocking mode; same as setblocking(False) |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1661 > 0 -- timeout mode; operations time out after timeout seconds |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1662 < 0 -- illegal; raises an exception |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1663 */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1664 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1665 sock_settimeout(PySocketSockObject *s, PyObject *arg) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1666 { |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1667 double timeout; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1668 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1669 if (arg == Py_None) |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1670 timeout = -1.0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1671 else { |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1672 timeout = PyFloat_AsDouble(arg); |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1673 if (timeout < 0.0) { |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1674 if (!PyErr_Occurred()) |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1675 PyErr_SetString(PyExc_ValueError, |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1676 "Timeout value out of range"); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1677 return NULL; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1678 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1679 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1680 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1681 s->sock_timeout = timeout; |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1682 internal_setblocking(s, timeout < 0.0); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1683 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1684 Py_INCREF(Py_None); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1685 return Py_None; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1686 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1687 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1688 PyDoc_STRVAR(settimeout_doc, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1689 "settimeout(timeout)\n\ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1690 \n\ |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1691 Set a timeout on socket operations. 'timeout' can be a float,\n\ |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1692 giving in seconds, or None. Setting a timeout of None disables\n\ |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
1693 the timeout feature and is equivalent to setblocking(1).\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1694 Setting a timeout of zero is the same as setblocking(0)."); |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1695 |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1696 /* s.gettimeout() method. |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
1697 Returns the timeout associated with a socket. */ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1698 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1699 sock_gettimeout(PySocketSockObject *s) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1700 { |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1701 if (s->sock_timeout < 0.0) { |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1702 Py_INCREF(Py_None); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1703 return Py_None; |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1704 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1705 else |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1706 return PyFloat_FromDouble(s->sock_timeout); |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1707 } |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1708 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1709 PyDoc_STRVAR(gettimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
1710 "gettimeout() -> timeout\n\ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1711 \n\ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1712 Returns the timeout in floating seconds associated with socket \n\ |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1713 operations. A timeout of None indicates that timeouts on socket \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1714 operations are disabled."); |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1792
diff
changeset
|
1715 |
|
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
|
1716 /* 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
|
1717 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
|
1718 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
|
1719 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
|
1720 |
| 1970 | 1721 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1722 sock_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
|
1723 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1724 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1725 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
|
1726 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
|
1727 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
|
1728 int buflen; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1729 int flag; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1730 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1731 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
|
1732 &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
|
1733 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
|
1734 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
|
1735 } |
|
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
|
1736 else { |
| 1970 | 1737 PyErr_Clear(); |
|
43954
092b5306983f
Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents:
43926
diff
changeset
|
1738 if (!PyArg_ParseTuple(args, "iiy#:setsockopt", |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1739 &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
|
1740 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
|
1741 } |
|
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
|
1742 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
|
1743 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
|
1744 return s->errorhandler(); |
| 1970 | 1745 Py_INCREF(Py_None); |
| 1746 return Py_None; | |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1747 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1748 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1749 PyDoc_STRVAR(setsockopt_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1750 "setsockopt(level, option, value)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1751 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1752 Set a socket option. See the Unix manual for level and option.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1753 The value argument can either be an integer or a string."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1754 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1755 |
|
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
|
1756 /* 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
|
1757 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
|
1758 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
|
1759 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
|
1760 |
| 1970 | 1761 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1762 sock_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
|
1763 { |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1764 int level; |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1765 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
|
1766 int res; |
| 1970 | 1767 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
|
1768 socklen_t buflen = 0; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1769 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
1770 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
|
1771 &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
|
1772 return NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
1773 |
|
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
|
1774 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
|
1775 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
|
1776 socklen_t flagsize = sizeof flag; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
1777 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
|
1778 (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
|
1779 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
|
1780 return s->errorhandler(); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
1781 return PyLong_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
|
1782 } |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1783 #ifdef __VMS |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1784 /* socklen_t is unsigned so no negative test is needed, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1785 test buflen == 0 is previously done */ |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1786 if (buflen > 1024) { |
|
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1787 #else |
|
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
|
1788 if (buflen <= 0 || buflen > 1024) { |
|
26550
b9c912e2c3c0
Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25994
diff
changeset
|
1789 #endif |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1790 PyErr_SetString(socket_error, |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
1791 "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
|
1792 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
|
1793 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
1794 buf = PyBytes_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
|
1795 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
|
1796 return NULL; |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
1797 res = getsockopt(s->sock_fd, level, optname, |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
1798 (void *)PyBytes_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
|
1799 if (res < 0) { |
| 1970 | 1800 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
|
1801 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
|
1802 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
1803 _PyBytes_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
|
1804 return buf; |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1805 } |
|
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1806 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1807 PyDoc_STRVAR(getsockopt_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1808 "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
|
1809 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1810 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
|
1811 If a nonzero buffersize argument is given, the return value is a\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1812 string of that length; otherwise it is an integer."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1813 |
|
896
6459e2f21bf6
Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1814 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1815 /* s.bind(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1816 |
| 1970 | 1817 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1818 sock_bind(PySocketSockObject *s, PyObject *addro) |
| 294 | 1819 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1820 sock_addr_t addrbuf; |
| 294 | 1821 int addrlen; |
| 926 | 1822 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
|
1823 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1824 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) |
| 294 | 1825 return NULL; |
| 1970 | 1826 Py_BEGIN_ALLOW_THREADS |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1827 res = bind(s->sock_fd, SAS2SA(&addrbuf), addrlen); |
| 1970 | 1828 Py_END_ALLOW_THREADS |
| 926 | 1829 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
|
1830 return s->errorhandler(); |
| 1970 | 1831 Py_INCREF(Py_None); |
| 1832 return Py_None; | |
| 294 | 1833 } |
| 1834 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1835 PyDoc_STRVAR(bind_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1836 "bind(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1837 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1838 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
|
1839 pair (host, port); the host must refer to the local host. For raw packet\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1840 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
|
1841 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1842 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1843 /* s.close() method. |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1844 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
|
1845 will surely fail. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1846 |
| 1970 | 1847 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1848 sock_close(PySocketSockObject *s) |
| 294 | 1849 { |
|
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
|
1850 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
|
1851 |
|
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
|
1852 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
|
1853 s->sock_fd = -1; |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1854 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
|
1855 (void) SOCKETCLOSE(fd); |
|
4407
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1856 Py_END_ALLOW_THREADS |
|
7ddd8b3f6802
Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents:
3738
diff
changeset
|
1857 } |
| 1970 | 1858 Py_INCREF(Py_None); |
| 1859 return Py_None; | |
| 294 | 1860 } |
| 1861 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1862 PyDoc_STRVAR(close_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1863 "close()\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1864 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1865 Close the socket. It cannot be used after this call."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1866 |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1867 static int |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1868 internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1869 int *timeoutp) |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1870 { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1871 int res, timeout; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1872 |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1873 timeout = 0; |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1874 res = connect(s->sock_fd, addr, addrlen); |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1875 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1876 #ifdef MS_WINDOWS |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1877 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1878 if (s->sock_timeout > 0.0) { |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1879 if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK && |
|
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1880 IS_SELECTABLE(s)) { |
|
27981
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1881 /* This is a mess. Best solution: trust select */ |
|
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1882 fd_set fds; |
|
32909
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1883 fd_set fds_exc; |
|
27981
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1884 struct timeval tv; |
|
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1885 tv.tv_sec = (int)s->sock_timeout; |
|
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1886 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); |
|
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1887 FD_ZERO(&fds); |
|
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1888 FD_SET(s->sock_fd, &fds); |
|
32909
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1889 FD_ZERO(&fds_exc); |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1890 FD_SET(s->sock_fd, &fds_exc); |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1891 res = select(s->sock_fd+1, NULL, &fds, &fds_exc, &tv); |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1892 if (res == 0) { |
|
27981
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1893 res = WSAEWOULDBLOCK; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1894 timeout = 1; |
|
32909
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1895 } else if (res > 0) { |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1896 if (FD_ISSET(s->sock_fd, &fds)) |
|
43384
4e57c36f6d2e
Fixing the spelling of "writeable" to "writable", particularly PyBUF_WRITEABLE.
Sean Reifscheider <jafo@tummy.com>
parents:
43300
diff
changeset
|
1897 /* The socket is in the writable set - this |
|
32909
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1898 means connected */ |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1899 res = 0; |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1900 else { |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1901 /* As per MS docs, we need to call getsockopt() |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1902 to get the underlying error */ |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1903 int res_size = sizeof res; |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1904 /* It must be in the exception set */ |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1905 assert(FD_ISSET(s->sock_fd, &fds_exc)); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1906 if (0 == getsockopt(s->sock_fd, SOL_SOCKET, SO_ERROR, |
|
32909
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1907 (char *)&res, &res_size)) |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1908 /* getsockopt also clears WSAGetLastError, |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1909 so reset it back. */ |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1910 WSASetLastError(res); |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1911 else |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1912 res = WSAGetLastError(); |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1913 } |
|
65319607bed8
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents:
32764
diff
changeset
|
1914 } |
|
27981
eb2a984d3747
The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents:
27861
diff
changeset
|
1915 /* else if (res < 0) an error occurred */ |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1916 } |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1917 } |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1918 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1919 if (res < 0) |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1920 res = WSAGetLastError(); |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1921 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1922 #else |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1923 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1924 if (s->sock_timeout > 0.0) { |
|
44810
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1925 if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) { |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1926 timeout = internal_select(s, 1); |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1927 if (timeout == 0) { |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1928 /* Bug #1019808: in case of an EINPROGRESS, |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1929 use getsockopt(SO_ERROR) to get the real |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1930 error. */ |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1931 socklen_t res_size = sizeof res; |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1932 (void)getsockopt(s->sock_fd, SOL_SOCKET, |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1933 SO_ERROR, &res, &res_size); |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1934 if (res == EISCONN) |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1935 res = 0; |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1936 errno = res; |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1937 } |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1938 else if (timeout == -1) { |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1939 res = errno; /* had error */ |
|
fa6cee14dcba
Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44674
diff
changeset
|
1940 } |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1941 else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1942 res = EWOULDBLOCK; /* timed out */ |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1943 } |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1944 } |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1945 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1946 if (res < 0) |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1947 res = errno; |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1948 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1949 #endif |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1950 *timeoutp = timeout; |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1951 |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1952 return res; |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1953 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1954 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1955 /* s.connect(sockaddr) method */ |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1956 |
| 1970 | 1957 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1958 sock_connect(PySocketSockObject *s, PyObject *addro) |
| 294 | 1959 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1960 sock_addr_t addrbuf; |
| 294 | 1961 int addrlen; |
| 926 | 1962 int res; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1963 int timeout; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1964 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1965 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) |
| 294 | 1966 return NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1967 |
| 1970 | 1968 Py_BEGIN_ALLOW_THREADS |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1969 res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); |
| 1970 | 1970 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
1971 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1972 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1973 PyErr_SetString(socket_timeout, "timed out"); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1974 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1975 } |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
1976 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
|
1977 return s->errorhandler(); |
| 1970 | 1978 Py_INCREF(Py_None); |
| 1979 return Py_None; | |
| 294 | 1980 } |
| 1981 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1982 PyDoc_STRVAR(connect_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1983 "connect(address)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1984 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1985 Connect the socket to a remote address. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
1986 is a pair (host, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
1987 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
1988 |
|
13278
3370edad08ce
Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1989 /* 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
|
1990 |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1991 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
1992 sock_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
|
1993 { |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1994 sock_addr_t addrbuf; |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
1995 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
|
1996 int res; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
1997 int timeout; |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
1998 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1999 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &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
|
2000 return NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2001 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2002 Py_BEGIN_ALLOW_THREADS |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2003 res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout); |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2004 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2005 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2006 /* Signals are not errors (though they may raise exceptions). Adapted |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2007 from PyErr_SetFromErrnoWithFilenameObject(). */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2008 #ifdef EINTR |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2009 if (res == EINTR && PyErr_CheckSignals()) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2010 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2011 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2012 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2013 return PyLong_FromLong((long) res); |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2014 } |
|
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2015 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2016 PyDoc_STRVAR(connect_ex_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
2017 "connect_ex(address) -> errno\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2018 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2019 This is like connect(address), but returns an error code (the errno value)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2020 instead of raising an exception when an error occurs."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2021 |
|
6604
f67a6339ede7
Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
2022 |
|
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
|
2023 /* 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
|
2024 |
| 1970 | 2025 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2026 sock_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
|
2027 { |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
2028 return PyLong_FromSocket_t(s->sock_fd); |
|
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
|
2029 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
900
diff
changeset
|
2030 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2031 PyDoc_STRVAR(fileno_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2032 "fileno() -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2033 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2034 Return the integer file descriptor of the socket."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2035 |
|
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
|
2036 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2037 /* s.getsockname() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2038 |
| 1970 | 2039 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2040 sock_getsockname(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2041 { |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2042 sock_addr_t addrbuf; |
|
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
|
2043 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
|
2044 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
|
2045 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2046 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2047 return NULL; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2048 memset(&addrbuf, 0, addrlen); |
| 1970 | 2049 Py_BEGIN_ALLOW_THREADS |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2050 res = getsockname(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
| 1970 | 2051 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2052 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
|
2053 return s->errorhandler(); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2054 return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
2055 s->sock_proto); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2056 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2057 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2058 PyDoc_STRVAR(getsockname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2059 "getsockname() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2060 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2061 Return the address of the local endpoint. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2062 info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2063 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2064 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2065 #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
|
2066 /* s.getpeername() method */ |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2067 |
| 1970 | 2068 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2069 sock_getpeername(PySocketSockObject *s) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2070 { |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2071 sock_addr_t addrbuf; |
|
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
|
2072 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
|
2073 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
|
2074 |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2075 if (!getsockaddrlen(s, &addrlen)) |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2076 return NULL; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2077 memset(&addrbuf, 0, addrlen); |
| 1970 | 2078 Py_BEGIN_ALLOW_THREADS |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2079 res = getpeername(s->sock_fd, SAS2SA(&addrbuf), &addrlen); |
| 1970 | 2080 Py_END_ALLOW_THREADS |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2081 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
|
2082 return s->errorhandler(); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2083 return makesockaddr(s->sock_fd, SAS2SA(&addrbuf), addrlen, |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
2084 s->sock_proto); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2085 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2086 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2087 PyDoc_STRVAR(getpeername_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2088 "getpeername() -> address info\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2089 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2090 Return the address of the remote endpoint. For IP sockets, the address\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2091 info is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2092 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2093 #endif /* HAVE_GETPEERNAME */ |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2094 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1039
diff
changeset
|
2095 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2096 /* s.listen(n) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2097 |
| 1970 | 2098 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2099 sock_listen(PySocketSockObject *s, PyObject *arg) |
| 294 | 2100 { |
| 2101 int backlog; | |
| 926 | 2102 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
|
2103 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2104 backlog = PyLong_AsLong(arg); |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
2105 if (backlog == -1 && PyErr_Occurred()) |
| 294 | 2106 return NULL; |
| 1970 | 2107 Py_BEGIN_ALLOW_THREADS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2108 if (backlog < 1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2109 backlog = 1; |
| 926 | 2110 res = listen(s->sock_fd, backlog); |
| 1970 | 2111 Py_END_ALLOW_THREADS |
| 926 | 2112 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
|
2113 return s->errorhandler(); |
| 1970 | 2114 Py_INCREF(Py_None); |
| 2115 return Py_None; | |
| 294 | 2116 } |
| 2117 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2118 PyDoc_STRVAR(listen_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2119 "listen(backlog)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2120 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2121 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
|
2122 least 1; it specifies the number of unaccepted connection that the system\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2123 will allow before refusing new connections."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2124 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2125 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2126 /* |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2127 * This is the guts of the recv() and recv_into() methods, which reads into a |
|
40582
67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
2128 * char buffer. If you have any inc/dec ref to do to the objects that contain |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2129 * the buffer, do it in the caller. This function returns the number of bytes |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2130 * succesfully read. If there was an error, it returns -1. Note that it is |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2131 * also possible that we return a number of bytes smaller than the request |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2132 * bytes. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2133 */ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2134 static ssize_t |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2135 sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2136 { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2137 ssize_t outlen = -1; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2138 int timeout; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2139 #ifdef __VMS |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2140 int remaining; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2141 char *read_buf; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2142 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2143 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2144 if (!IS_SELECTABLE(s)) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2145 select_error(); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2146 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2147 } |
|
42439
71304efbc316
Get rid of a bogus assert when recv_into() is called with a zero-length
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2148 if (len == 0) { |
|
71304efbc316
Get rid of a bogus assert when recv_into() is called with a zero-length
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2149 /* If 0 bytes were requested, do nothing. */ |
|
71304efbc316
Get rid of a bogus assert when recv_into() is called with a zero-length
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2150 return 0; |
|
71304efbc316
Get rid of a bogus assert when recv_into() is called with a zero-length
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
2151 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2152 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2153 #ifndef __VMS |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2154 Py_BEGIN_ALLOW_THREADS |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2155 timeout = internal_select(s, 0); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2156 if (!timeout) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2157 outlen = recv(s->sock_fd, cbuf, len, flags); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2158 Py_END_ALLOW_THREADS |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2159 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2160 if (timeout == 1) { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2161 PyErr_SetString(socket_timeout, "timed out"); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2162 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2163 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2164 if (outlen < 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2165 /* Note: the call to errorhandler() ALWAYS indirectly returned |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2166 NULL, so ignore its return value */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2167 s->errorhandler(); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2168 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2169 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2170 #else |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2171 read_buf = cbuf; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2172 remaining = len; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2173 while (remaining != 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2174 unsigned int segment; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2175 int nread = -1; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2176 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2177 segment = remaining /SEGMENT_SIZE; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2178 if (segment != 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2179 segment = SEGMENT_SIZE; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2180 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2181 else { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2182 segment = remaining; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2183 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2184 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2185 Py_BEGIN_ALLOW_THREADS |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2186 timeout = internal_select(s, 0); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2187 if (!timeout) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2188 nread = recv(s->sock_fd, read_buf, segment, flags); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2189 Py_END_ALLOW_THREADS |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2190 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2191 if (timeout == 1) { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2192 PyErr_SetString(socket_timeout, "timed out"); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2193 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2194 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2195 if (nread < 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2196 s->errorhandler(); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2197 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2198 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2199 if (nread != remaining) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2200 read_buf += nread; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2201 break; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2202 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2203 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2204 remaining -= segment; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2205 read_buf += segment; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2206 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2207 outlen = read_buf - cbuf; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2208 #endif /* !__VMS */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2209 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2210 return outlen; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2211 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2212 |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2213 |
|
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
|
2214 /* 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
|
2215 |
| 1970 | 2216 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2217 sock_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
|
2218 { |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2219 int recvlen, flags = 0; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2220 ssize_t outlen; |
| 1970 | 2221 PyObject *buf; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2222 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2223 if (!PyArg_ParseTuple(args, "i|i:recv", &recvlen, &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
|
2224 return NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2225 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2226 if (recvlen < 0) { |
|
21022
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
2227 PyErr_SetString(PyExc_ValueError, |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23807
diff
changeset
|
2228 "negative buffersize in recv"); |
|
21022
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
2229 return NULL; |
|
9f66aaddf8d4
Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents:
20920
diff
changeset
|
2230 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2231 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2232 /* Allocate a new string. */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2233 buf = PyBytes_FromStringAndSize((char *) 0, recvlen); |
| 294 | 2234 if (buf == NULL) |
| 2235 return NULL; | |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2236 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2237 /* Call the guts */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2238 outlen = sock_recv_guts(s, PyBytes_AS_STRING(buf), recvlen, flags); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2239 if (outlen < 0) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2240 /* An error occurred, release the string and return an |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2241 error. */ |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2242 Py_DECREF(buf); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2243 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2244 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2245 if (outlen != recvlen) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2246 /* We did not read as many bytes as we anticipated, resize the |
| 42709 | 2247 string if possible and be successful. */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2248 _PyBytes_Resize(&buf, outlen); |
| 3091 | 2249 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2250 |
| 294 | 2251 return buf; |
| 2252 } | |
| 2253 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2254 PyDoc_STRVAR(recv_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2255 "recv(buffersize[, flags]) -> data\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2256 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2257 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
|
2258 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
|
2259 at least one byte is available or until the remote end is closed. When\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2260 the remote end is closed and all data is read, return the empty string."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2261 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2262 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2263 /* s.recv_into(buffer, [nbytes [,flags]]) method */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2264 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2265 static PyObject* |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2266 sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2267 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2268 static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2269 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2270 int recvlen = 0, flags = 0; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2271 ssize_t readlen; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2272 Py_buffer pbuf; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2273 char *buf; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2274 int buflen; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2275 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2276 /* Get the buffer's memory */ |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2277 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recv_into", kwlist, |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2278 &pbuf, &recvlen, &flags)) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2279 return NULL; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2280 buf = pbuf.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2281 buflen = pbuf.len; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2282 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2283 if (recvlen < 0) { |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2284 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2285 PyErr_SetString(PyExc_ValueError, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2286 "negative buffersize in recv_into"); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2287 return NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2288 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2289 if (recvlen == 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2290 /* If nbytes was not specified, use the buffer's length */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2291 recvlen = buflen; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2292 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2293 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2294 /* Check if the buffer is large enough */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2295 if (buflen < recvlen) { |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2296 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2297 PyErr_SetString(PyExc_ValueError, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2298 "buffer too small for requested bytes"); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2299 return NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2300 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2301 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2302 /* Call the guts */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2303 readlen = sock_recv_guts(s, buf, recvlen, flags); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2304 if (readlen < 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2305 /* Return an error. */ |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2306 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2307 return NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2308 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2309 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2310 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2311 /* Return the number of bytes read. Note that we do not do anything |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2312 special here in the case that readlen < recvlen. */ |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2313 return PyLong_FromSsize_t(readlen); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2314 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2315 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2316 PyDoc_STRVAR(recv_into_doc, |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2317 "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2318 \n\ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2319 A version of recv() that stores its data into a buffer rather than creating \n\ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2320 a new string. Receive up to buffersize bytes from the socket. If buffersize \n\ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2321 is not specified (or 0), receive up to the size available in the given buffer.\n\ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2322 \n\ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2323 See recv() for documentation about the flags."); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2324 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2325 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2326 /* |
|
44349
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2327 * This is the guts of the recvfrom() and recvfrom_into() methods, which reads |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2328 * into a char buffer. If you have any inc/def ref to do to the objects that |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2329 * contain the buffer, do it in the caller. This function returns the number |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2330 * of bytes succesfully read. If there was an error, it returns -1. Note |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2331 * that it is also possible that we return a number of bytes smaller than the |
|
4dc01402d78a
Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44158
diff
changeset
|
2332 * request bytes. |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2333 * |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2334 * 'addr' is a return value for the address object. Note that you must decref |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2335 * it yourself. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2336 */ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2337 static ssize_t |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2338 sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2339 PyObject** addr) |
| 294 | 2340 { |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2341 sock_addr_t addrbuf; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2342 int timeout; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2343 ssize_t n = -1; |
|
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
|
2344 socklen_t addrlen; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2345 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2346 *addr = NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2347 |
|
1295
4773d5c3b5a4
* socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
2348 if (!getsockaddrlen(s, &addrlen)) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2349 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2350 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2351 if (!IS_SELECTABLE(s)) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2352 select_error(); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2353 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2354 } |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2355 |
| 1970 | 2356 Py_BEGIN_ALLOW_THREADS |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2357 memset(&addrbuf, 0, addrlen); |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2358 timeout = internal_select(s, 0); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2359 if (!timeout) { |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
2360 #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
|
2361 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2362 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2363 SAS2SA(&addrbuf), &addrlen); |
|
6718
32f2eda2946c
Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
2364 #else |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2365 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2366 (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
|
2367 #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
|
2368 #else |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2369 n = recvfrom(s->sock_fd, cbuf, len, flags, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2370 SAS2SA(&addrbuf), &addrlen); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2371 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2372 } |
| 1970 | 2373 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2374 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2375 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2376 PyErr_SetString(socket_timeout, "timed out"); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2377 return -1; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2378 } |
| 3091 | 2379 if (n < 0) { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2380 s->errorhandler(); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2381 return -1; |
| 3091 | 2382 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2383 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2384 if (!(*addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf), |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2385 addrlen, s->sock_proto))) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2386 return -1; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2387 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2388 return n; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2389 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2390 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2391 /* s.recvfrom(nbytes [,flags]) method */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2392 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2393 static PyObject * |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2394 sock_recvfrom(PySocketSockObject *s, PyObject *args) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2395 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2396 PyObject *buf = NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2397 PyObject *addr = NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2398 PyObject *ret = NULL; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2399 int recvlen, flags = 0; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2400 ssize_t outlen; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2401 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2402 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags)) |
| 294 | 2403 return NULL; |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2404 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2405 if (recvlen < 0) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2406 PyErr_SetString(PyExc_ValueError, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2407 "negative buffersize in recvfrom"); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2408 return NULL; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2409 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2410 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2411 buf = PyBytes_FromStringAndSize((char *) 0, recvlen); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2412 if (buf == NULL) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2413 return NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2414 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2415 outlen = sock_recvfrom_guts(s, PyBytes_AS_STRING(buf), |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2416 recvlen, flags, &addr); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2417 if (outlen < 0) { |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2418 goto finally; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2419 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2420 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2421 if (outlen != recvlen) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2422 /* We did not read as many bytes as we anticipated, resize the |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2423 string if possible and be succesful. */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
2424 if (_PyBytes_Resize(&buf, outlen) < 0) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2425 /* Oopsy, not so succesful after all. */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2426 goto finally; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2427 } |
|
4871
a7159ba0e45d
Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents:
4783
diff
changeset
|
2428 |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30646
diff
changeset
|
2429 ret = PyTuple_Pack(2, buf, addr); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2430 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2431 finally: |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2432 Py_XDECREF(buf); |
| 1970 | 2433 Py_XDECREF(addr); |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1132
diff
changeset
|
2434 return ret; |
| 294 | 2435 } |
| 2436 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2437 PyDoc_STRVAR(recvfrom_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2438 "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
|
2439 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2440 Like recv(buffersize, flags) but also return the sender's address info."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2441 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2442 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2443 /* s.recvfrom_into(buffer[, nbytes [,flags]]) method */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2444 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2445 static PyObject * |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2446 sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2447 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2448 static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2449 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2450 int recvlen = 0, flags = 0; |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2451 ssize_t readlen; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2452 Py_buffer pbuf; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2453 char *buf; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2454 int buflen; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2455 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2456 PyObject *addr = NULL; |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2457 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2458 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recvfrom_into", |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2459 kwlist, &pbuf, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2460 &recvlen, &flags)) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2461 return NULL; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2462 buf = pbuf.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2463 buflen = pbuf.len; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2464 assert(buf != 0 && buflen > 0); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2465 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2466 if (recvlen < 0) { |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2467 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2468 PyErr_SetString(PyExc_ValueError, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
2469 "negative buffersize in recvfrom_into"); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2470 return NULL; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2471 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2472 if (recvlen == 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2473 /* If nbytes was not specified, use the buffer's length */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2474 recvlen = buflen; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2475 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2476 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2477 readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2478 if (readlen < 0) { |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2479 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2480 /* Return an error */ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2481 Py_XDECREF(addr); |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2482 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2483 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2484 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2485 PyBuffer_Release(&pbuf); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2486 /* Return the number of bytes read and the address. Note that we do |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2487 not do anything special here in the case that readlen < recvlen. */ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2488 return Py_BuildValue("lN", readlen, addr); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2489 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2490 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2491 PyDoc_STRVAR(recvfrom_into_doc, |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2492 "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2493 \n\ |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2494 Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info."); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2495 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2496 |
|
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
|
2497 /* 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
|
2498 |
| 1970 | 2499 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2500 sock_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
|
2501 { |
| 926 | 2502 char *buf; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2503 int len, n = -1, flags = 0, timeout; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2504 Py_buffer pbuf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2505 |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2506 if (!PyArg_ParseTuple(args, "y*|i:send", &pbuf, &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
|
2507 return NULL; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2508 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2509 if (!IS_SELECTABLE(s)) { |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2510 PyBuffer_Release(&pbuf); |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2511 return select_error(); |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2512 } |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2513 buf = pbuf.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2514 len = pbuf.len; |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2515 |
| 1970 | 2516 Py_BEGIN_ALLOW_THREADS |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2517 timeout = internal_select(s, 1); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2518 if (!timeout) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2519 #ifdef __VMS |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2520 n = sendsegmented(s->sock_fd, buf, len, flags); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2521 #else |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2522 n = send(s->sock_fd, buf, len, flags); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2523 #endif |
| 1970 | 2524 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2525 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2526 PyBuffer_Release(&pbuf); |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2527 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2528 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2529 PyErr_SetString(socket_timeout, "timed out"); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2530 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2531 } |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2532 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
|
2533 return s->errorhandler(); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2534 return PyLong_FromLong((long)n); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2535 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2536 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2537 PyDoc_STRVAR(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
|
2538 "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
|
2539 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2540 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
|
2541 argument, see the Unix manual. Return the number of bytes\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2542 sent; this may be less than len(data) if the network is busy."); |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2543 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2544 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2545 /* 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
|
2546 |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2547 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2548 sock_sendall(PySocketSockObject *s, PyObject *args) |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2549 { |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2550 char *buf; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2551 int len, n = -1, flags = 0, timeout; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2552 Py_buffer pbuf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2553 |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2554 if (!PyArg_ParseTuple(args, "y*|i:sendall", &pbuf, &flags)) |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2555 return NULL; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2556 buf = pbuf.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2557 len = pbuf.len; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2558 |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2559 if (!IS_SELECTABLE(s)) { |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2560 PyBuffer_Release(&pbuf); |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2561 return select_error(); |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2562 } |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2563 |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2564 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
|
2565 do { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2566 timeout = internal_select(s, 1); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2567 n = -1; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2568 if (timeout) |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2569 break; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2570 #ifdef __VMS |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2571 n = sendsegmented(s->sock_fd, buf, len, flags); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2572 #else |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2573 n = send(s->sock_fd, buf, len, flags); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2574 #endif |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2575 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
|
2576 break; |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2577 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
|
2578 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
|
2579 } 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
|
2580 Py_END_ALLOW_THREADS |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2581 PyBuffer_Release(&pbuf); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2582 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2583 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2584 PyErr_SetString(socket_timeout, "timed out"); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2585 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2586 } |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2587 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
|
2588 return s->errorhandler(); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2589 |
|
20679
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2590 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
|
2591 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
|
2592 } |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2593 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2594 PyDoc_STRVAR(sendall_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
|
2595 "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
|
2596 \n\ |
|
e89c25ca6b29
Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents:
20661
diff
changeset
|
2597 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
|
2598 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
|
2599 until all data is sent. If an error occurs, it's impossible\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2600 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
|
2601 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2602 |
|
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
|
2603 /* 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
|
2604 |
| 1970 | 2605 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2606 sock_sendto(PySocketSockObject *s, PyObject *args) |
| 294 | 2607 { |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2608 Py_buffer pbuf; |
| 1970 | 2609 PyObject *addro; |
| 926 | 2610 char *buf; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2611 Py_ssize_t len; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2612 sock_addr_t addrbuf; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2613 int addrlen, n = -1, flags, timeout; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2614 |
|
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
|
2615 flags = 0; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2616 if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) { |
| 1970 | 2617 PyErr_Clear(); |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2618 if (!PyArg_ParseTuple(args, "y*iO:sendto", |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2619 &pbuf, &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
|
2620 return NULL; |
| 294 | 2621 } |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2622 buf = pbuf.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2623 len = pbuf.len; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2624 |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2625 if (!IS_SELECTABLE(s)) { |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2626 PyBuffer_Release(&pbuf); |
|
36452
7789cc557e1e
Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
2627 return select_error(); |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2628 } |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2629 |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2630 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) { |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2631 PyBuffer_Release(&pbuf); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2632 return NULL; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2633 } |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2634 |
| 1970 | 2635 Py_BEGIN_ALLOW_THREADS |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2636 timeout = internal_select(s, 1); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2637 if (!timeout) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2638 n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); |
| 1970 | 2639 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2640 |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
2641 PyBuffer_Release(&pbuf); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2642 if (timeout == 1) { |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2643 PyErr_SetString(socket_timeout, "timed out"); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2644 return NULL; |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
2645 } |
| 294 | 2646 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
|
2647 return s->errorhandler(); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2648 return PyLong_FromLong((long)n); |
| 294 | 2649 } |
| 2650 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2651 PyDoc_STRVAR(sendto_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
2652 "sendto(data[, flags], address) -> count\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2653 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2654 Like send(data, flags) but allows specifying the destination address.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2655 For IP sockets, the address is a pair (hostaddr, port)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2656 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2657 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2658 /* s.shutdown(how) method */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2659 |
| 1970 | 2660 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2661 sock_shutdown(PySocketSockObject *s, PyObject *arg) |
| 294 | 2662 { |
| 2663 int how; | |
| 926 | 2664 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
|
2665 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
2666 how = PyLong_AsLong(arg); |
|
20376
061da22f4203
Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20369
diff
changeset
|
2667 if (how == -1 && PyErr_Occurred()) |
| 294 | 2668 return NULL; |
| 1970 | 2669 Py_BEGIN_ALLOW_THREADS |
| 926 | 2670 res = shutdown(s->sock_fd, how); |
| 1970 | 2671 Py_END_ALLOW_THREADS |
| 926 | 2672 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
|
2673 return s->errorhandler(); |
| 1970 | 2674 Py_INCREF(Py_None); |
| 2675 return Py_None; | |
| 294 | 2676 } |
| 2677 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2678 PyDoc_STRVAR(shutdown_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2679 "shutdown(flag)\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2680 \n\ |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
2681 Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\ |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
2682 of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR)."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2683 |
|
47667
b1f4ea4eb555
Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47663
diff
changeset
|
2684 #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2685 static PyObject* |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2686 sock_ioctl(PySocketSockObject *s, PyObject *arg) |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2687 { |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2688 unsigned long cmd = SIO_RCVALL; |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2689 unsigned int option = RCVALL_ON; |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2690 DWORD recv; |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2691 |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2692 if (!PyArg_ParseTuple(arg, "kI:ioctl", &cmd, &option)) |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2693 return NULL; |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2694 |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2695 if (WSAIoctl(s->sock_fd, cmd, &option, sizeof(option), |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2696 NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) { |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2697 return set_error(); |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2698 } |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2699 return PyLong_FromUnsignedLong(recv); |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2700 } |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2701 PyDoc_STRVAR(sock_ioctl_doc, |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2702 "ioctl(cmd, option) -> long\n\ |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2703 \n\ |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2704 Control the socket with WSAIoctl syscall. Currently only socket.SIO_RCVALL\n\ |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2705 is supported as control. Options must be one of the socket.RCVALL_*\n\ |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2706 constants."); |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2707 |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2708 #endif |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2709 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2710 /* List of methods for socket objects */ |
| 294 | 2711 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2712 static PyMethodDef sock_methods[] = { |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
2713 {"_accept", (PyCFunction)sock_accept, METH_NOARGS, |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2714 accept_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2715 {"bind", (PyCFunction)sock_bind, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2716 bind_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2717 {"close", (PyCFunction)sock_close, METH_NOARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2718 close_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2719 {"connect", (PyCFunction)sock_connect, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2720 connect_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2721 {"connect_ex", (PyCFunction)sock_connect_ex, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2722 connect_ex_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2723 {"fileno", (PyCFunction)sock_fileno, METH_NOARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2724 fileno_doc}, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2725 #ifdef HAVE_GETPEERNAME |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2726 {"getpeername", (PyCFunction)sock_getpeername, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2727 METH_NOARGS, getpeername_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2728 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2729 {"getsockname", (PyCFunction)sock_getsockname, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2730 METH_NOARGS, getsockname_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2731 {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2732 getsockopt_doc}, |
|
47667
b1f4ea4eb555
Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47663
diff
changeset
|
2733 #if defined(MS_WINDOWS) && defined(SIO_RCVALL) |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2734 {"ioctl", (PyCFunction)sock_ioctl, METH_VARARGS, |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2735 sock_ioctl_doc}, |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
2736 #endif |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2737 {"listen", (PyCFunction)sock_listen, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2738 listen_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2739 {"recv", (PyCFunction)sock_recv, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2740 recv_doc}, |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2741 {"recv_into", (PyCFunction)sock_recv_into, METH_VARARGS | METH_KEYWORDS, |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2742 recv_into_doc}, |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2743 {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2744 recvfrom_doc}, |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2745 {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS | METH_KEYWORDS, |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
2746 recvfrom_into_doc}, |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2747 {"send", (PyCFunction)sock_send, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2748 send_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2749 {"sendall", (PyCFunction)sock_sendall, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2750 sendall_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2751 {"sendto", (PyCFunction)sock_sendto, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2752 sendto_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2753 {"setblocking", (PyCFunction)sock_setblocking, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2754 setblocking_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2755 {"settimeout", (PyCFunction)sock_settimeout, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2756 settimeout_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2757 {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2758 gettimeout_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2759 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2760 setsockopt_doc}, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2761 {"shutdown", (PyCFunction)sock_shutdown, METH_O, |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2762 shutdown_doc}, |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2763 {NULL, NULL} /* sentinel */ |
| 294 | 2764 }; |
| 2765 | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2766 /* SockObject members */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2767 static PyMemberDef sock_memberlist[] = { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2768 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "the socket family"}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2769 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the socket type"}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2770 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2771 {"timeout", T_DOUBLE, offsetof(PySocketSockObject, sock_timeout), READONLY, "the socket timeout"}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2772 {0}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2773 }; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2774 |
| 1970 | 2775 /* 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
|
2776 First close the file description. */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2777 |
| 294 | 2778 static void |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2779 sock_dealloc(PySocketSockObject *s) |
| 294 | 2780 { |
|
12319
57f34e162e67
In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents:
12229
diff
changeset
|
2781 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
|
2782 (void) SOCKETCLOSE(s->sock_fd); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
2783 Py_TYPE(s)->tp_free((PyObject *)s); |
| 294 | 2784 } |
| 2785 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2786 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2787 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2788 sock_repr(PySocketSockObject *s) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2789 { |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2790 #if SIZEOF_SOCKET_T > SIZEOF_LONG |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2791 if (s->sock_fd > LONG_MAX) { |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2792 /* 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
|
2793 ugly printf formatter for decimal pointer length integer |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2794 printing, only bother if necessary*/ |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2795 PyErr_SetString(PyExc_OverflowError, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2796 "no printf formatter to display " |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2797 "the socket descriptor in decimal"); |
|
13171
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2798 return NULL; |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2799 } |
|
c17fd2ca6659
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12712
diff
changeset
|
2800 #endif |
|
41941
e4ab08039c75
Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents:
41809
diff
changeset
|
2801 return PyUnicode_FromFormat( |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2802 "<socket object, fd=%ld, family=%d, type=%d, proto=%d>", |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2803 (long)s->sock_fd, s->sock_family, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2804 s->sock_type, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2805 s->sock_proto); |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2806 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2807 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
2808 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2809 /* 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
|
2810 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2811 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2812 sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2813 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2814 PyObject *new; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2815 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2816 new = type->tp_alloc(type, 0); |
|
23711
565032b48f50
The tp_new implementation should initialize the errorhandler field,
Guido van Rossum <guido@python.org>
parents:
23295
diff
changeset
|
2817 if (new != NULL) { |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2818 ((PySocketSockObject *)new)->sock_fd = -1; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2819 ((PySocketSockObject *)new)->sock_timeout = -1.0; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2820 ((PySocketSockObject *)new)->errorhandler = &set_error; |
|
23711
565032b48f50
The tp_new implementation should initialize the errorhandler field,
Guido van Rossum <guido@python.org>
parents:
23295
diff
changeset
|
2821 } |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2822 return new; |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2823 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2824 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2825 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2826 /* 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
|
2827 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2828 /*ARGSUSED*/ |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2829 static int |
|
23807
cc65b5bcfc38
work around name clash with OS/2 TCPIP routine sock_init()
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
23736
diff
changeset
|
2830 sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2831 { |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2832 PySocketSockObject *s = (PySocketSockObject *)self; |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2833 PyObject *fdobj = NULL; |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2834 SOCKET_T fd = INVALID_SOCKET; |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2835 int family = AF_INET, type = SOCK_STREAM, proto = 0; |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2836 static char *keywords[] = {"family", "type", "proto", "fileno", 0}; |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2837 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2838 if (!PyArg_ParseTupleAndKeywords(args, kwds, |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2839 "|iiiO:socket", keywords, |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2840 &family, &type, &proto, &fdobj)) |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2841 return -1; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2842 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
2843 if (fdobj != NULL && fdobj != Py_None) { |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
2844 fd = PyLong_AsSocket_t(fdobj); |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2845 if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2846 return -1; |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2847 if (fd == INVALID_SOCKET) { |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2848 PyErr_SetString(PyExc_ValueError, |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2849 "can't use invalid socket value"); |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2850 return -1; |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2851 } |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2852 } |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2853 else { |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2854 Py_BEGIN_ALLOW_THREADS |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2855 fd = socket(family, type, proto); |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2856 Py_END_ALLOW_THREADS |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2857 |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2858 if (fd == INVALID_SOCKET) { |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2859 set_error(); |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2860 return -1; |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
2861 } |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2862 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2863 init_sockobject(s, fd, family, type, proto); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2864 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2865 return 0; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2866 |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2867 } |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2868 |
|
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2869 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2870 /* 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
|
2871 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2872 static PyTypeObject sock_type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42084
diff
changeset
|
2873 PyVarObject_HEAD_INIT(0, 0) /* Must fill in type value later */ |
|
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
|
2874 "_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
|
2875 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
|
2876 0, /* tp_itemsize */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2877 (destructor)sock_dealloc, /* tp_dealloc */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2878 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
|
2879 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
|
2880 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50812
diff
changeset
|
2881 0, /* tp_reserved */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2882 (reprfunc)sock_repr, /* tp_repr */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2883 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
|
2884 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
|
2885 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
|
2886 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
|
2887 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
|
2888 0, /* tp_str */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27019
diff
changeset
|
2889 PyObject_GenericGetAttr, /* 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
|
2890 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
|
2891 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
|
2892 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2893 sock_doc, /* tp_doc */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2894 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
|
2895 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
|
2896 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
|
2897 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
|
2898 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
|
2899 0, /* tp_iternext */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2900 sock_methods, /* tp_methods */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
2901 sock_memberlist, /* tp_members */ |
|
20727
abd71e89840f
Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents:
20679
diff
changeset
|
2902 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
|
2903 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
|
2904 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
|
2905 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
|
2906 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
|
2907 0, /* tp_dictoffset */ |
|
23807
cc65b5bcfc38
work around name clash with OS/2 TCPIP routine sock_init()
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
23736
diff
changeset
|
2908 sock_initobj, /* tp_init */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27019
diff
changeset
|
2909 PyType_GenericAlloc, /* tp_alloc */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2910 sock_new, /* tp_new */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27019
diff
changeset
|
2911 PyObject_Del, /* tp_free */ |
| 294 | 2912 }; |
| 2913 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2914 |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2915 /* Python interface to gethostname(). */ |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2916 |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2917 /*ARGSUSED*/ |
| 1970 | 2918 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2919 socket_gethostname(PyObject *self, PyObject *unused) |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2920 { |
|
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2921 char buf[1024]; |
| 926 | 2922 int res; |
| 1970 | 2923 Py_BEGIN_ALLOW_THREADS |
| 926 | 2924 res = gethostname(buf, (int) sizeof buf - 1); |
| 1970 | 2925 Py_END_ALLOW_THREADS |
| 926 | 2926 if (res < 0) |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2927 return set_error(); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2928 buf[sizeof buf - 1] = '\0'; |
| 42596 | 2929 return PyUnicode_FromString(buf); |
|
324
a81020d505bf
Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents:
309
diff
changeset
|
2930 } |
| 926 | 2931 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2932 PyDoc_STRVAR(gethostname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2933 "gethostname() -> string\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2934 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2935 Return the current host name."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2936 |
| 926 | 2937 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2938 /* Python interface to gethostbyname(name). */ |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2939 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2940 /*ARGSUSED*/ |
| 1970 | 2941 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2942 socket_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
|
2943 { |
|
1792
a584b4bbbc59
Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents:
1760
diff
changeset
|
2944 char *name; |
|
35551
57f630a9de26
- Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents:
35452
diff
changeset
|
2945 sock_addr_t addrbuf; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2946 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
2947 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
|
2948 return NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2949 if (setipaddr(name, SAS2SA(&addrbuf), sizeof(addrbuf), AF_INET) < 0) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2950 return NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
2951 return makeipaddr(SAS2SA(&addrbuf), sizeof(struct sockaddr_in)); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2952 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
2953 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2954 PyDoc_STRVAR(gethostbyname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2955 "gethostbyname(host) -> address\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2956 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
2957 Return the IP address (a string of the form '255.255.255.255') for a host."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2958 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
2959 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2960 /* 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
|
2961 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2962 static PyObject * |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2963 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
|
2964 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2965 char **pch; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2966 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
|
2967 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
|
2968 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
|
2969 PyObject *tmp; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2970 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2971 if (h == NULL) { |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
2972 /* Let's get real error message to return */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2973 set_herror(h_errno); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2974 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2975 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2976 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2977 if (h->h_addrtype != af) { |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2978 /* Let's get real error message to return */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
2979 PyErr_SetString(socket_error, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
2980 (char *)strerror(EAFNOSUPPORT)); |
|
45865
e0e8bef0d5ec
Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44905
diff
changeset
|
2981 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2982 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
2983 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2984 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2985 switch (af) { |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2986 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2987 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2988 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
|
2989 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2990 break; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2991 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
2992 #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
|
2993 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2994 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
|
2995 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2996 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2997 #endif |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
2998 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
2999 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3000 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3001 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
|
3002 goto err; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3003 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3004 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
|
3005 goto err; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3006 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3007 /* SF #1511317: h_aliases can be NULL */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3008 if (h->h_aliases) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3009 for (pch = h->h_aliases; *pch != NULL; pch++) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3010 int status; |
| 42596 | 3011 tmp = PyUnicode_FromString(*pch); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3012 if (tmp == NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3013 goto err; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3014 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3015 status = PyList_Append(name_list, tmp); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3016 Py_DECREF(tmp); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3017 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3018 if (status) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3019 goto err; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
3020 } |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3021 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3022 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3023 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
|
3024 int status; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3025 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3026 switch (af) { |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3027 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3028 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3029 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3030 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
|
3031 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
|
3032 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
|
3033 #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
|
3034 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
|
3035 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3036 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
|
3037 tmp = makeipaddr((struct sockaddr *)&sin, sizeof(sin)); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3038 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3039 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
|
3040 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
|
3041 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3042 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3043 |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3044 #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
|
3045 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3046 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3047 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
|
3048 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
|
3049 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
|
3050 #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
|
3051 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
|
3052 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3053 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
|
3054 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
|
3055 sizeof(sin6)); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3056 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3057 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
|
3058 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
|
3059 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3060 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3061 #endif |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3062 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3063 default: /* can't happen */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3064 PyErr_SetString(socket_error, |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3065 "unsupported address family"); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3066 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3067 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3068 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3069 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
|
3070 goto err; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3071 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3072 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
|
3073 Py_DECREF(tmp); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3074 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3075 if (status) |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3076 goto err; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3077 } |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3078 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3079 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3080 |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3081 err: |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3082 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
|
3083 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
|
3084 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
|
3085 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3086 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3087 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3088 /* 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
|
3089 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3090 /*ARGSUSED*/ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3091 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3092 socket_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
|
3093 { |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3094 char *name; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3095 struct hostent *h; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3096 #ifdef ENABLE_IPV6 |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3097 struct sockaddr_storage addr; |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3098 #else |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3099 struct sockaddr_in addr; |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
28925
diff
changeset
|
3100 #endif |
|
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
|
3101 struct sockaddr *sa; |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
3102 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
|
3103 #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
|
3104 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
|
3105 #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
|
3106 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
|
3107 #else |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3108 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
|
3109 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
|
3110 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3111 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3112 #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
|
3113 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3114 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3115 #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
|
3116 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
3117 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
|
3118 return NULL; |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
3119 if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), AF_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
|
3120 return NULL; |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3121 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
|
3122 #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
|
3123 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG) |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3124 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3125 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3126 #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
|
3127 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
|
3128 #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
|
3129 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
|
3130 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
|
3131 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
|
3132 #endif |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3133 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3134 #ifdef USE_GETHOSTBYNAME_LOCK |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3135 PyThread_acquire_lock(netdb_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
|
3136 #endif |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3137 h = gethostbyname(name); |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
3138 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
3139 Py_END_ALLOW_THREADS |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3140 /* Some C libraries would require addr.__ss_family instead of |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3141 addr.ss_family. |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3142 Therefore, we cast the sockaddr_storage into sockaddr to |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3143 access sa_family. */ |
|
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
|
3144 sa = (struct sockaddr*)&addr; |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23714
diff
changeset
|
3145 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3146 sa->sa_family); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3147 #ifdef USE_GETHOSTBYNAME_LOCK |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3148 PyThread_release_lock(netdb_lock); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3149 #endif |
|
10441
9ba5dffccb1b
Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents:
10401
diff
changeset
|
3150 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
|
3151 } |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3152 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3153 PyDoc_STRVAR(ghbn_ex_doc, |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3154 "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
|
3155 \n\ |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3156 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3157 for a host. The host argument is a string giving a host name or IP number."); |
|
8821
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3158 |
|
a1c16a3fa7db
Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents:
8631
diff
changeset
|
3159 |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3160 /* Python interface to gethostbyaddr(IP). */ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3161 |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3162 /*ARGSUSED*/ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3163 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3164 socket_gethostbyaddr(PyObject *self, PyObject *args) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3165 { |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3166 #ifdef ENABLE_IPV6 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3167 struct sockaddr_storage addr; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3168 #else |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
3169 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
|
3170 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3171 struct sockaddr *sa = (struct sockaddr *)&addr; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3172 char *ip_num; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3173 struct hostent *h; |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3174 PyObject *ret; |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3175 #ifdef HAVE_GETHOSTBYNAME_R |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3176 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
|
3177 #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
|
3178 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
|
3179 #else |
|
50812
a04b1c7167ba
Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48683
diff
changeset
|
3180 /* glibcs up to 2.10 assume that the buf argument to |
|
a04b1c7167ba
Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48683
diff
changeset
|
3181 gethostbyaddr_r is 8-byte aligned, which at least llvm-gcc |
|
a04b1c7167ba
Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48683
diff
changeset
|
3182 does not ensure. The attribute below instructs the compiler |
|
a04b1c7167ba
Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48683
diff
changeset
|
3183 to maintain this alignment. */ |
|
a04b1c7167ba
Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48683
diff
changeset
|
3184 char buf[16384] Py_ALIGNED(8); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3185 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
|
3186 int errnop; |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3187 #endif |
|
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3188 #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
|
3189 int result; |
|
f81db738abd9
Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
3190 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3191 #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
|
3192 char *ap; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3193 int al; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3194 int af; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3195 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
3196 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
|
3197 return NULL; |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
3198 af = AF_UNSPEC; |
|
24411
8e266d0acd10
Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents:
24380
diff
changeset
|
3199 if (setipaddr(ip_num, sa, sizeof(addr), af) < 0) |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3200 return NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3201 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
|
3202 ap = NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3203 al = 0; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3204 switch (af) { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3205 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3206 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
|
3207 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
|
3208 break; |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3209 #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
|
3210 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3211 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
|
3212 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
|
3213 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3214 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3215 default: |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3216 PyErr_SetString(socket_error, "unsupported address family"); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3217 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3218 } |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3219 Py_BEGIN_ALLOW_THREADS |
|
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3220 #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
|
3221 #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
|
3222 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
|
3223 &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
|
3224 &h, &errnop); |
|
10453
5b54fa775e55
Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents:
10442
diff
changeset
|
3225 #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
|
3226 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
|
3227 &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
|
3228 #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
|
3229 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
|
3230 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
|
3231 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
|
3232 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3233 #else /* not HAVE_GETHOSTBYNAME_R */ |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3234 #ifdef USE_GETHOSTBYNAME_LOCK |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3235 PyThread_acquire_lock(netdb_lock, 1); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3236 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3237 h = gethostbyaddr(ap, al, af); |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3238 #endif /* HAVE_GETHOSTBYNAME_R */ |
|
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3239 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
|
3240 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
|
3241 #ifdef USE_GETHOSTBYNAME_LOCK |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3242 PyThread_release_lock(netdb_lock); |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
3243 #endif |
|
10442
9184c9e108f9
Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents:
10441
diff
changeset
|
3244 return ret; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3245 } |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1970
diff
changeset
|
3246 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3247 PyDoc_STRVAR(gethostbyaddr_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3248 "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
|
3249 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3250 Return the true host name, a list of aliases, and a list of IP addresses,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3251 for a host. The host argument is a string giving a host name or IP number."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3252 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3253 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3254 /* Python interface to getservbyname(name). |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3255 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
|
3256 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
|
3257 |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3258 /*ARGSUSED*/ |
| 1970 | 3259 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3260 socket_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
|
3261 { |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3262 char *name, *proto=NULL; |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3263 struct servent *sp; |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3264 if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)) |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3265 return NULL; |
| 1970 | 3266 Py_BEGIN_ALLOW_THREADS |
| 926 | 3267 sp = getservbyname(name, proto); |
| 1970 | 3268 Py_END_ALLOW_THREADS |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3269 if (sp == NULL) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3270 PyErr_SetString(socket_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
|
3271 return NULL; |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3272 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
3273 return PyLong_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
|
3274 } |
|
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3275 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3276 PyDoc_STRVAR(getservbyname_doc, |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3277 "getservbyname(servicename[, protocolname]) -> integer\n\ |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3278 \n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3279 Return a port number from a service name and protocol name.\n\ |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3280 The optional protocol name, if given, should be 'tcp' or 'udp',\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3281 otherwise any protocol will match."); |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3282 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3283 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3284 /* Python interface to getservbyport(port). |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3285 This only returns the service name, since the other info is already |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3286 known or not useful (like the list of aliases). */ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3287 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3288 /*ARGSUSED*/ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3289 static PyObject * |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3290 socket_getservbyport(PyObject *self, PyObject *args) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3291 { |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3292 int port; |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3293 char *proto=NULL; |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3294 struct servent *sp; |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3295 if (!PyArg_ParseTuple(args, "i|s:getservbyport", &port, &proto)) |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3296 return NULL; |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3297 if (port < 0 || port > 0xffff) { |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3298 PyErr_SetString( |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3299 PyExc_OverflowError, |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3300 "getservbyport: port must be 0-65535."); |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3301 return NULL; |
|
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3302 } |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3303 Py_BEGIN_ALLOW_THREADS |
|
51384
7a0525613644
Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
3304 sp = getservbyport(htons((short)port), proto); |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3305 Py_END_ALLOW_THREADS |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3306 if (sp == NULL) { |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3307 PyErr_SetString(socket_error, "port/proto not found"); |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3308 return NULL; |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3309 } |
| 42596 | 3310 return PyUnicode_FromString(sp->s_name); |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3311 } |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3312 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3313 PyDoc_STRVAR(getservbyport_doc, |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3314 "getservbyport(port[, protocolname]) -> string\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3315 \n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3316 Return the service name from a port number and protocol name.\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3317 The optional protocol name, if given, should be 'tcp' or 'udp',\n\ |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
3318 otherwise any protocol will match."); |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
3319 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3320 /* Python interface to getprotobyname(name). |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3321 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
|
3322 already known or not useful (like the list of aliases). */ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3323 |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3324 /*ARGSUSED*/ |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3325 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3326 socket_getprotobyname(PyObject *self, PyObject *args) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3327 { |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3328 char *name; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3329 struct protoent *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
|
3330 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name)) |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3331 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3332 Py_BEGIN_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3333 sp = getprotobyname(name); |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3334 Py_END_ALLOW_THREADS |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3335 if (sp == NULL) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3336 PyErr_SetString(socket_error, "protocol not found"); |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3337 return NULL; |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3338 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
3339 return PyLong_FromLong((long) sp->p_proto); |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3340 } |
|
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3341 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3342 PyDoc_STRVAR(getprotobyname_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3343 "getprotobyname(name) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3344 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3345 Return the protocol number for the named protocol. (Rarely used.)"); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3346 |
|
4782
2426a220664b
Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4651
diff
changeset
|
3347 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3348 #ifndef NO_DUP |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3349 /* dup() function for socket fds */ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3350 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3351 static PyObject * |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3352 socket_dup(PyObject *self, PyObject *fdobj) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3353 { |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3354 SOCKET_T fd, newfd; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3355 PyObject *newfdobj; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3356 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3357 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3358 fd = PyLong_AsSocket_t(fdobj); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3359 if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3360 return NULL; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3361 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3362 newfd = dup_socket(fd); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3363 if (newfd == INVALID_SOCKET) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3364 return set_error(); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3365 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3366 newfdobj = PyLong_FromSocket_t(newfd); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3367 if (newfdobj == NULL) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3368 SOCKETCLOSE(newfd); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3369 return newfdobj; |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3370 } |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3371 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3372 PyDoc_STRVAR(dup_doc, |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3373 "dup(integer) -> integer\n\ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3374 \n\ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3375 Duplicate an integer socket file descriptor. This is like os.dup(), but for\n\ |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3376 sockets; on some platforms os.dup() won't work for socket file descriptors."); |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3377 #endif |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3378 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
3379 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3380 #ifdef HAVE_SOCKETPAIR |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3381 /* Create a pair of sockets using the socketpair() function. |
|
33239
fb9869044bba
Updated the socketpair() docstring and documentation to explain that the
Dave Cole <djc@object-craft.com.au>
parents:
33238
diff
changeset
|
3382 Arguments as for socket() except the default family is AF_UNIX if |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33260
diff
changeset
|
3383 defined on the platform; otherwise, the default is AF_INET. */ |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3384 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3385 /*ARGSUSED*/ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3386 static PyObject * |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3387 socket_socketpair(PyObject *self, PyObject *args) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3388 { |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3389 PySocketSockObject *s0 = NULL, *s1 = NULL; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3390 SOCKET_T sv[2]; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3391 int family, type = SOCK_STREAM, proto = 0; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3392 PyObject *res = NULL; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3393 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3394 #if defined(AF_UNIX) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3395 family = AF_UNIX; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3396 #else |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3397 family = AF_INET; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3398 #endif |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3399 if (!PyArg_ParseTuple(args, "|iii:socketpair", |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3400 &family, &type, &proto)) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3401 return NULL; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3402 /* Create a pair of socket fds */ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3403 if (socketpair(family, type, proto, sv) < 0) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3404 return set_error(); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3405 s0 = new_sockobject(sv[0], family, type, proto); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3406 if (s0 == NULL) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3407 goto finally; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3408 s1 = new_sockobject(sv[1], family, type, proto); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3409 if (s1 == NULL) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3410 goto finally; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3411 res = PyTuple_Pack(2, s0, s1); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3412 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3413 finally: |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3414 if (res == NULL) { |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3415 if (s0 == NULL) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3416 SOCKETCLOSE(sv[0]); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3417 if (s1 == NULL) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3418 SOCKETCLOSE(sv[1]); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3419 } |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3420 Py_XDECREF(s0); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3421 Py_XDECREF(s1); |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3422 return res; |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3423 } |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3424 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3425 PyDoc_STRVAR(socketpair_doc, |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3426 "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3427 \n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3428 Create a pair of socket objects from the sockets returned by the platform\n\ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3429 socketpair() function.\n\ |
|
33239
fb9869044bba
Updated the socketpair() docstring and documentation to explain that the
Dave Cole <djc@object-craft.com.au>
parents:
33238
diff
changeset
|
3430 The arguments are the same as for socket() except the default family is\n\ |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33260
diff
changeset
|
3431 AF_UNIX if defined on the platform; otherwise, the default is AF_INET."); |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3432 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3433 #endif /* HAVE_SOCKETPAIR */ |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3434 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
3435 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3436 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3437 socket_ntohs(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3438 { |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3439 int x1, x2; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3440 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
3441 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
|
3442 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3443 } |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3444 if (x1 < 0) { |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3445 PyErr_SetString(PyExc_OverflowError, |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3446 "can't convert negative number to unsigned long"); |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3447 return NULL; |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3448 } |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3449 x2 = (unsigned int)ntohs((unsigned short)x1); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
3450 return PyLong_FromLong(x2); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3451 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3452 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3453 PyDoc_STRVAR(ntohs_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3454 "ntohs(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3455 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3456 Convert a 16-bit integer from network to host byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3457 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3458 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3459 static PyObject * |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3460 socket_ntohl(PyObject *self, PyObject *arg) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3461 { |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3462 unsigned long x; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3463 |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40582
diff
changeset
|
3464 if (PyLong_Check(arg)) { |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3465 x = PyLong_AsUnsignedLong(arg); |
|
24380
672843ee4b61
Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
3466 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
672843ee4b61
Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
3467 return NULL; |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3468 #if SIZEOF_LONG > 4 |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3469 { |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3470 unsigned long y; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3471 /* only want the trailing 32 bits */ |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3472 y = x & 0xFFFFFFFFUL; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3473 if (y ^ x) |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3474 return PyErr_Format(PyExc_OverflowError, |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3475 "long int larger than 32 bits"); |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3476 x = y; |
|
24619
b64db550972c
internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
3477 } |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3478 #endif |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3479 } |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3480 else |
|
24619
b64db550972c
internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
3481 return PyErr_Format(PyExc_TypeError, |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3482 "expected int/long, %s found", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
3483 Py_TYPE(arg)->tp_name); |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3484 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3485 return NULL; |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3486 return PyLong_FromUnsignedLong(ntohl(x)); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3487 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3488 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3489 PyDoc_STRVAR(ntohl_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3490 "ntohl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3491 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3492 Convert a 32-bit integer from network to host byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3493 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3494 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3495 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3496 socket_htons(PyObject *self, PyObject *args) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3497 { |
|
31207
f388e83f8e43
Fix erroneus argument parsing of socket.htons() on 64bit big endian
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31027
diff
changeset
|
3498 int x1, x2; |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3499 |
|
12050
b90880c0e5eb
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents:
11937
diff
changeset
|
3500 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
|
3501 return NULL; |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3502 } |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3503 if (x1 < 0) { |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3504 PyErr_SetString(PyExc_OverflowError, |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3505 "can't convert negative number to unsigned long"); |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3506 return NULL; |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3507 } |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3508 x2 = (unsigned int)htons((unsigned short)x1); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
3509 return PyLong_FromLong(x2); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3510 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3511 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3512 PyDoc_STRVAR(htons_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3513 "htons(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3514 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3515 Convert a 16-bit integer from host to network byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3516 |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3517 |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3518 static PyObject * |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3519 socket_htonl(PyObject *self, PyObject *arg) |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3520 { |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3521 unsigned long x; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3522 |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40582
diff
changeset
|
3523 if (PyLong_Check(arg)) { |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3524 x = PyLong_AsUnsignedLong(arg); |
|
24380
672843ee4b61
Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
3525 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
672843ee4b61
Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
3526 return NULL; |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3527 #if SIZEOF_LONG > 4 |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3528 { |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3529 unsigned long y; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3530 /* only want the trailing 32 bits */ |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3531 y = x & 0xFFFFFFFFUL; |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3532 if (y ^ x) |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3533 return PyErr_Format(PyExc_OverflowError, |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3534 "long int larger than 32 bits"); |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3535 x = y; |
|
24619
b64db550972c
internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
3536 } |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3537 #endif |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3538 } |
|
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3539 else |
|
24619
b64db550972c
internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents:
24471
diff
changeset
|
3540 return PyErr_Format(PyExc_TypeError, |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
3541 "expected int/long, %s found", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
3542 Py_TYPE(arg)->tp_name); |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40626
diff
changeset
|
3543 return PyLong_FromUnsignedLong(htonl((unsigned long)x)); |
|
3673
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3544 } |
|
f6ace61c3dfe
ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents:
3672
diff
changeset
|
3545 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3546 PyDoc_STRVAR(htonl_doc, |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3547 "htonl(integer) -> integer\n\ |
|
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3548 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3549 Convert a 32-bit integer from host to network byte order."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3550 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
3551 /* socket.inet_aton() and socket.inet_ntoa() functions. */ |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3552 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3553 PyDoc_STRVAR(inet_aton_doc, |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
3554 "inet_aton(string) -> bytes giving packed 32-bit IP representation\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
|
3555 \n\ |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
3556 Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3557 binary format used in low-level network functions."); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3558 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3559 static PyObject* |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3560 socket_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
|
3561 { |
|
11268
3fe8d13328c8
It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents:
11219
diff
changeset
|
3562 #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
|
3563 #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
|
3564 #endif |
|
27858
9453d8cdd01e
Ummm, try to get it right this time
Neal Norwitz <nnorwitz@gmail.com>
parents:
27857
diff
changeset
|
3565 #ifdef HAVE_INET_ATON |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3566 struct in_addr buf; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3567 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3568 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3569 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK) |
|
51579
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
3570 #if (SIZEOF_INT != 4) |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
3571 #error "Not sure if in_addr_t exists and int is not 32-bits." |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
3572 #endif |
|
27861
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3573 /* Have to use inet_addr() instead */ |
|
51579
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
3574 unsigned int packed_addr; |
|
27861
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3575 #endif |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3576 char *ip_addr; |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3577 |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3578 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
|
3579 return NULL; |
|
27861
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3580 |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3581 |
|
f8440bb8ede5
socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents:
27858
diff
changeset
|
3582 #ifdef HAVE_INET_ATON |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3583 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3584 #ifdef USE_INET_ATON_WEAKLINK |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3585 if (inet_aton != NULL) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3586 #endif |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3587 if (inet_aton(ip_addr, &buf)) |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3588 return PyBytes_FromStringAndSize((char *)(&buf), |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3589 sizeof(buf)); |
|
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3590 |
|
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3591 PyErr_SetString(socket_error, |
|
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3592 "illegal IP address string passed to inet_aton"); |
|
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3593 return NULL; |
|
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3594 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3595 #ifdef USE_INET_ATON_WEAKLINK |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3596 } else { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3597 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3598 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3599 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3600 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3601 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3602 |
|
35452
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3603 /* special-case this address as inet_addr might return INADDR_NONE |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3604 * for this */ |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3605 if (strcmp(ip_addr, "255.255.255.255") == 0) { |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3606 packed_addr = 0xFFFFFFFF; |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3607 } else { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3608 |
|
35452
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3609 packed_addr = inet_addr(ip_addr); |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3610 |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3611 if (packed_addr == INADDR_NONE) { /* invalid address */ |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3612 PyErr_SetString(socket_error, |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3613 "illegal IP address string passed to inet_aton"); |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3614 return NULL; |
|
59a63b09a4c2
backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
33928
diff
changeset
|
3615 } |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
3616 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3617 return PyBytes_FromStringAndSize((char *) &packed_addr, |
|
43954
092b5306983f
Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents:
43926
diff
changeset
|
3618 sizeof(packed_addr)); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3619 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3620 #ifdef USE_INET_ATON_WEAKLINK |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3621 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3622 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3623 |
|
27854
81afca747caa
Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents:
27558
diff
changeset
|
3624 #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
|
3625 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3626 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3627 PyDoc_STRVAR(inet_ntoa_doc, |
| 11937 | 3628 "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
|
3629 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3630 Convert an IP address from 32-bit packed binary format to string format"); |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3631 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3632 static PyObject* |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3633 socket_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
|
3634 { |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3635 char *packed_str; |
|
11219
2d7331f4dfe3
Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents:
11217
diff
changeset
|
3636 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
|
3637 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
|
3638 |
| 42596 | 3639 if (!PyArg_ParseTuple(args, "y#: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
|
3640 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
|
3641 } |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
3642 |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3643 if (addr_len != sizeof(packed_addr)) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3644 PyErr_SetString(socket_error, |
|
11217
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3645 "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
|
3646 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
|
3647 } |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3648 |
|
f406e78ec10b
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents:
11182
diff
changeset
|
3649 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
|
3650 |
| 42596 | 3651 return PyUnicode_FromString(inet_ntoa(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
|
3652 } |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
3653 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3654 #ifdef HAVE_INET_PTON |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3655 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3656 PyDoc_STRVAR(inet_pton_doc, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3657 "inet_pton(af, ip) -> packed IP address string\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3658 \n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3659 Convert an IP address from string format to a packed string suitable\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3660 for use with low-level network functions."); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3661 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3662 static PyObject * |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3663 socket_inet_pton(PyObject *self, PyObject *args) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3664 { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3665 int af; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3666 char* ip; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3667 int retval; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3668 #ifdef ENABLE_IPV6 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3669 char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))]; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3670 #else |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3671 char packed[sizeof(struct in_addr)]; |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3672 #endif |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3673 if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3674 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3675 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3676 |
|
32183
a799b0d1c568
Patch #924294: Do not check for AF_INET6 if it is not defined.
Martin v. Löwis <martin@v.loewis.de>
parents:
32149
diff
changeset
|
3677 #if !defined(ENABLE_IPV6) && defined(AF_INET6) |
|
30061
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3678 if(af == AF_INET6) { |
|
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3679 PyErr_SetString(socket_error, |
|
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3680 "can't use AF_INET6, IPv6 is disabled"); |
|
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3681 return NULL; |
|
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3682 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3683 #endif |
|
30061
354c7ee438bf
Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29929
diff
changeset
|
3684 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3685 retval = inet_pton(af, ip, packed); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3686 if (retval < 0) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3687 PyErr_SetFromErrno(socket_error); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3688 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3689 } else if (retval == 0) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3690 PyErr_SetString(socket_error, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3691 "illegal IP address string passed to inet_pton"); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3692 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3693 } else if (af == AF_INET) { |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3694 return PyBytes_FromStringAndSize(packed, |
|
43954
092b5306983f
Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents:
43926
diff
changeset
|
3695 sizeof(struct in_addr)); |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3696 #ifdef ENABLE_IPV6 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3697 } else if (af == AF_INET6) { |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3698 return PyBytes_FromStringAndSize(packed, |
|
43954
092b5306983f
Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents:
43926
diff
changeset
|
3699 sizeof(struct in6_addr)); |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3700 #endif |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3701 } else { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3702 PyErr_SetString(socket_error, "unknown address family"); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3703 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3704 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3705 } |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3706 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3707 PyDoc_STRVAR(inet_ntop_doc, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3708 "inet_ntop(af, packed_ip) -> string formatted IP address\n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3709 \n\ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3710 Convert a packed IP address of the given family to string format."); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3711 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3712 static PyObject * |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3713 socket_inet_ntop(PyObject *self, PyObject *args) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3714 { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3715 int af; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3716 char* packed; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3717 int len; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3718 const char* retval; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3719 #ifdef ENABLE_IPV6 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3720 char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3721 #else |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3722 char ip[INET_ADDRSTRLEN + 1]; |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3723 #endif |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3724 |
| 42596 | 3725 /* Guarantee NUL-termination for PyUnicode_FromString() below */ |
|
33928
0d4ecc31cfd8
Fix apparently trivial buffer overflow (SF bug 1060396).
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
33760
diff
changeset
|
3726 memset((void *) &ip[0], '\0', sizeof(ip)); |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3727 |
| 42596 | 3728 if (!PyArg_ParseTuple(args, "iy#:inet_ntop", &af, &packed, &len)) { |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3729 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3730 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3731 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3732 if (af == AF_INET) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3733 if (len != sizeof(struct in_addr)) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3734 PyErr_SetString(PyExc_ValueError, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3735 "invalid length of packed IP address string"); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3736 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3737 } |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3738 #ifdef ENABLE_IPV6 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3739 } else if (af == AF_INET6) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3740 if (len != sizeof(struct in6_addr)) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3741 PyErr_SetString(PyExc_ValueError, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3742 "invalid length of packed IP address string"); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3743 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3744 } |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
29037
diff
changeset
|
3745 #endif |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3746 } else { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3747 PyErr_Format(PyExc_ValueError, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3748 "unknown address family %d", af); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3749 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3750 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3751 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3752 retval = inet_ntop(af, packed, ip, sizeof(ip)); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3753 if (!retval) { |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3754 PyErr_SetFromErrno(socket_error); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3755 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3756 } else { |
| 42596 | 3757 return PyUnicode_FromString(retval); |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3758 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3759 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3760 /* NOTREACHED */ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3761 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop"); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3762 return NULL; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3763 } |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3764 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3765 #endif /* HAVE_INET_PTON */ |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
3766 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3767 /* 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
|
3768 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3769 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3770 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3771 socket_getaddrinfo(PyObject *self, PyObject *args) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3772 { |
|
20912
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
3773 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
|
3774 struct addrinfo *res0 = NULL; |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3775 PyObject *hobj = NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3776 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
|
3777 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
|
3778 char *hptr, *pptr; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3779 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
|
3780 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3781 PyObject *all = (PyObject *)NULL; |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3782 PyObject *idna = NULL; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3783 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3784 family = socktype = protocol = flags = 0; |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
3785 family = AF_UNSPEC; |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3786 if (!PyArg_ParseTuple(args, "OO|iiii:getaddrinfo", |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3787 &hobj, &pobj, &family, &socktype, |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3788 &protocol, &flags)) { |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3789 return NULL; |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3790 } |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3791 if (hobj == Py_None) { |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3792 hptr = NULL; |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3793 } else if (PyUnicode_Check(hobj)) { |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3794 idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3795 if (!idna) |
|
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3796 return NULL; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3797 assert(PyBytes_Check(idna)); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3798 hptr = PyBytes_AS_STRING(idna); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3799 } else if (PyBytes_Check(hobj)) { |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3800 hptr = PyBytes_AsString(hobj); |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3801 } else { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
3802 PyErr_SetString(PyExc_TypeError, |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3803 "getaddrinfo() argument 1 must be string or None"); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3804 return NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3805 } |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
3806 if (PyLong_CheckExact(pobj)) { |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
3807 long value = PyLong_AsLong(pobj); |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
3808 if (value == -1 && PyErr_Occurred()) |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
3809 goto err; |
|
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44099
diff
changeset
|
3810 PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3811 pptr = pbuf; |
| 42596 | 3812 } else if (PyUnicode_Check(pobj)) { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47667
diff
changeset
|
3813 pptr = _PyUnicode_AsString(pobj); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3814 } else if (PyBytes_Check(pobj)) { |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
45865
diff
changeset
|
3815 pptr = PyBytes_AsString(pobj); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3816 } 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
|
3817 pptr = (char *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3818 } else { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3819 PyErr_SetString(socket_error, "Int or String expected"); |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
3820 goto err; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3821 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3822 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
|
3823 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
|
3824 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
|
3825 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
|
3826 hints.ai_flags = flags; |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3827 Py_BEGIN_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3828 ACQUIRE_GETADDRINFO_LOCK |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3829 error = getaddrinfo(hptr, pptr, &hints, &res0); |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3830 Py_END_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3831 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3832 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3833 set_gaierror(error); |
|
30081
7f5489184d94
Release host name memory. Fixes #783312. Will backport to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30061
diff
changeset
|
3834 goto err; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3835 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3836 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3837 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
|
3838 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3839 for (res = res0; res; res = res->ai_next) { |
|
42509
043a102a170e
Fix two bugs in socket_getaddr():
Guido van Rossum <guido@python.org>
parents:
42439
diff
changeset
|
3840 PyObject *single; |
|
20389
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
3841 PyObject *addr = |
|
32213
70dee2b193f7
Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents:
32183
diff
changeset
|
3842 makesockaddr(-1, res->ai_addr, res->ai_addrlen, protocol); |
|
20389
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
3843 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
|
3844 goto err; |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3845 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
|
3846 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
|
3847 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
|
3848 addr); |
|
b47168178d87
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents:
20378
diff
changeset
|
3849 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
|
3850 if (single == NULL) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3851 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3852 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3853 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
|
3854 goto err; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3855 Py_XDECREF(single); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3856 } |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3857 Py_XDECREF(idna); |
|
24687
8b470281645e
SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents:
24677
diff
changeset
|
3858 if (res0) |
|
8b470281645e
SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents:
24677
diff
changeset
|
3859 freeaddrinfo(res0); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3860 return all; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3861 err: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3862 Py_XDECREF(all); |
|
28671
d41d8de9768f
Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents:
28437
diff
changeset
|
3863 Py_XDECREF(idna); |
|
20912
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
3864 if (res0) |
|
06d95b6877c4
Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents:
20871
diff
changeset
|
3865 freeaddrinfo(res0); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3866 return (PyObject *)NULL; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3867 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3868 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3869 PyDoc_STRVAR(getaddrinfo_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
3870 "getaddrinfo(host, port [, family, socktype, proto, flags])\n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
3871 -> list of (family, socktype, proto, canonname, sockaddr)\n\ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3872 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3873 Resolve host and port into addrinfo struct."); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3874 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3875 /* 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
|
3876 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3877 /*ARGSUSED*/ |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3878 static PyObject * |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3879 socket_getnameinfo(PyObject *self, PyObject *args) |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3880 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3881 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
|
3882 int flags; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3883 char *hostp; |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
3884 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
|
3885 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
|
3886 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
|
3887 int error; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3888 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
|
3889 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3890 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
|
3891 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
|
3892 return NULL; |
|
56368
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3893 if (!PyTuple_Check(sa)) { |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3894 PyErr_SetString(PyExc_TypeError, |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3895 "getnameinfo() argument 1 must be a tuple"); |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3896 return NULL; |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3897 } |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3898 if (!PyArg_ParseTuple(sa, "si|ii", |
|
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3899 &hostp, &port, &flowinfo, &scope_id)) |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20756
diff
changeset
|
3900 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
|
3901 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
|
3902 memset(&hints, 0, sizeof(hints)); |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
3903 hints.ai_family = AF_UNSPEC; |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
3904 hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */ |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3905 Py_BEGIN_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3906 ACQUIRE_GETADDRINFO_LOCK |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3907 error = getaddrinfo(hostp, pbuf, &hints, &res); |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3908 Py_END_ALLOW_THREADS |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
3909 RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3910 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3911 set_gaierror(error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3912 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3913 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3914 if (res->ai_next) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3915 PyErr_SetString(socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3916 "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
|
3917 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3918 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3919 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
|
3920 case AF_INET: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3921 { |
|
56368
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
53824
diff
changeset
|
3922 if (PyTuple_GET_SIZE(sa) != 2) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3923 PyErr_SetString(socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3924 "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
|
3925 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3926 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3927 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3928 } |
|
21128
15ff504632ed
Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents:
21094
diff
changeset
|
3929 #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
|
3930 case AF_INET6: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3931 { |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3932 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
|
3933 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
|
3934 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
|
3935 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
|
3936 break; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3937 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3938 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3939 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3940 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
|
3941 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
|
3942 if (error) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
3943 set_gaierror(error); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3944 goto fail; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3945 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3946 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
|
3947 |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3948 fail: |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3949 if (res) |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3950 freeaddrinfo(res); |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3951 return ret; |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3952 } |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3953 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3954 PyDoc_STRVAR(getnameinfo_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
3955 "getnameinfo(sockaddr, flags) --> (host, port)\n\ |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3956 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
3957 Get host and port for a sockaddr."); |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
3958 |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3959 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3960 /* Python API to getting and setting the default timeout value. */ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3961 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3962 static PyObject * |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3963 socket_getdefaulttimeout(PyObject *self) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3964 { |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3965 if (defaulttimeout < 0.0) { |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3966 Py_INCREF(Py_None); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3967 return Py_None; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3968 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3969 else |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3970 return PyFloat_FromDouble(defaulttimeout); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3971 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3972 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3973 PyDoc_STRVAR(getdefaulttimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
3974 "getdefaulttimeout() -> timeout\n\ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3975 \n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3976 Returns the default timeout in floating seconds for new socket objects.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3977 A value of None indicates that new socket objects have no timeout.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3978 When the socket module is first imported, the default is None."); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3979 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3980 static PyObject * |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3981 socket_setdefaulttimeout(PyObject *self, PyObject *arg) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3982 { |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3983 double timeout; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3984 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3985 if (arg == Py_None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3986 timeout = -1.0; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3987 else { |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3988 timeout = PyFloat_AsDouble(arg); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3989 if (timeout < 0.0) { |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3990 if (!PyErr_Occurred()) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3991 PyErr_SetString(PyExc_ValueError, |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3992 "Timeout value out of range"); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3993 return NULL; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3994 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3995 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3996 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3997 defaulttimeout = timeout; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3998 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
3999 Py_INCREF(Py_None); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4000 return Py_None; |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4001 } |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4002 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4003 PyDoc_STRVAR(setdefaulttimeout_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4004 "setdefaulttimeout(timeout)\n\ |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4005 \n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4006 Set the default timeout in floating seconds for new socket objects.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4007 A value of None indicates that new socket objects have no timeout.\n\ |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4008 When the socket module is first imported, the default is None."); |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4009 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4010 |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4011 /* 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
|
4012 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4013 static PyMethodDef socket_methods[] = { |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4014 {"gethostbyname", socket_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
|
4015 METH_VARARGS, gethostbyname_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4016 {"gethostbyname_ex", socket_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
|
4017 METH_VARARGS, ghbn_ex_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4018 {"gethostbyaddr", socket_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
|
4019 METH_VARARGS, gethostbyaddr_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4020 {"gethostname", socket_gethostname, |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4021 METH_NOARGS, gethostname_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4022 {"getservbyname", socket_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
|
4023 METH_VARARGS, getservbyname_doc}, |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
4024 {"getservbyport", socket_getservbyport, |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32213
diff
changeset
|
4025 METH_VARARGS, getservbyport_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4026 {"getprotobyname", socket_getprotobyname, |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4027 METH_VARARGS, getprotobyname_doc}, |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
4028 #ifndef NO_DUP |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
4029 {"dup", socket_dup, |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
4030 METH_O, dup_doc}, |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
4031 #endif |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
4032 #ifdef HAVE_SOCKETPAIR |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
4033 {"socketpair", socket_socketpair, |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
4034 METH_VARARGS, socketpair_doc}, |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32913
diff
changeset
|
4035 #endif |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4036 {"ntohs", socket_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
|
4037 METH_VARARGS, ntohs_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4038 {"ntohl", socket_ntohl, |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
4039 METH_O, ntohl_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4040 {"htons", socket_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
|
4041 METH_VARARGS, htons_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4042 {"htonl", socket_htonl, |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24363
diff
changeset
|
4043 METH_O, htonl_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4044 {"inet_aton", socket_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
|
4045 METH_VARARGS, inet_aton_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4046 {"inet_ntoa", socket_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
|
4047 METH_VARARGS, inet_ntoa_doc}, |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4048 #ifdef HAVE_INET_PTON |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4049 {"inet_pton", socket_inet_pton, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4050 METH_VARARGS, inet_pton_doc}, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4051 {"inet_ntop", socket_inet_ntop, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4052 METH_VARARGS, inet_ntop_doc}, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4053 #endif |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4054 {"getaddrinfo", socket_getaddrinfo, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4055 METH_VARARGS, getaddrinfo_doc}, |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4056 {"getnameinfo", socket_getnameinfo, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4057 METH_VARARGS, getnameinfo_doc}, |
|
24303
93434bc0899d
Silence warning about getdefaulttimeout in PyMethodDef.
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
4058 {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout, |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4059 METH_NOARGS, getdefaulttimeout_doc}, |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4060 {"setdefaulttimeout", socket_setdefaulttimeout, |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
24280
diff
changeset
|
4061 METH_O, setdefaulttimeout_doc}, |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4062 {NULL, NULL} /* Sentinel */ |
| 294 | 4063 }; |
| 4064 | |
|
295
d7a38dece86a
Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents:
294
diff
changeset
|
4065 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
4066 #ifdef MS_WINDOWS |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4067 #define OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4068 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4069 /* Additional initialization and cleanup for 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
|
4070 |
|
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
|
4071 static void |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4072 os_cleanup(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
|
4073 { |
|
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
|
4074 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
|
4075 } |
|
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
|
4076 |
|
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
|
4077 static int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4078 os_init(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
|
4079 { |
|
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
|
4080 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
|
4081 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
|
4082 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
|
4083 switch (ret) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4084 case 0: /* No error */ |
|
29790
1037feacb54f
Fix [ 766669 ] Consistent GPF on exit
Mark Hammond <mhammond@skippinet.com.au>
parents:
29651
diff
changeset
|
4085 Py_AtExit(os_cleanup); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4086 return 1; /* Success */ |
|
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
|
4087 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
|
4088 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
|
4089 "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
|
4090 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
|
4091 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
|
4092 case WSAEINVAL: |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4093 PyErr_SetString( |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4094 PyExc_ImportError, |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4095 "WSAStartup failed: requested version not supported"); |
|
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
|
4096 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
|
4097 default: |
|
41943
8bcfc46e444b
Simplify os_init() implementations by using PyErr_Format()
Walter Dörwald <walter@livinglogic.de>
parents:
41942
diff
changeset
|
4098 PyErr_Format(PyExc_ImportError, "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
|
4099 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
|
4100 } |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4101 return 0; /* Failure */ |
|
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
|
4102 } |
|
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
|
4103 |
|
3702
3408756ec601
changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents:
3700
diff
changeset
|
4104 #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
|
4105 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4106 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4107 #ifdef PYOS_OS2 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4108 #define OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4109 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4110 /* Additional initialization for OS/2 */ |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4111 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4112 static int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4113 os_init(void) |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4114 { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4115 #ifndef PYCC_GCC |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4116 int rc = sock_init(); |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4117 |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4118 if (rc == 0) { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4119 return 1; /* Success */ |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4120 } |
|
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4121 |
|
41943
8bcfc46e444b
Simplify os_init() implementations by using PyErr_Format()
Walter Dörwald <walter@livinglogic.de>
parents:
41942
diff
changeset
|
4122 PyErr_Format(PyExc_ImportError, "OS/2 TCP/IP Error# %d", sock_errno()); |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4123 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4124 return 0; /* Failure */ |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
4125 #else |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4126 /* No need to initialise sockets with GCC/EMX */ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4127 return 1; /* Success */ |
|
22115
d104bb50a194
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
22096
diff
changeset
|
4128 #endif |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4129 } |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4130 |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4131 #endif /* PYOS_OS2 */ |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
6618
diff
changeset
|
4132 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4133 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4134 #ifndef OS_INIT_DEFINED |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4135 static int |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4136 os_init(void) |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4137 { |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4138 return 1; /* Success */ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4139 } |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4140 #endif |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4141 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4142 |
|
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
|
4143 /* 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
|
4144 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
|
4145 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
|
4146 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
|
4147 { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4148 &sock_type, |
|
31790
29da8bdfeb4e
Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents:
31541
diff
changeset
|
4149 NULL |
|
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
|
4150 }; |
|
3957d155f8c5
Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents:
21757
diff
changeset
|
4151 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4152 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4153 /* Initialize the _socket module. |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4154 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4155 This module is actually called "_socket", and there's a wrapper |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4156 "socket.py" which implements some additional functionality. |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4157 The import of "_socket" may fail with an ImportError exception if |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4158 os-specific initialization fails. On Windows, this does WINSOCK |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4159 initialization. When WINSOCK is initialized succesfully, a call to |
|
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4160 WSACleanup() is scheduled to be made at exit time. |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4161 */ |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4162 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23818
diff
changeset
|
4163 PyDoc_STRVAR(socket_doc, |
|
24676
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4164 "Implementation module for socket operations.\n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4165 \n\ |
|
980767c6cd97
Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents:
24619
diff
changeset
|
4166 See the socket module for documentation."); |
|
8631
d86733676815
Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents:
8439
diff
changeset
|
4167 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4168 static struct PyModuleDef socketmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4169 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4170 PySocket_MODULE_NAME, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4171 socket_doc, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4172 -1, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4173 socket_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4174 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4175 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4176 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4177 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4178 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4179 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24411
diff
changeset
|
4180 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4181 PyInit__socket(void) |
| 294 | 4182 { |
|
44643
d8e4342c145e
Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44568
diff
changeset
|
4183 PyObject *m, *has_ipv6; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4184 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4185 if (!os_init()) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4186 return NULL; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4187 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44349
diff
changeset
|
4188 Py_TYPE(&sock_type) = &PyType_Type; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4189 m = PyModule_Create(&socketmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36298
diff
changeset
|
4190 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4191 return NULL; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4192 |
|
43300
b355d2dba9b6
merge this from trunk:
Gregory P. Smith <greg@mad-scientist.com>
parents:
42918
diff
changeset
|
4193 socket_error = PyErr_NewException("socket.error", |
|
b355d2dba9b6
merge this from trunk:
Gregory P. Smith <greg@mad-scientist.com>
parents:
42918
diff
changeset
|
4194 PyExc_IOError, NULL); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4195 if (socket_error == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4196 return NULL; |
|
31790
29da8bdfeb4e
Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents:
31541
diff
changeset
|
4197 PySocketModuleAPI.error = socket_error; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4198 Py_INCREF(socket_error); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4199 PyModule_AddObject(m, "error", socket_error); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4200 socket_herror = PyErr_NewException("socket.herror", |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4201 socket_error, NULL); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4202 if (socket_herror == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4203 return NULL; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4204 Py_INCREF(socket_herror); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4205 PyModule_AddObject(m, "herror", socket_herror); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4206 socket_gaierror = PyErr_NewException("socket.gaierror", socket_error, |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4207 NULL); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4208 if (socket_gaierror == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4209 return NULL; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4210 Py_INCREF(socket_gaierror); |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4211 PyModule_AddObject(m, "gaierror", socket_gaierror); |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
4212 socket_timeout = PyErr_NewException("socket.timeout", |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
4213 socket_error, NULL); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
4214 if (socket_timeout == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4215 return NULL; |
|
29651
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
4216 Py_INCREF(socket_timeout); |
|
0a3751df4195
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29066
diff
changeset
|
4217 PyModule_AddObject(m, "timeout", socket_timeout); |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4218 Py_INCREF((PyObject *)&sock_type); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4219 if (PyModule_AddObject(m, "SocketType", |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4220 (PyObject *)&sock_type) != 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4221 return NULL; |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4222 Py_INCREF((PyObject *)&sock_type); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4223 if (PyModule_AddObject(m, "socket", |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
4224 (PyObject *)&sock_type) != 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4225 return NULL; |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4226 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4227 #ifdef ENABLE_IPV6 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4228 has_ipv6 = Py_True; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4229 #else |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4230 has_ipv6 = Py_False; |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4231 #endif |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4232 Py_INCREF(has_ipv6); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4233 PyModule_AddObject(m, "has_ipv6", has_ipv6); |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
4234 |
|
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
|
4235 /* 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
|
4236 if (PyModule_AddObject(m, PySocket_CAPI_NAME, |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
52561
diff
changeset
|
4237 PyCapsule_New(&PySocketModuleAPI, PySocket_CAPSULE_NAME, NULL) |
|
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
|
4238 ) != 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
4239 return NULL; |
|
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
|
4240 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4241 /* 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
|
4242 #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
|
4243 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
|
4244 #endif |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4245 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
|
4246 #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
|
4247 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
|
4248 #endif /* AF_INET6 */ |
|
31867
51aaceeaabe1
OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
31790
diff
changeset
|
4249 #if defined(AF_UNIX) |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4250 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
|
4251 #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
|
4252 #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
|
4253 /* 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
|
4254 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
|
4255 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4256 #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
|
4257 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
|
4258 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4259 #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
|
4260 /* Appletalk DDP */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4261 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
|
4262 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4263 #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
|
4264 /* Amateur radio NetROM */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4265 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
|
4266 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4267 #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
|
4268 /* Multiprotocol bridge */ |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4269 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
|
4270 #endif |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4271 #ifdef AF_ATMPVC |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4272 /* ATM PVCs */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4273 PyModule_AddIntConstant(m, "AF_ATMPVC", AF_ATMPVC); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4274 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4275 #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
|
4276 /* 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
|
4277 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
|
4278 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4279 #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
|
4280 /* 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
|
4281 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
|
4282 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4283 #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
|
4284 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
|
4285 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4286 #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
|
4287 /* 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
|
4288 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
|
4289 #endif |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4290 #ifdef AF_DECnet |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4291 /* Reserved for DECnet project */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4292 PyModule_AddIntConstant(m, "AF_DECnet", AF_DECnet); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4293 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4294 #ifdef AF_NETBEUI |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4295 /* Reserved for 802.2LLC project */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4296 PyModule_AddIntConstant(m, "AF_NETBEUI", AF_NETBEUI); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4297 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4298 #ifdef AF_SECURITY |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4299 /* Security callback pseudo AF */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4300 PyModule_AddIntConstant(m, "AF_SECURITY", AF_SECURITY); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4301 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4302 #ifdef AF_KEY |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4303 /* PF_KEY key management API */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4304 PyModule_AddIntConstant(m, "AF_KEY", AF_KEY); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4305 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4306 #ifdef AF_NETLINK |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4307 /* */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4308 PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4309 PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4310 #ifdef NETLINK_SKIP |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4311 PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4312 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4313 #ifdef NETLINK_W1 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4314 PyModule_AddIntConstant(m, "NETLINK_W1", NETLINK_W1); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4315 #endif |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4316 PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK); |
|
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4317 PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4318 #ifdef NETLINK_TCPDIAG |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4319 PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4320 #endif |
|
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4321 #ifdef NETLINK_NFLOG |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4322 PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG); |
|
36632
4d988dda6478
NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents:
36610
diff
changeset
|
4323 #endif |
|
36298
9eeaa33f9640
Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36289
diff
changeset
|
4324 #ifdef NETLINK_XFRM |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4325 PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM); |
|
36298
9eeaa33f9640
Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36289
diff
changeset
|
4326 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4327 #ifdef NETLINK_ARPD |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4328 PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4329 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4330 #ifdef NETLINK_ROUTE6 |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4331 PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4332 #endif |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4333 PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW); |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
4334 #ifdef NETLINK_DNRTMSG |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4335 PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG); |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43877
diff
changeset
|
4336 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4337 #ifdef NETLINK_TAPBASE |
|
36286
ae4480935016
Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents:
36090
diff
changeset
|
4338 PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE); |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4339 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36684
diff
changeset
|
4340 #endif /* AF_NETLINK */ |
|
32764
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4341 #ifdef AF_ROUTE |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4342 /* Alias to emulate 4.4BSD */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4343 PyModule_AddIntConstant(m, "AF_ROUTE", AF_ROUTE); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4344 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4345 #ifdef AF_ASH |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4346 /* Ash */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4347 PyModule_AddIntConstant(m, "AF_ASH", AF_ASH); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4348 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4349 #ifdef AF_ECONET |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4350 /* Acorn Econet */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4351 PyModule_AddIntConstant(m, "AF_ECONET", AF_ECONET); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4352 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4353 #ifdef AF_ATMSVC |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4354 /* ATM SVCs */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4355 PyModule_AddIntConstant(m, "AF_ATMSVC", AF_ATMSVC); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4356 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4357 #ifdef AF_SNA |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4358 /* Linux SNA Project (nutters!) */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4359 PyModule_AddIntConstant(m, "AF_SNA", AF_SNA); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4360 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4361 #ifdef AF_IRDA |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4362 /* IRDA sockets */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4363 PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4364 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4365 #ifdef AF_PPPOX |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4366 /* PPPoX sockets */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4367 PyModule_AddIntConstant(m, "AF_PPPOX", AF_PPPOX); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4368 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4369 #ifdef AF_WANPIPE |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4370 /* Wanpipe API Sockets */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4371 PyModule_AddIntConstant(m, "AF_WANPIPE", AF_WANPIPE); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4372 #endif |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4373 #ifdef AF_LLC |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4374 /* Linux LLC */ |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4375 PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); |
|
ecb0c97f1e42
Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
32611
diff
changeset
|
4376 #endif |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4377 |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
4378 #ifdef USE_BLUETOOTH |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4379 PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4380 PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
4381 PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
4382 PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI); |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41943
diff
changeset
|
4383 PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41943
diff
changeset
|
4384 #if !defined(__FreeBSD__) |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
4385 PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP); |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40638
diff
changeset
|
4386 PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR); |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4387 PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); |
|
31443
afb4c9726d1a
Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31441
diff
changeset
|
4388 #endif |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4389 PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4390 PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00"); |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4391 PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); |
|
31441
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4392 #endif |
|
493707692671
Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
31274
diff
changeset
|
4393 |
|
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
|
4394 #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
|
4395 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
|
4396 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
|
4397 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
|
4398 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
|
4399 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
|
4400 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
|
4401 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
|
4402 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
|
4403 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16472
diff
changeset
|
4404 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4405 |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4406 #ifdef HAVE_LINUX_TIPC_H |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4407 PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4408 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4409 /* for addresses */ |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4410 PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4411 PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4412 PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4413 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4414 PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4415 PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4416 PyModule_AddIntConstant(m, "TIPC_NODE_SCOPE", TIPC_NODE_SCOPE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4417 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4418 /* for setsockopt() */ |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4419 PyModule_AddIntConstant(m, "SOL_TIPC", SOL_TIPC); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4420 PyModule_AddIntConstant(m, "TIPC_IMPORTANCE", TIPC_IMPORTANCE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4421 PyModule_AddIntConstant(m, "TIPC_SRC_DROPPABLE", TIPC_SRC_DROPPABLE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4422 PyModule_AddIntConstant(m, "TIPC_DEST_DROPPABLE", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4423 TIPC_DEST_DROPPABLE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4424 PyModule_AddIntConstant(m, "TIPC_CONN_TIMEOUT", TIPC_CONN_TIMEOUT); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4425 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4426 PyModule_AddIntConstant(m, "TIPC_LOW_IMPORTANCE", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4427 TIPC_LOW_IMPORTANCE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4428 PyModule_AddIntConstant(m, "TIPC_MEDIUM_IMPORTANCE", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4429 TIPC_MEDIUM_IMPORTANCE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4430 PyModule_AddIntConstant(m, "TIPC_HIGH_IMPORTANCE", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4431 TIPC_HIGH_IMPORTANCE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4432 PyModule_AddIntConstant(m, "TIPC_CRITICAL_IMPORTANCE", |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4433 TIPC_CRITICAL_IMPORTANCE); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4434 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4435 /* for subscriptions */ |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4436 PyModule_AddIntConstant(m, "TIPC_SUB_PORTS", TIPC_SUB_PORTS); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4437 PyModule_AddIntConstant(m, "TIPC_SUB_SERVICE", TIPC_SUB_SERVICE); |
|
44643
d8e4342c145e
Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44568
diff
changeset
|
4438 #ifdef TIPC_SUB_CANCEL |
|
d8e4342c145e
Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44568
diff
changeset
|
4439 /* doesn't seem to be available everywhere */ |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4440 PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL); |
|
44643
d8e4342c145e
Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44568
diff
changeset
|
4441 #endif |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4442 PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4443 PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4444 PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4445 PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4446 PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4447 PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4448 #endif |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4449 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4450 /* Socket types */ |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4451 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
|
4452 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
|
4453 /* 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
|
4454 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
|
4455 PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); |
|
26597
7ddea4dfa519
Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents:
26551
diff
changeset
|
4456 #if defined(SOCK_RDM) |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4457 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
|
4458 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4459 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4460 #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
|
4461 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4462 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4463 #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
|
4464 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4465 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4466 #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
|
4467 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4468 #endif |
|
32578
21fd6e62cd27
[Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents:
32521
diff
changeset
|
4469 #ifdef SO_EXCLUSIVEADDRUSE |
|
21fd6e62cd27
[Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents:
32521
diff
changeset
|
4470 PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE); |
|
21fd6e62cd27
[Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents:
32521
diff
changeset
|
4471 #endif |
|
21fd6e62cd27
[Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents:
32521
diff
changeset
|
4472 |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4473 #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
|
4474 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4475 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4476 #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
|
4477 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4478 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4479 #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
|
4480 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4481 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4482 #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
|
4483 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4484 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4485 #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
|
4486 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4487 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4488 #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
|
4489 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4490 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4491 #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
|
4492 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4493 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4494 #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
|
4495 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4496 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4497 #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
|
4498 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4499 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4500 #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
|
4501 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4502 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4503 #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
|
4504 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4505 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4506 #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
|
4507 PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4508 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4509 #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
|
4510 PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4511 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4512 #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
|
4513 PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4514 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4515 #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
|
4516 PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4517 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4518 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4519 /* Maximum number of connections for "listen" */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4520 #ifdef SOMAXCONN |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4521 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4522 #else |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
4523 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4524 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4525 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4526 /* Flags for send, recv */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4527 #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
|
4528 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4529 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4530 #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
|
4531 PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4532 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4533 #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
|
4534 PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4535 #endif |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
4536 #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
|
4537 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT); |
|
12492
1725e802e3eb
Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents:
12479
diff
changeset
|
4538 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4539 #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
|
4540 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4541 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4542 #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
|
4543 PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4544 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4545 #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
|
4546 PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4547 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4548 #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
|
4549 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4550 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4551 #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
|
4552 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4553 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4554 #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
|
4555 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4556 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4557 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4558 /* Protocol level and numbers, usable for [gs]etsockopt */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4559 #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
|
4560 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4561 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4562 #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
|
4563 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
|
4564 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4565 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
|
4566 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4567 #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
|
4568 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
|
4569 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4570 #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
|
4571 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
|
4572 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4573 #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
|
4574 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
|
4575 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4576 #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
|
4577 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
|
4578 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4579 #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
|
4580 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
|
4581 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4582 #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
|
4583 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
|
4584 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4585 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
|
4586 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4587 #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
|
4588 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
|
4589 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4590 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
|
4591 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4592 #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
|
4593 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
|
4594 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4595 PyModule_AddIntConstant(m, "IPPROTO_IP", 0); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4596 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4597 #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
|
4598 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
|
4599 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4600 #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
|
4601 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
|
4602 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4603 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4604 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4605 #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
|
4606 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4607 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4608 #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
|
4609 PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4610 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4611 #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
|
4612 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
|
4613 #endif |
|
30630
9200712d31e7
Patch #813445: Add missing socket.IPPROTO_IPV6. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30081
diff
changeset
|
4614 #ifdef IPPROTO_IPV6 |
|
9200712d31e7
Patch #813445: Add missing socket.IPPROTO_IPV6. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30081
diff
changeset
|
4615 PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); |
|
9200712d31e7
Patch #813445: Add missing socket.IPPROTO_IPV6. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30081
diff
changeset
|
4616 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4617 #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
|
4618 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
|
4619 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4620 #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
|
4621 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
|
4622 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4623 PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4624 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4625 #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
|
4626 PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4627 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4628 #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
|
4629 PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4630 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4631 #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
|
4632 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
|
4633 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4634 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4635 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4636 #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
|
4637 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4638 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4639 #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
|
4640 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4641 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4642 #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
|
4643 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4644 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4645 #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
|
4646 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4647 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4648 #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
|
4649 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
|
4650 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4651 #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
|
4652 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
|
4653 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4654 #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
|
4655 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
|
4656 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4657 #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
|
4658 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
|
4659 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4660 #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
|
4661 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
|
4662 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4663 #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
|
4664 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
|
4665 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4666 #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
|
4667 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
|
4668 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4669 #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
|
4670 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
|
4671 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4672 #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
|
4673 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
|
4674 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4675 #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
|
4676 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
|
4677 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4678 #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
|
4679 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
|
4680 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4681 #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
|
4682 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4683 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4684 #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
|
4685 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4686 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4687 #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
|
4688 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
|
4689 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4690 #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
|
4691 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
|
4692 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4693 #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
|
4694 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
|
4695 #endif |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4696 #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
|
4697 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4698 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4699 /**/ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4700 #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
|
4701 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
|
4702 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4703 PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4704 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4705 #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
|
4706 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4707 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4708 |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4709 /* Some port configuration */ |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4710 #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
|
4711 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4712 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4713 PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4714 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4715 #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
|
4716 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4717 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4718 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4719 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4720 |
| 2369 | 4721 /* Some reserved IP v.4 addresses */ |
| 4722 #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
|
4723 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY); |
| 2369 | 4724 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4725 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); |
| 2369 | 4726 #endif |
| 4727 #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
|
4728 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST); |
| 2369 | 4729 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4730 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); |
| 2369 | 4731 #endif |
| 4732 #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
|
4733 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK); |
| 2369 | 4734 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4735 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); |
| 2369 | 4736 #endif |
| 4737 #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
|
4738 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); |
| 2369 | 4739 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4740 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); |
| 2369 | 4741 #endif |
| 4742 #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
|
4743 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
|
4744 INADDR_ALLHOSTS_GROUP); |
| 2369 | 4745 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4746 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); |
| 2369 | 4747 #endif |
| 4748 #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
|
4749 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
|
4750 INADDR_MAX_LOCAL_GROUP); |
| 2369 | 4751 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4752 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); |
| 2369 | 4753 #endif |
| 4754 #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
|
4755 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE); |
| 2369 | 4756 #else |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22568
diff
changeset
|
4757 PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); |
| 2369 | 4758 #endif |
| 4759 | |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4760 /* IPv4 [gs]etsockopt options */ |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4761 #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
|
4762 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4763 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4764 #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
|
4765 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4766 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4767 #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
|
4768 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4769 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4770 #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
|
4771 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4772 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4773 #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
|
4774 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4775 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4776 #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
|
4777 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4778 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4779 #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
|
4780 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4781 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4782 #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
|
4783 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS); |
|
2299
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4784 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4785 #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
|
4786 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
|
4787 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4788 #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
|
4789 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
|
4790 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4791 #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
|
4792 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
|
4793 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4794 #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
|
4795 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
|
4796 #endif |
|
990099ed7810
add socket related constants
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
4797 #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
|
4798 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
|
4799 #endif |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4800 #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
|
4801 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
|
4802 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
|
4803 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4804 #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
|
4805 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
|
4806 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
|
4807 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4808 #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
|
4809 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
|
4810 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4811 |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4812 /* 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
|
4813 #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
|
4814 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
|
4815 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4816 #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
|
4817 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
|
4818 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4819 #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
|
4820 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
|
4821 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4822 #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
|
4823 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
|
4824 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4825 #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
|
4826 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
|
4827 #endif |
|
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4828 #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
|
4829 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
|
4830 #endif |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4831 /* Additional IPV6 socket options, defined in RFC 3493 */ |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4832 #ifdef IPV6_V6ONLY |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4833 PyModule_AddIntConstant(m, "IPV6_V6ONLY", IPV6_V6ONLY); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4834 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4835 /* Advanced IPV6 socket options, from RFC 3542 */ |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4836 #ifdef IPV6_CHECKSUM |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4837 PyModule_AddIntConstant(m, "IPV6_CHECKSUM", IPV6_CHECKSUM); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4838 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4839 #ifdef IPV6_DONTFRAG |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4840 PyModule_AddIntConstant(m, "IPV6_DONTFRAG", IPV6_DONTFRAG); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4841 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4842 #ifdef IPV6_DSTOPTS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4843 PyModule_AddIntConstant(m, "IPV6_DSTOPTS", IPV6_DSTOPTS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4844 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4845 #ifdef IPV6_HOPLIMIT |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4846 PyModule_AddIntConstant(m, "IPV6_HOPLIMIT", IPV6_HOPLIMIT); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4847 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4848 #ifdef IPV6_HOPOPTS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4849 PyModule_AddIntConstant(m, "IPV6_HOPOPTS", IPV6_HOPOPTS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4850 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4851 #ifdef IPV6_NEXTHOP |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4852 PyModule_AddIntConstant(m, "IPV6_NEXTHOP", IPV6_NEXTHOP); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4853 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4854 #ifdef IPV6_PATHMTU |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4855 PyModule_AddIntConstant(m, "IPV6_PATHMTU", IPV6_PATHMTU); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4856 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4857 #ifdef IPV6_PKTINFO |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4858 PyModule_AddIntConstant(m, "IPV6_PKTINFO", IPV6_PKTINFO); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4859 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4860 #ifdef IPV6_RECVDSTOPTS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4861 PyModule_AddIntConstant(m, "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4862 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4863 #ifdef IPV6_RECVHOPLIMIT |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4864 PyModule_AddIntConstant(m, "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4865 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4866 #ifdef IPV6_RECVHOPOPTS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4867 PyModule_AddIntConstant(m, "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4868 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4869 #ifdef IPV6_RECVPKTINFO |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4870 PyModule_AddIntConstant(m, "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4871 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4872 #ifdef IPV6_RECVRTHDR |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4873 PyModule_AddIntConstant(m, "IPV6_RECVRTHDR", IPV6_RECVRTHDR); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4874 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4875 #ifdef IPV6_RECVTCLASS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4876 PyModule_AddIntConstant(m, "IPV6_RECVTCLASS", IPV6_RECVTCLASS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4877 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4878 #ifdef IPV6_RTHDR |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4879 PyModule_AddIntConstant(m, "IPV6_RTHDR", IPV6_RTHDR); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4880 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4881 #ifdef IPV6_RTHDRDSTOPTS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4882 PyModule_AddIntConstant(m, "IPV6_RTHDRDSTOPTS", IPV6_RTHDRDSTOPTS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4883 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4884 #ifdef IPV6_RTHDR_TYPE_0 |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4885 PyModule_AddIntConstant(m, "IPV6_RTHDR_TYPE_0", IPV6_RTHDR_TYPE_0); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4886 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4887 #ifdef IPV6_RECVPATHMTU |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4888 PyModule_AddIntConstant(m, "IPV6_RECVPATHMTU", IPV6_RECVPATHMTU); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4889 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4890 #ifdef IPV6_TCLASS |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4891 PyModule_AddIntConstant(m, "IPV6_TCLASS", IPV6_TCLASS); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4892 #endif |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4893 #ifdef IPV6_USE_MIN_MTU |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4894 PyModule_AddIntConstant(m, "IPV6_USE_MIN_MTU", IPV6_USE_MIN_MTU); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4895 #endif |
|
18997
9fc4a5abb369
Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
18996
diff
changeset
|
4896 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4897 /* TCP options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4898 #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
|
4899 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
|
4900 #endif |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4901 #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
|
4902 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
|
4903 #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
|
4904 #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
|
4905 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
|
4906 #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
|
4907 #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
|
4908 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
|
4909 #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
|
4910 #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
|
4911 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
|
4912 #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
|
4913 #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
|
4914 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
|
4915 #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
|
4916 #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
|
4917 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
|
4918 #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
|
4919 #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
|
4920 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
|
4921 #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
|
4922 #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
|
4923 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
|
4924 #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
|
4925 #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
|
4926 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
|
4927 #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
|
4928 #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
|
4929 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
|
4930 #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
|
4931 #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
|
4932 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
|
4933 #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
|
4934 |
|
11182
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4935 |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4936 /* IPX options */ |
|
35e0d03f2b02
Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents:
10579
diff
changeset
|
4937 #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
|
4938 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
|
4939 #endif |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
4940 |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4941 /* 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
|
4942 #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
|
4943 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
|
4944 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4945 #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
|
4946 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
|
4947 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4948 #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
|
4949 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
|
4950 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4951 #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
|
4952 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
|
4953 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4954 #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
|
4955 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
|
4956 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4957 #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
|
4958 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
|
4959 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4960 #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
|
4961 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
|
4962 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4963 #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
|
4964 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
|
4965 #endif |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4966 #ifdef EAI_OVERFLOW |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4967 PyModule_AddIntConstant(m, "EAI_OVERFLOW", EAI_OVERFLOW); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4968 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4969 #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
|
4970 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
|
4971 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4972 #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
|
4973 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
|
4974 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4975 #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
|
4976 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
|
4977 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4978 #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
|
4979 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
|
4980 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4981 #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
|
4982 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
|
4983 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4984 #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
|
4985 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
|
4986 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4987 #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
|
4988 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
|
4989 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4990 #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
|
4991 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
|
4992 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4993 #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
|
4994 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
|
4995 #endif |
|
31274
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4996 #ifdef AI_NUMERICSERV |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4997 PyModule_AddIntConstant(m, "AI_NUMERICSERV", AI_NUMERICSERV); |
|
24d34ab4ef75
Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents:
31207
diff
changeset
|
4998 #endif |
|
18794
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
4999 #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
|
5000 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
|
5001 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5002 #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
|
5003 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
|
5004 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5005 #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
|
5006 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
|
5007 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5008 #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
|
5009 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
|
5010 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5011 #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
|
5012 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
|
5013 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5014 #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
|
5015 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
|
5016 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5017 #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
|
5018 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
|
5019 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5020 #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
|
5021 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
|
5022 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5023 #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
|
5024 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
|
5025 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5026 #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
|
5027 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
|
5028 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5029 #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
|
5030 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
|
5031 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5032 #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
|
5033 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
|
5034 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5035 #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
|
5036 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
|
5037 #endif |
|
4d0ea4c2386d
Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents:
18790
diff
changeset
|
5038 |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5039 /* shutdown() parameters */ |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5040 #ifdef SHUT_RD |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5041 PyModule_AddIntConstant(m, "SHUT_RD", SHUT_RD); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5042 #elif defined(SD_RECEIVE) |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5043 PyModule_AddIntConstant(m, "SHUT_RD", SD_RECEIVE); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5044 #else |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5045 PyModule_AddIntConstant(m, "SHUT_RD", 0); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5046 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5047 #ifdef SHUT_WR |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5048 PyModule_AddIntConstant(m, "SHUT_WR", SHUT_WR); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5049 #elif defined(SD_SEND) |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5050 PyModule_AddIntConstant(m, "SHUT_WR", SD_SEND); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5051 #else |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5052 PyModule_AddIntConstant(m, "SHUT_WR", 1); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5053 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5054 #ifdef SHUT_RDWR |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5055 PyModule_AddIntConstant(m, "SHUT_RDWR", SHUT_RDWR); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5056 #elif defined(SD_BOTH) |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5057 PyModule_AddIntConstant(m, "SHUT_RDWR", SD_BOTH); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5058 #else |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5059 PyModule_AddIntConstant(m, "SHUT_RDWR", 2); |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5060 #endif |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30978
diff
changeset
|
5061 |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5062 #ifdef SIO_RCVALL |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5063 { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5064 PyObject *tmp; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5065 tmp = PyLong_FromUnsignedLong(SIO_RCVALL); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5066 if (tmp == NULL) |
|
47583
b82e0545d111
Add missing NULL return value.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
5067 return NULL; |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5068 PyModule_AddObject(m, "SIO_RCVALL", tmp); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44643
diff
changeset
|
5069 } |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5070 PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF); |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5071 PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON); |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5072 PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY); |
|
47663
92b79b6d1a3b
Slowly apply part of #2065: py3k can be compiled with VS8.0
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47583
diff
changeset
|
5073 #ifdef RCVALL_IPLEVEL |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5074 PyModule_AddIntConstant(m, "RCVALL_IPLEVEL", RCVALL_IPLEVEL); |
|
47663
92b79b6d1a3b
Slowly apply part of #2065: py3k can be compiled with VS8.0
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47583
diff
changeset
|
5075 #endif |
|
92b79b6d1a3b
Slowly apply part of #2065: py3k can be compiled with VS8.0
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47583
diff
changeset
|
5076 #ifdef RCVALL_MAX |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5077 PyModule_AddIntConstant(m, "RCVALL_MAX", RCVALL_MAX); |
|
47663
92b79b6d1a3b
Slowly apply part of #2065: py3k can be compiled with VS8.0
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47583
diff
changeset
|
5078 #endif |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5079 #endif /* _MSTCPIP_ */ |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
5080 |
|
7942
ee2aaa2f722a
Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents:
6718
diff
changeset
|
5081 /* Initialize gethostbyname lock */ |
|
29035
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
5082 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) |
|
e1d5ca8ab7dc
[ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents:
28953
diff
changeset
|
5083 netdb_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
|
5084 #endif |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
5085 return m; |
| 294 | 5086 } |
|
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
|
5087 |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5088 |
|
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5089 #ifndef HAVE_INET_PTON |
|
43926
2de7d00fbf19
The patch from weck does a better job than my original idea. Thanks!
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
5090 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN) |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5091 |
|
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
|
5092 /* Simplistic emulation code for inet_pton that only works for IPv4 */ |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28671
diff
changeset
|
5093 /* These are not exposed because they do not set errno properly */ |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5094 |
|
23723
2f6f8708e3e9
Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents:
23722
diff
changeset
|
5095 int |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5096 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
|
5097 { |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5098 if (af == AF_INET) { |
|
51579
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
5099 #if (SIZEOF_INT != 4) |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
5100 #error "Not sure if in_addr_t exists and int is not 32-bits." |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
5101 #endif |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51384
diff
changeset
|
5102 unsigned int packed_addr; |
|
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
|
5103 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
|
5104 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
|
5105 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
|
5106 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
|
5107 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
|
5108 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5109 /* 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
|
5110 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
|
5111 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5112 |
|
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
|
5113 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
|
5114 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
|
5115 { |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5116 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
|
5117 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
|
5118 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
|
5119 /* 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
|
5120 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
|
5121 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
|
5122 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
|
5123 } |
|
6b0a8157be3b
Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents:
18253
diff
changeset
|
5124 /* 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
|
5125 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
|
5126 } |
|
23725
1235a95fedcd
Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents:
23723
diff
changeset
|
5127 |
|
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
|
5128 #endif |
| 43874 | 5129 #endif |
