annotate Modules/socketmodule.c @ 51271:87fbbf22adf3 3.0

Merged revisions 69214 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r69214 | mark.dickinson | 2009-02-02 20:36:42 +0000 (Mon, 02 Feb 2009) | 4 lines Issue #1717: rename tp_compare to tp_reserved. I'll change the type of tp_compare in a separate commit, for ease of reversion should things go wrong. ........
author Mark Dickinson <dickinsm@gmail.com>
date Mon, 02 Feb 2009 20:41:29 +0000
parents a04b1c7167ba
children 7a0525613644
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Socket module */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 This module provides an interface to Berkeley socket IPC.
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Limitations:
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
16 Module interface:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 - an Internet socket address is a pair (hostname, port)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 where hostname can be anything recognized by gethostbyname()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 (including the dd.dd.dd.dd notation) and port is in host byte order
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a5e984eda45a Remove support for BeOS
Skip Montanaro <skip@pobox.com>
parents: 42622
diff changeset
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
6b012f01a889 Fix for VS 2008
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
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
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
385 #if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
532 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
723 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
729 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
753
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
865 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
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
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
938 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
944 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1125 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1143 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1176 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1225 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1226 addr->sin_family = AF_INET;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
1227 addr->sin_port = htons((short)port);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1228 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1229 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1230 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1231
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1232 #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
1233 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1234 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1235 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241 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
1242 "getsockaddrarg: "
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1243 "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
1244 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
1245 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
1246 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1247 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
1248 "idna", &host, &port, &flowinfo,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1249 &scope_id)) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1250 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1251 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1252 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
1253 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
1254 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
1255 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
1256 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
1257 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1258 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
1259 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
1260 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
1261 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
1262 *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
1263 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1264 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1265 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1266
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1267 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1268 case AF_BLUETOOTH:
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1269 {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1270 switch (s->sock_proto) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1271 case BTPROTO_L2CAP:
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1272 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1273 struct sockaddr_l2 *addr;
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1274 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1275
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1276 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
1277 _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
1278 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
1279 &_BT_L2_MEMB(addr, psm))) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1280 PyErr_SetString(socket_error, "getsockaddrarg: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1281 "wrong format");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1282 return 0;
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1283 }
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1284 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
1285 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1286
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1287 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1288 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1289 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1290 case BTPROTO_RFCOMM:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1291 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1292 struct sockaddr_rc *addr;
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1293 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1294
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1295 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
1296 _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
1297 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
1298 &_BT_RC_MEMB(addr, channel))) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1299 PyErr_SetString(socket_error, "getsockaddrarg: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1300 "wrong format");
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1301 return 0;
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1302 }
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1303 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
1304 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1305
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1306 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1307 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1308 }
40893
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1309 case BTPROTO_HCI:
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1310 {
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1311 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
1312 _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1313 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
1314 PyErr_SetString(socket_error, "getsockaddrarg: "
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1315 "wrong format");
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1316 return 0;
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1317 }
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1318 *len_ret = sizeof *addr;
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1319 return 1;
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1320 }
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1321 #if !defined(__FreeBSD__)
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1322 case BTPROTO_SCO:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1323 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1324 struct sockaddr_sco *addr;
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1325 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1326
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1327 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
1328 _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
1329 if (!PyBytes_Check(args)) {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1330 PyErr_SetString(socket_error, "getsockaddrarg: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1331 "wrong format");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1332 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1333 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
1334 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
1335 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
1336 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1337
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1338 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1339 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1340 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1341 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1342 default:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1343 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
1344 return 0;
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1345 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1346 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1347 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1348
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
1349 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1350 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1351 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1352 struct sockaddr_ll* addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1353 struct ifreq ifr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1354 char *interfaceName;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1355 int protoNumber;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1356 int hatype = 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1357 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
1358 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
1359 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
1360
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1361 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
1362 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
1363 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
1364 "getsockaddrarg: "
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1365 "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
1366 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
1367 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
1368 }
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
1369 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
1370 &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
1371 &haddr, &halen))
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1372 return 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1373 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
1374 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
1375 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
1376 s->errorhandler();
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1377 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
1378 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1379 if (halen > 8) {
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1380 PyErr_SetString(PyExc_ValueError,
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1381 "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
1382 return 0;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1383 }
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1384 addr = (struct sockaddr_ll*)addr_ret;
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1385 addr->sll_family = AF_PACKET;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1386 addr->sll_protocol = htons((short)protoNumber);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1387 addr->sll_ifindex = ifr.ifr_ifindex;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1388 addr->sll_pkttype = pkttype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1389 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
1390 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
1391 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
1392 }
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1393 addr->sll_halen = halen;
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1394 *len_ret = sizeof *addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1395 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1396 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1397 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1398
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1399 #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
1400 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
1401 {
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1402 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
1403 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
1404 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
1405
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1406 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
1407 PyErr_Format(
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1408 PyExc_TypeError,
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1409 "getsockaddrarg: "
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1410 "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
1411 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
1412 return 0;
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1413 }
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1414
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1415 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
1416 "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
1417 &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
1418 return 0;
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 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
1421 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
1422
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1423 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
1424 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
1425 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
1426
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1427 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
1428 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
1429 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
1430 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
1431 } 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
1432 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
1433 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
1434 } 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
1435 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
1436 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
1437 } else {
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1438 /* 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
1439 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
1440 return 0;
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1441 }
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1442
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1443 *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
1444
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1445 return 1;
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1446 }
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1447 #endif
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1448
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1449 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1450
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1451 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1452 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
1453 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1454
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1455 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1456 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1457
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1458
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1459 /* 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
1460 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
1461 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
1462
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1463 static int
13554
906efc1da247 Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13538
diff changeset
1464 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
1465 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1466 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
1467
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
1468 #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
1469 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
1470 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1471 *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
1472 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1473 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1474 #endif /* AF_UNIX */
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1475 #if defined(AF_NETLINK)
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1476 case AF_NETLINK:
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1477 {
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1478 *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
1479 return 1;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1480 }
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1481 #endif
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1482
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1483 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
1484 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1485 *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
1486 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1487 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1488
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1489 #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
1490 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1491 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1492 *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
1493 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1494 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1495 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1496
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1497 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1498 case AF_BLUETOOTH:
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1499 {
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1500 switch(s->sock_proto)
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1501 {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1502
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1503 case BTPROTO_L2CAP:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1504 *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
1505 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1506 case BTPROTO_RFCOMM:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1507 *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
1508 return 1;
40893
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1509 case BTPROTO_HCI:
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1510 *len_ret = sizeof (struct sockaddr_hci);
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
1511 return 1;
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1512 #if !defined(__FreeBSD__)
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1513 case BTPROTO_SCO:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1514 *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
1515 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1516 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1517 default:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1518 PyErr_SetString(socket_error, "getsockaddrlen: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1519 "unknown BT protocol");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1520 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1521
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1522 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1523 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1524 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1525
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
1526 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1527 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1528 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1529 *len_ret = sizeof (struct sockaddr_ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1530 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1531 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1532 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1533
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1534 #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
1535 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
1536 {
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1537 *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
1538 return 1;
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1539 }
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1540 #endif
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1541
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1542 /* 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
1543
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1544 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1545 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
1546 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1547
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1548 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1549 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1550
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1551
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
1552 /* s._accept() -> (fd, address) */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1553
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1554 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
1555 sock_accept(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1556 {
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
1557 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
1558 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
1559 socklen_t addrlen;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1560 PyObject *sock = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1561 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1562 PyObject *res = NULL;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1563 int timeout;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1564
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1565 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
1566 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
1567 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
1568
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1569 if (!IS_SELECTABLE(s))
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1570 return select_error();
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1571
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1572 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1573 timeout = internal_select(s, 0);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1574 if (!timeout)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1575 newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1576 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
1577
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1578 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1579 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1580 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1581 }
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1582
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1583 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
1584 return s->errorhandler();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1585
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
1586 sock = PyLong_FromSocket_t(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1587 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
1588 SOCKETCLOSE(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1589 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1590 }
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
1591
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1592 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
1593 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
1594 if (addr == NULL)
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1595 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1596
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30646
diff changeset
1597 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
1598
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1599 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1600 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1601 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1602 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1603 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1604
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1605 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
1606 "_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
1607 \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
1608 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
1609 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
1610 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
1611
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1612 /* s.setblocking(flag) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1613 False -- non-blocking mode; same as settimeout(0)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1614 True -- blocking mode; same as settimeout(None)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1615 */
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1616
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1617 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
1618 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
1619 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1620 int block;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1621
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
1622 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
1623 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
1624 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1625
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1626 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
1627 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
1628
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1629 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1630 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
1631 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1632
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1633 PyDoc_STRVAR(setblocking_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1634 "setblocking(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1635 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1636 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
1637 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
1638 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
1639
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1640 /* s.settimeout(timeout) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1641 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
1642 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
1643 > 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
1644 < 0 -- illegal; raises an exception
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1645 */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1646 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
1647 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
1648 {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1649 double timeout;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1650
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1651 if (arg == Py_None)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1652 timeout = -1.0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1653 else {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1654 timeout = PyFloat_AsDouble(arg);
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1655 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
1656 if (!PyErr_Occurred())
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1657 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1658 "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
1659 return NULL;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1660 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1661 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1662
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1663 s->sock_timeout = timeout;
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1664 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
1665
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1666 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1667 return Py_None;
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
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1670 PyDoc_STRVAR(settimeout_doc,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1671 "settimeout(timeout)\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1672 \n\
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1673 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
1674 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
1675 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
1676 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
1677
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1678 /* s.gettimeout() method.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1679 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
1680 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
1681 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
1682 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1683 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
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 else
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1688 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
1689 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1690
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1691 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
1692 "gettimeout() -> timeout\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1693 \n\
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1694 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
1695 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
1696 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
1697
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
1698 /* 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
1699 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
1700 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
1701 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
1702
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1703 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
1704 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
1705 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1706 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1707 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
1708 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
1709 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
1710 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1711 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1712
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1713 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
1714 &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
1715 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
1716 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
1717 }
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 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1719 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
1720 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
1721 &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
1722 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
1723 }
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
1724 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
1725 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
1726 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1727 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1728 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1729 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1730
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1731 PyDoc_STRVAR(setsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1732 "setsockopt(level, option, value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1733 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1734 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
1735 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
1736
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1737
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
1738 /* 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
1739 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
1740 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
1741 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
1742
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1743 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
1744 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
1745 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1746 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1747 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
1748 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1749 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
1750 socklen_t buflen = 0;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1751
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1752 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
1753 &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
1754 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1755
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
1756 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
1757 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
1758 socklen_t flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1759 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
1760 (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
1761 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
1762 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
1763 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
1764 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1765 #ifdef __VMS
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1766 /* 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
1767 test buflen == 0 is previously done */
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1768 if (buflen > 1024) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1769 #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
1770 if (buflen <= 0 || buflen > 1024) {
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1771 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1772 PyErr_SetString(socket_error,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1773 "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
1774 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
1775 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
1776 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
1777 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
1778 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1779 res = getsockopt(s->sock_fd, level, optname,
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
1780 (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
1781 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1782 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
1783 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
1784 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
1785 _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
1786 return buf;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1787 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1788
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1789 PyDoc_STRVAR(getsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1790 "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
1791 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1792 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
1793 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
1794 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
1795
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1796
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1797 /* s.bind(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1798
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1799 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
1800 sock_bind(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1801 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1802 sock_addr_t addrbuf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1803 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1804 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
1805
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1806 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1807 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1808 Py_BEGIN_ALLOW_THREADS
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1809 res = bind(s->sock_fd, SAS2SA(&addrbuf), addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1810 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1811 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
1812 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1813 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1814 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1815 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1816
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1817 PyDoc_STRVAR(bind_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1818 "bind(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1819 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1820 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
1821 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
1822 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
1823
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1824
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1825 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1826 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
1827 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1828
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1829 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
1830 sock_close(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1831 {
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
1832 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
1833
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
1834 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
1835 s->sock_fd = -1;
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1836 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
1837 (void) SOCKETCLOSE(fd);
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1838 Py_END_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1839 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1840 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1841 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1842 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1843
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1844 PyDoc_STRVAR(close_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1845 "close()\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1846 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1847 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
1848
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1849 static int
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1850 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
1851 int *timeoutp)
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1852 {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1853 int res, timeout;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1854
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1855 timeout = 0;
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1856 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
1857
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1858 #ifdef MS_WINDOWS
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1859
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1860 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
1861 if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK &&
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1862 IS_SELECTABLE(s)) {
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1863 /* 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
1864 fd_set fds;
32909
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1865 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
1866 struct timeval tv;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1867 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
1868 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
1869 FD_ZERO(&fds);
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1870 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
1871 FD_ZERO(&fds_exc);
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1872 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
1873 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
1874 if (res == 0) {
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1875 res = WSAEWOULDBLOCK;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1876 timeout = 1;
32909
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1877 } else if (res > 0) {
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1878 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
1879 /* 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
1880 means connected */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1881 res = 0;
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1882 else {
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1883 /* 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
1884 to get the underlying error */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1885 int res_size = sizeof res;
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1886 /* 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
1887 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
1888 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
1889 (char *)&res, &res_size))
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1890 /* getsockopt also clears WSAGetLastError,
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1891 so reset it back. */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1892 WSASetLastError(res);
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1893 else
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1894 res = WSAGetLastError();
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1895 }
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1896 }
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1897 /* 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
1898 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1899 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1900
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1901 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1902 res = WSAGetLastError();
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1903
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1904 #else
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1905
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1906 if (s->sock_timeout > 0.0) {
44810
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1907 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
1908 timeout = internal_select(s, 1);
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1909 if (timeout == 0) {
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1910 /* Bug #1019808: in case of an EINPROGRESS,
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1911 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
1912 error. */
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1913 socklen_t res_size = sizeof res;
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1914 (void)getsockopt(s->sock_fd, SOL_SOCKET,
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1915 SO_ERROR, &res, &res_size);
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1916 if (res == EISCONN)
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1917 res = 0;
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1918 errno = res;
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1919 }
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1920 else if (timeout == -1) {
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1921 res = errno; /* had error */
fa6cee14dcba Merged revisions 60094-60123 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44674
diff changeset
1922 }
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1923 else
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1924 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
1925 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1926 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1927
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1928 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1929 res = errno;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1930
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1931 #endif
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1932 *timeoutp = timeout;
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1933
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1934 return res;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1935 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1936
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1937 /* s.connect(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1938
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1939 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
1940 sock_connect(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1941 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1942 sock_addr_t addrbuf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1943 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1944 int res;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1945 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
1946
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1947 if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1948 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1949
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1950 Py_BEGIN_ALLOW_THREADS
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1951 res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1952 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
1953
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1954 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1955 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1956 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1957 }
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1958 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
1959 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1960 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1961 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1962 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1963
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1964 PyDoc_STRVAR(connect_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1965 "connect(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1966 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1967 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
1968 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
1969
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1970
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1971 /* 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
1972
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1973 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
1974 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
1975 {
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1976 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
1977 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
1978 int res;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1979 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
1980
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1981 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
1982 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1983
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1984 Py_BEGIN_ALLOW_THREADS
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
1985 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
1986 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
1987
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1988 /* 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
1989 from PyErr_SetFromErrnoWithFilenameObject(). */
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1990 #ifdef EINTR
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1991 if (res == EINTR && PyErr_CheckSignals())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1992 return NULL;
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1993 #endif
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1994
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
1995 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
1996 }
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1997
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1998 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
1999 "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
2000 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2001 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
2002 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
2003
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
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
2005 /* 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
2006
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2007 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
2008 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
2009 {
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
2010 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
2011 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
2012
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2013 PyDoc_STRVAR(fileno_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2014 "fileno() -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2015 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2016 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
2017
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
2018
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2019 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2020
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2021 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
2022 sock_getsockname(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2023 {
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
2024 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
2025 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
2026 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
2027
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2028 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2029 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
2030 memset(&addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2031 Py_BEGIN_ALLOW_THREADS
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2032 res = getsockname(s->sock_fd, SAS2SA(&addrbuf), &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2033 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2034 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
2035 return s->errorhandler();
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2036 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
2037 s->sock_proto);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2038 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2039
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2040 PyDoc_STRVAR(getsockname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2041 "getsockname() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2042 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2043 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
2044 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
2045
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2046
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2047 #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
2048 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2049
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2050 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
2051 sock_getpeername(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2052 {
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
2053 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
2054 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
2055 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
2056
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2057 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2058 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
2059 memset(&addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2060 Py_BEGIN_ALLOW_THREADS
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2061 res = getpeername(s->sock_fd, SAS2SA(&addrbuf), &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2062 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2063 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
2064 return s->errorhandler();
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2065 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
2066 s->sock_proto);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2067 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2068
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2069 PyDoc_STRVAR(getpeername_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2070 "getpeername() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2071 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2072 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
2073 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
2074
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2075 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2076
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2077
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2078 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2079
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2080 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
2081 sock_listen(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2082 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2083 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2084 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
2085
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
2086 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
2087 if (backlog == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2088 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2089 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2090 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2091 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2092 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2093 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2094 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
2095 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2096 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2097 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2098 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2099
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2100 PyDoc_STRVAR(listen_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2101 "listen(backlog)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2102 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2103 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
2104 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
2105 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
2106
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2107
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2108 /*
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2109 * 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
2110 * 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
2111 * 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
2112 * 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
2113 * 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
2114 * bytes.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2115 */
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2116 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
2117 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
2118 {
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2119 ssize_t outlen = -1;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2120 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
2121 #ifdef __VMS
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2122 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
2123 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
2124 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2125
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2126 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
2127 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
2128 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
2129 }
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
2130 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
2131 /* 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
2132 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
2133 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2134
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2135 #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
2136 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
2137 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
2138 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
2139 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
2140 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
2141
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2142 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
2143 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
2144 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
2145 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2146 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
2147 /* 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
2148 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
2149 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
2150 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
2151 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2152 #else
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2153 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
2154 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
2155 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
2156 unsigned int segment;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2157 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
2158
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2159 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
2160 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
2161 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
2162 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2163 else {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2164 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
2165 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2166
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2167 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
2168 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
2169 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
2170 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
2171 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
2172
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2173 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
2174 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
2175 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
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 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
2178 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
2179 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
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 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
2182 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
2183 break;
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
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2186 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
2187 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
2188 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2189 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
2190 #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
2191
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2192 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
2193 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2194
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2195
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
2196 /* 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
2197
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2198 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
2199 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
2200 {
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2201 int recvlen, flags = 0;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2202 ssize_t outlen;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2203 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
2204
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2205 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
2206 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2207
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2208 if (recvlen < 0) {
21022
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
2209 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
2210 "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
2211 return NULL;
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
2212 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2213
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2214 /* Allocate a new string. */
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2215 buf = PyBytes_FromStringAndSize((char *) 0, recvlen);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2216 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2217 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2218
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2219 /* Call the guts */
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2220 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
2221 if (outlen < 0) {
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2222 /* 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
2223 error. */
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2224 Py_DECREF(buf);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2225 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2226 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2227 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
2228 /* We did not read as many bytes as we anticipated, resize the
42709
9e81b22689d2 Fix typo in comment
Kurt B. Kaiser <kbk@shore.net>
parents: 42645
diff changeset
2229 string if possible and be successful. */
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2230 _PyBytes_Resize(&buf, outlen);
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
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
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2233 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2234 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2235
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2236 PyDoc_STRVAR(recv_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2237 "recv(buffersize[, flags]) -> data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2238 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2239 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
2240 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
2241 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
2242 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
2243
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2244
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2245 /* 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
2246
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2247 static PyObject*
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2248 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
2249 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2250 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
2251
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2252 int recvlen = 0, flags = 0;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2253 ssize_t readlen;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2254 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
2255 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
2256 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
2257
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2258 /* 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
2259 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
2260 &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
2261 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2262 buf = pbuf.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2263 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
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 if (recvlen < 0) {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2266 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
2267 PyErr_SetString(PyExc_ValueError,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2268 "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
2269 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
2270 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2271 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
2272 /* 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
2273 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
2274 }
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 /* 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
2277 if (buflen < recvlen) {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2278 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
2279 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
2280 "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
2281 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
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
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2284 /* 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
2285 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
2286 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
2287 /* Return an error. */
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2288 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
2289 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
2290 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2291
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2292 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
2293 /* 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
2294 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
2295 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
2296 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2297
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2298 PyDoc_STRVAR(recv_into_doc,
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2299 "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
2300 \n\
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2301 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
2302 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
2303 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
2304 \n\
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2305 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
2306
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2307
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2308 /*
44349
4dc01402d78a Merged revisions 59541-59561 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44158
diff changeset
2309 * 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
2310 * 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
2311 * 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
2312 * 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
2313 * 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
2314 * 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
2315 *
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2316 * '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
2317 * 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
2318 */
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2319 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
2320 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
2321 PyObject** addr)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2322 {
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
2323 sock_addr_t addrbuf;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2324 int timeout;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2325 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
2326 socklen_t addrlen;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2327
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2328 *addr = NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2329
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
2330 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
2331 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
2332
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2333 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
2334 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
2335 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
2336 }
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2337
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2338 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
2339 memset(&addrbuf, 0, addrlen);
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2340 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
2341 if (!timeout) {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2342 #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
2343 #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
2344 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
2345 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
2346 #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
2347 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
2348 (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
2349 #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
2350 #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
2351 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
2352 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
2353 #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
2354 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2355 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
2356
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2357 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2358 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
2359 return -1;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2360 }
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
2361 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
2362 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
2363 return -1;
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
2364 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2365
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2366 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
2367 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
2368 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
2369
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2370 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
2371 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2372
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2373 /* 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
2374
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2375 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
2376 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
2377 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2378 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
2379 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
2380 PyObject *ret = NULL;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2381 int recvlen, flags = 0;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2382 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
2383
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2384 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2385 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2386
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2387 if (recvlen < 0) {
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2388 PyErr_SetString(PyExc_ValueError,
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2389 "negative buffersize in recvfrom");
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2390 return NULL;
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2391 }
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2392
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2393 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
2394 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
2395 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
2396
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2397 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
2398 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
2399 if (outlen < 0) {
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2400 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
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
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2403 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
2404 /* 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
2405 string if possible and be succesful. */
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
2406 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
2407 /* 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
2408 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
2409 }
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2410
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30646
diff changeset
2411 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
2412
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2413 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
2414 Py_XDECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2415 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
2416 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2417 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2418
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2419 PyDoc_STRVAR(recvfrom_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2420 "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
2421 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2422 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
2423
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2424
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2425 /* 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
2426
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2427 static PyObject *
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2428 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
2429 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2430 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
2431
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2432 int recvlen = 0, flags = 0;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2433 ssize_t readlen;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2434 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
2435 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
2436 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
2437
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2438 PyObject *addr = NULL;
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2439
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2440 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
2441 kwlist, &pbuf,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2442 &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
2443 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2444 buf = pbuf.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2445 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
2446 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
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 if (recvlen < 0) {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2449 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
2450 PyErr_SetString(PyExc_ValueError,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40893
diff changeset
2451 "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
2452 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
2453 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2454 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
2455 /* 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
2456 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
2457 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2458
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2459 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
2460 if (readlen < 0) {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2461 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
2462 /* Return an error */
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2463 Py_XDECREF(addr);
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2464 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
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
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 /* 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
2469 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
2470 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
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
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2473 PyDoc_STRVAR(recvfrom_into_doc,
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2474 "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
2475 \n\
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2476 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
2477
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2478
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
2479 /* 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
2480
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2481 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
2482 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
2483 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2484 char *buf;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2485 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
2486 Py_buffer pbuf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2487
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2488 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
2489 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2490
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2491 if (!IS_SELECTABLE(s)) {
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2492 PyBuffer_Release(&pbuf);
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2493 return select_error();
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2494 }
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2495 buf = pbuf.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2496 len = pbuf.len;
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2497
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2498 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2499 timeout = internal_select(s, 1);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2500 if (!timeout)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2501 #ifdef __VMS
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2502 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
2503 #else
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2504 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
2505 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2506 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
2507
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2508 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2509
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2510 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2511 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2512 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2513 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2514 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
2515 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
2516 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
2517 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2518
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2519 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
2520 "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
2521 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2522 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
2523 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
2524 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
2525
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2526
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2527 /* 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
2528
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2529 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
2530 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
2531 {
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2532 char *buf;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2533 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
2534 Py_buffer pbuf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2535
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2536 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
2537 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2538 buf = pbuf.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2539 len = pbuf.len;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2540
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2541 if (!IS_SELECTABLE(s)) {
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2542 PyBuffer_Release(&pbuf);
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2543 return select_error();
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2544 }
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2545
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2546 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
2547 do {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2548 timeout = internal_select(s, 1);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2549 n = -1;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2550 if (timeout)
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2551 break;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2552 #ifdef __VMS
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2553 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
2554 #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
2555 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
2556 #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
2557 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
2558 break;
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2559 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
2560 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
2561 } 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
2562 Py_END_ALLOW_THREADS
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2563 PyBuffer_Release(&pbuf);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2564
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2565 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2566 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2567 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2568 }
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2569 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
2570 return s->errorhandler();
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2571
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2572 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
2573 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
2574 }
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2575
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2576 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
2577 "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
2578 \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 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
2580 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
2581 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
2582 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
2583
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2584
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
2585 /* 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
2586
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2587 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
2588 sock_sendto(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2589 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2590 Py_buffer pbuf;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2591 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2592 char *buf;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2593 Py_ssize_t len;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2594 sock_addr_t addrbuf;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2595 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
2596
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
2597 flags = 0;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2598 if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2599 PyErr_Clear();
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2600 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
2601 &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
2602 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2603 }
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2604 buf = pbuf.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2605 len = pbuf.len;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2606
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2607 if (!IS_SELECTABLE(s)) {
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2608 PyBuffer_Release(&pbuf);
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2609 return select_error();
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2610 }
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2611
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2612 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
2613 PyBuffer_Release(&pbuf);
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2614 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2615 }
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2616
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2617 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2618 timeout = internal_select(s, 1);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2619 if (!timeout)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2620 n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2621 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
2622
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 48660
diff changeset
2623 PyBuffer_Release(&pbuf);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
2624 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2625 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2626 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2627 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2628 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
2629 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
2630 return PyLong_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2631 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2632
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2633 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
2634 "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
2635 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2636 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
2637 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
2638
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2639
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2640 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2641
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2642 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
2643 sock_shutdown(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2644 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2645 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2646 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
2647
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 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
2649 if (how == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2650 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2651 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2652 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2653 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2654 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
2655 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2656 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2657 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2658 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2659
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2660 PyDoc_STRVAR(shutdown_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2661 "shutdown(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2662 \n\
31027
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
2663 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
2664 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
2665
47667
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47663
diff changeset
2666 #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
2667 static PyObject*
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2668 sock_ioctl(PySocketSockObject *s, PyObject *arg)
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2669 {
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2670 unsigned long cmd = SIO_RCVALL;
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2671 unsigned int option = RCVALL_ON;
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2672 DWORD recv;
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2673
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2674 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
2675 return NULL;
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2676
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2677 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
2678 NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) {
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2679 return set_error();
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2680 }
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2681 return PyLong_FromUnsignedLong(recv);
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2682 }
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2683 PyDoc_STRVAR(sock_ioctl_doc,
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2684 "ioctl(cmd, option) -> long\n\
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2685 \n\
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2686 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
2687 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
2688 constants.");
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2689
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2690 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2691
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2692 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2693
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2694 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
2695 {"_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
2696 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
2697 {"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
2698 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
2699 {"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
2700 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
2701 {"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
2702 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
2703 {"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
2704 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
2705 {"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
2706 fileno_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2707 #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
2708 {"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
2709 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
2710 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
2711 {"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
2712 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
2713 {"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
2714 getsockopt_doc},
47667
b1f4ea4eb555 Merged revisions 64214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47663
diff changeset
2715 #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
2716 {"ioctl", (PyCFunction)sock_ioctl, METH_VARARGS,
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2717 sock_ioctl_doc},
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
2718 #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
2719 {"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
2720 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
2721 {"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
2722 recv_doc},
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2723 {"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
2724 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
2725 {"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
2726 recvfrom_doc},
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
2727 {"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
2728 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
2729 {"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
2730 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
2731 {"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
2732 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
2733 {"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
2734 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
2735 {"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
2736 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
2737 {"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
2738 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
2739 {"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
2740 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
2741 {"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
2742 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
2743 {"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
2744 shutdown_doc},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2745 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2746 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2747
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
2748 /* 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
2749 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
2750 {"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
2751 {"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
2752 {"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
2753 {"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
2754 {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
2755 };
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2756
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2757 /* 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
2758 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2759
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2760 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
2761 sock_dealloc(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2762 {
12319
57f34e162e67 In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents: 12229
diff changeset
2763 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
2764 (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
2765 Py_TYPE(s)->tp_free((PyObject *)s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2766 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2767
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2768
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2769 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
2770 sock_repr(PySocketSockObject *s)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2771 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2772 #if SIZEOF_SOCKET_T > SIZEOF_LONG
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2773 if (s->sock_fd > LONG_MAX) {
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2774 /* 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
2775 ugly printf formatter for decimal pointer length integer
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2776 printing, only bother if necessary*/
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2777 PyErr_SetString(PyExc_OverflowError,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2778 "no printf formatter to display "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2779 "the socket descriptor in decimal");
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2780 return NULL;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2781 }
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2782 #endif
41941
e4ab08039c75 Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents: 41809
diff changeset
2783 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
2784 "<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
2785 (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
2786 s->sock_type,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2787 s->sock_proto);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2788 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2789
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2790
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2791 /* 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
2792
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2793 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
2794 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
2795 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2796 PyObject *new;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2797
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2798 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
2799 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
2800 ((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
2801 ((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
2802 ((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
2803 }
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2804 return new;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2805 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2806
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2807
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2808 /* 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
2809
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2810 /*ARGSUSED*/
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2811 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
2812 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
2813 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2814 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
2815 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
2816 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
2817 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
2818 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
2819
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2820 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
2821 "|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
2822 &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
2823 return -1;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2824
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
2825 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
2826 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
2827 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
2828 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
2829 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
2830 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
2831 "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
2832 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
2833 }
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
2834 }
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
2835 else {
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
2836 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
2837 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
2838 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
2839
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
2840 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
2841 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
2842 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
2843 }
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2844 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2845 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
2846
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2847 return 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2848
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2849 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2850
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2851
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2852 /* 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
2853
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2854 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
2855 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
2856 "_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
2857 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
2858 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
2859 (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
2860 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
2861 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
2862 0, /* tp_setattr */
51271
87fbbf22adf3 Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50812
diff changeset
2863 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
2864 (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
2865 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
2866 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
2867 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
2868 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
2869 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
2870 0, /* tp_str */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2871 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
2872 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
2873 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
2874 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
2875 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
2876 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
2877 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
2878 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
2879 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
2880 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
2881 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
2882 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
2883 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
2884 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
2885 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
2886 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
2887 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
2888 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
2889 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
2890 sock_initobj, /* tp_init */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2891 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
2892 sock_new, /* tp_new */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2893 PyObject_Del, /* tp_free */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2894 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2895
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2896
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2897 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2898
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2899 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2900 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
2901 socket_gethostname(PyObject *self, PyObject *unused)
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2902 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2903 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2904 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2905 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2906 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2907 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2908 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
2909 return set_error();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2910 buf[sizeof buf - 1] = '\0';
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
2911 return PyUnicode_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2912 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2913
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2914 PyDoc_STRVAR(gethostname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2915 "gethostname() -> string\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2916 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2917 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
2918
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2919
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2920 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2921
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2922 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2923 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
2924 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
2925 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2926 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
2927 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
2928
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2929 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
2930 return NULL;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2931 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
2932 return NULL;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39610
diff changeset
2933 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
2934 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2935
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2936 PyDoc_STRVAR(gethostbyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2937 "gethostbyname(host) -> address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2938 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2939 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
2940
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2941
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2942 /* 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
2943
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2944 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2945 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
2946 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2947 char **pch;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2948 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
2949 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
2950 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
2951 PyObject *tmp;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2952
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2953 if (h == NULL) {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2954 /* 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
2955 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
2956 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2957 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2958
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2959 if (h->h_addrtype != af) {
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2960 /* 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
2961 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2962 (char *)strerror(EAFNOSUPPORT));
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44905
diff changeset
2963
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2964 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2965 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2966
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2967 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2968
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2969 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2970 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
2971 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2972 break;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2973
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
2974 #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
2975 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2976 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
2977 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2978 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2979 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2980
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2981 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2982
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2983 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
2984 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2985
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2986 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
2987 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2988
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2989 /* 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
2990 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
2991 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
2992 int status;
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
2993 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
2994 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
2995 goto err;
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2996
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
2997 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
2998 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
2999
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
3000 if (status)
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
3001 goto err;
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
3002 }
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3003 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3004
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3005 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
3006 int status;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3007
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3008 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3009
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3010 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3011 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3012 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
3013 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
3014 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
3015 #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
3016 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
3017 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3018 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
3019 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
3020
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3021 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
3022 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
3023 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3024 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3025
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3026 #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
3027 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3028 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3029 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
3030 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
3031 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
3032 #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
3033 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
3034 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3035 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
3036 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
3037 sizeof(sin6));
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(sin6))
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, &sin6, sizeof(sin6));
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 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3043 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3044
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3045 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
3046 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3047 "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
3048 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3049 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3050
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3051 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
3052 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3053
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3054 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
3055 Py_DECREF(tmp);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3056
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3057 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3058 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3059 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3060
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3061 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
3062
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3063 err:
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3064 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
3065 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
3066 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
3067 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3068
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3069
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3070 /* 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
3071
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3072 /*ARGSUSED*/
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3073 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
3074 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
3075 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3076 char *name;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3077 struct hostent *h;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3078 #ifdef ENABLE_IPV6
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3079 struct sockaddr_storage addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3080 #else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3081 struct sockaddr_in addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3082 #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
3083 struct sockaddr *sa;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3084 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
3085 #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
3086 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
3087 #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
3088 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
3089 #else
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3090 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
3091 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
3092 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3093 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3094 #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
3095 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
3096 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3097 #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
3098
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3099 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
3100 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
3101 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
3102 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3103 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
3104 #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
3105 #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
3106 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
3107 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3108 #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
3109 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
3110 #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
3111 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
3112 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
3113 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
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 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3116 #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
3117 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
3118 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3119 h = gethostbyname(name);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3120 #endif /* HAVE_GETHOSTBYNAME_R */
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3121 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
3122 /* 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
3123 addr.ss_family.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3124 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
3125 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
3126 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
3127 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
3128 sa->sa_family);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3129 #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
3130 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
3131 #endif
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3132 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
3133 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3134
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3135 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
3136 "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
3137 \n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3138 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
3139 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
3140
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3141
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3142 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3143
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3144 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3145 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
3146 socket_gethostbyaddr(PyObject *self, PyObject *args)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3147 {
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3148 #ifdef ENABLE_IPV6
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3149 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
3150 #else
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3151 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
3152 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3153 struct sockaddr *sa = (struct sockaddr *)&addr;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3154 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3155 struct hostent *h;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3156 PyObject *ret;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3157 #ifdef HAVE_GETHOSTBYNAME_R
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3158 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
3159 #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
3160 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
3161 #else
50812
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48683
diff changeset
3162 /* 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
3163 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
3164 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
3165 to maintain this alignment. */
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48683
diff changeset
3166 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
3167 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
3168 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3169 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3170 #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
3171 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
3172 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3173 #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
3174 char *ap;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3175 int al;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3176 int af;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3177
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3178 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
3179 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
3180 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
3181 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
3182 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3183 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
3184 ap = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3185 al = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3186 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3187 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3188 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
3189 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
3190 break;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3191 #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
3192 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3193 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
3194 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
3195 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3196 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3197 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3198 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
3199 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3200 }
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3201 Py_BEGIN_ALLOW_THREADS
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3202 #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
3203 #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
3204 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
3205 &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
3206 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3207 #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
3208 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
3209 &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
3210 #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
3211 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
3212 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
3213 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
3214 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3215 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3216 #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
3217 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
3218 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3219 h = gethostbyaddr(ap, al, af);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3220 #endif /* HAVE_GETHOSTBYNAME_R */
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3221 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
3222 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
3223 #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
3224 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
3225 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3226 return ret;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3227 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3228
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3229 PyDoc_STRVAR(gethostbyaddr_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3230 "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
3231 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3232 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
3233 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
3234
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3235
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3236 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3237 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
3238 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
3239
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3240 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3241 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
3242 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
3243 {
32429
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3244 char *name, *proto=NULL;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3245 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
3246 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
3247 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3248 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
3249 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3250 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3251 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
3252 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
3253 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3254 }
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
3255 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
3256 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3257
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3258 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
3259 "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
3260 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3261 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
3262 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
3263 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
3264
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3265
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3266 /* 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
3267 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
3268 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
3269
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3270 /*ARGSUSED*/
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3271 static PyObject *
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3272 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
3273 {
33606
4d7b0d206bc7 Silence a compiler warning by supplying the correct argument type to
Raymond Hettinger <python@rcn.com>
parents: 33478
diff changeset
3274 unsigned short port;
32429
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3275 char *proto=NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3276 struct servent *sp;
33606
4d7b0d206bc7 Silence a compiler warning by supplying the correct argument type to
Raymond Hettinger <python@rcn.com>
parents: 33478
diff changeset
3277 if (!PyArg_ParseTuple(args, "H|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
3278 return NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3279 Py_BEGIN_ALLOW_THREADS
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3280 sp = getservbyport(htons(port), proto);
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3281 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
3282 if (sp == NULL) {
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3283 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
3284 return NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3285 }
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3286 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
3287 }
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3288
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3289 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
3290 "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
3291 \n\
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3292 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
3293 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
3294 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
3295
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3296 /* Python interface to getprotobyname(name).
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3297 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
3298 already known or not useful (like the list of aliases). */
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3299
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3300 /*ARGSUSED*/
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3301 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
3302 socket_getprotobyname(PyObject *self, PyObject *args)
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3303 {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3304 char *name;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3305 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
3306 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3307 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3308 Py_BEGIN_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3309 sp = getprotobyname(name);
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3310 Py_END_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3311 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
3312 PyErr_SetString(socket_error, "protocol not found");
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3313 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3314 }
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
3315 return PyLong_FromLong((long) sp->p_proto);
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3316 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3317
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3318 PyDoc_STRVAR(getprotobyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3319 "getprotobyname(name) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3320 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3321 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
3322
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3323
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
3324 #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
3325 /* 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
3326
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3327 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
3328 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
3329 {
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3330 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
3331 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
3332
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3333
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3334 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
3335 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
3336 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
3337
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3338 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
3339 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
3340 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
3341
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3342 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
3343 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
3344 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
3345 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
3346 }
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43877
diff changeset
3347
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 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
3349 "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
3350 \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
3351 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
3352 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
3353 #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
3354
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
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3356 #ifdef HAVE_SOCKETPAIR
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3357 /* 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
3358 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
3359 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
3360
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3361 /*ARGSUSED*/
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3362 static PyObject *
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3363 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
3364 {
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3365 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
3366 SOCKET_T sv[2];
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3367 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
3368 PyObject *res = NULL;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3369
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3370 #if defined(AF_UNIX)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3371 family = AF_UNIX;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3372 #else
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3373 family = AF_INET;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3374 #endif
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3375 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
3376 &family, &type, &proto))
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3377 return NULL;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3378 /* 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
3379 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
3380 return set_error();
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3381 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
3382 if (s0 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3383 goto finally;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3384 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
3385 if (s1 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3386 goto finally;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3387 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
3388
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3389 finally:
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3390 if (res == NULL) {
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3391 if (s0 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3392 SOCKETCLOSE(sv[0]);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3393 if (s1 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3394 SOCKETCLOSE(sv[1]);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3395 }
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3396 Py_XDECREF(s0);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3397 Py_XDECREF(s1);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3398 return res;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3399 }
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3400
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3401 PyDoc_STRVAR(socketpair_doc,
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3402 "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
3403 \n\
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3404 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
3405 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
3406 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
3407 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
3408
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3409 #endif /* HAVE_SOCKETPAIR */
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3410
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3411
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3412 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
3413 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
3414 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3415 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3416
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3417 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
3418 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3419 }
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3420 if (x1 < 0) {
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3421 PyErr_SetString(PyExc_OverflowError,
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3422 "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
3423 return NULL;
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3424 }
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3425 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
3426 return PyLong_FromLong(x2);
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3427 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3428
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3429 PyDoc_STRVAR(ntohs_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3430 "ntohs(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3431 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3432 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
3433
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3434
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3435 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3436 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
3437 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3438 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3439
40626
4aee3f672f77 Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents: 40582
diff changeset
3440 if (PyLong_Check(arg)) {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3441 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
3442 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
3443 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3444 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3445 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3446 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3447 /* 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
3448 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3449 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3450 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3451 "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
3452 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3453 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3454 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3455 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3456 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3457 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
3458 "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
3459 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
3460 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
3461 return NULL;
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3462 return PyLong_FromUnsignedLong(ntohl(x));
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3463 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3464
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3465 PyDoc_STRVAR(ntohl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3466 "ntohl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3467 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3468 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
3469
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3470
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3471 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
3472 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
3473 {
31207
f388e83f8e43 Fix erroneus argument parsing of socket.htons() on 64bit big endian
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31027
diff changeset
3474 int x1, x2;
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3475
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3476 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
3477 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3478 }
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3479 if (x1 < 0) {
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3480 PyErr_SetString(PyExc_OverflowError,
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3481 "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
3482 return NULL;
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3483 }
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3484 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
3485 return PyLong_FromLong(x2);
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3486 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3487
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3488 PyDoc_STRVAR(htons_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3489 "htons(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3490 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3491 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
3492
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3493
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3494 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3495 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
3496 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3497 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3498
40626
4aee3f672f77 Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents: 40582
diff changeset
3499 if (PyLong_Check(arg)) {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3500 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
3501 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
3502 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3503 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3504 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3505 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3506 /* 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
3507 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3508 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3509 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3510 "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
3511 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3512 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3513 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3514 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3515 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3516 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
3517 "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
3518 Py_TYPE(arg)->tp_name);
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40626
diff changeset
3519 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
3520 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3521
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3522 PyDoc_STRVAR(htonl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3523 "htonl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3524 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3525 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
3526
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3527 /* 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
3528
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3529 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
3530 "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
3531 \n\
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3532 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
3533 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
3534
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3535 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
3536 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
3537 {
11268
3fe8d13328c8 It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents: 11219
diff changeset
3538 #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
3539 #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
3540 #endif
27858
9453d8cdd01e Ummm, try to get it right this time
Neal Norwitz <nnorwitz@gmail.com>
parents: 27857
diff changeset
3541 #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
3542 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
3543 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3544
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3545 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK)
27861
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3546 /* Have to use inet_addr() instead */
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3547 unsigned long packed_addr;
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3548 #endif
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3549 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
3550
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3551 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
3552 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
3553
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3554
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3555 #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
3556
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3557 #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
3558 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
3559 #endif
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3560 if (inet_aton(ip_addr, &buf))
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3561 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
3562 sizeof(buf));
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3563
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3564 PyErr_SetString(socket_error,
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3565 "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
3566 return NULL;
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3567
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3568 #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
3569 } else {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3570 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3571
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3572 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3573
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3574 #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
3575
35452
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3576 /* 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
3577 * 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
3578 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
3579 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
3580 } 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
3581
35452
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3582 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
3583
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3584 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
3585 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
3586 "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
3587 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
3588 }
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3589 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3590 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
3591 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
3592
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3593 #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
3594 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3595 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3596
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3597 #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
3598 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3599
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3600 PyDoc_STRVAR(inet_ntoa_doc,
11937
ef98ee6aeb42 Fixed inet_ntoa() docstring.
Fred Drake <fdrake@acm.org>
parents: 11882
diff changeset
3601 "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
3602 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3603 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
3604
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3605 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
3606 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
3607 {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3608 char *packed_str;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3609 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
3610 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
3611
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3612 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
3613 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
3614 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3615
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3616 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
3617 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
3618 "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
3619 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
3620 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3621
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3622 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
3623
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3624 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
3625 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3626
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3627 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3628
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3629 PyDoc_STRVAR(inet_pton_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3630 "inet_pton(af, ip) -> packed IP address string\n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3631 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3632 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
3633 for use with low-level network functions.");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3634
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3635 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3636 socket_inet_pton(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3637 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3638 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3639 char* ip;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3640 int retval;
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3641 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3642 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
3643 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3644 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
3645 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3646 if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3647 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3648 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3649
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
3650 #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
3651 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
3652 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
3653 "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
3654 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
3655 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3656 #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
3657
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3658 retval = inet_pton(af, ip, packed);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3659 if (retval < 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3660 PyErr_SetFromErrno(socket_error);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3661 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3662 } else if (retval == 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3663 PyErr_SetString(socket_error,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3664 "illegal IP address string passed to inet_pton");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3665 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3666 } else if (af == AF_INET) {
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3667 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
3668 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
3669 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3670 } else if (af == AF_INET6) {
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3671 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
3672 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
3673 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3674 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3675 PyErr_SetString(socket_error, "unknown address family");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3676 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3677 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3678 }
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
3679
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3680 PyDoc_STRVAR(inet_ntop_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3681 "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
3682 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3683 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
3684
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3685 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3686 socket_inet_ntop(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3687 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3688 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3689 char* packed;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3690 int len;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3691 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
3692 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3693 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
3694 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3695 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
3696 #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
3697
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3698 /* 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
3699 memset((void *) &ip[0], '\0', sizeof(ip));
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3700
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3701 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
3702 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3703 }
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 if (af == AF_INET) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3706 if (len != sizeof(struct in_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3707 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3708 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3709 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3710 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3711 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3712 } else if (af == AF_INET6) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3713 if (len != sizeof(struct in6_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3714 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3715 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3716 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3717 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3718 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3719 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3720 PyErr_Format(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3721 "unknown address family %d", af);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3722 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3723 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3724
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3725 retval = inet_ntop(af, packed, ip, sizeof(ip));
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3726 if (!retval) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3727 PyErr_SetFromErrno(socket_error);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3728 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3729 } else {
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3730 return PyUnicode_FromString(retval);
28818
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
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3733 /* NOTREACHED */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3734 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3735 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3736 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3737
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3738 #endif /* HAVE_INET_PTON */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3739
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3740 /* 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
3741
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3742 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3743 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
3744 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
3745 {
20912
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
3746 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
3747 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
3748 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
3749 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
3750 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
3751 char *hptr, *pptr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3752 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
3753 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3754 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
3755 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
3756
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3757 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
3758 family = AF_UNSPEC;
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3759 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
3760 &hobj, &pobj, &family, &socktype,
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3761 &protocol, &flags)) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3762 return NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3763 }
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3764 if (hobj == Py_None) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3765 hptr = NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3766 } 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
3767 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
3768 if (!idna)
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3769 return NULL;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3770 assert(PyBytes_Check(idna));
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3771 hptr = PyBytes_AS_STRING(idna);
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3772 } else if (PyBytes_Check(hobj)) {
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3773 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
3774 } 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
3775 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
3776 "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
3777 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3778 }
44158
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
3779 if (PyLong_CheckExact(pobj)) {
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
3780 long value = PyLong_AsLong(pobj);
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
3781 if (value == -1 && PyErr_Occurred())
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
3782 goto err;
81e0c0e2a8c1 Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
3783 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
3784 pptr = pbuf;
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42509
diff changeset
3785 } else if (PyUnicode_Check(pobj)) {
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 47667
diff changeset
3786 pptr = _PyUnicode_AsString(pobj);
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3787 } else if (PyBytes_Check(pobj)) {
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 45865
diff changeset
3788 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
3789 } 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
3790 pptr = (char *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3791 } else {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3792 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
3793 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3794 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3795 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
3796 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
3797 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
3798 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
3799 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
3800 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3801 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
3802 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
3803 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3804 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
3805 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
3806 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
3807 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3808 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3809
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3810 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
3811 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3812 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
3813 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
3814 PyObject *addr =
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
3815 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
3816 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
3817 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3818 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
3819 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
3820 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
3821 addr);
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3822 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
3823 if (single == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3824 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3825
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3826 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
3827 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3828 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3829 }
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3830 Py_XDECREF(idna);
24687
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3831 if (res0)
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3832 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3833 return all;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3834 err:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3835 Py_XDECREF(all);
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3836 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
3837 if (res0)
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
3838 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3839 return (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3840 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3841
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3842 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
3843 "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
3844 -> 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
3845 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3846 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
3847
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3848 /* 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
3849
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3850 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3851 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
3852 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
3853 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3854 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
3855 int flags;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3856 char *hostp;
20853
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20756
diff changeset
3857 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
3858 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
3859 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
3860 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3861 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
3862
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3863 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
3864 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
3865 return NULL;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3866 if (!PyArg_ParseTuple(sa, "si|ii",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3867 &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
3868 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
3869 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
3870 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
3871 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
3872 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
3873 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3874 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
3875 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
3876 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3877 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
3878 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
3879 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
3880 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3881 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3882 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
3883 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
3884 "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
3885 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3886 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3887 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
3888 case AF_INET:
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 char *t1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3891 int t2;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3892 if (PyArg_ParseTuple(sa, "si", &t1, &t2) == 0) {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3893 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
3894 "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
3895 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3896 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3897 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3898 }
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3899 #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
3900 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3901 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3902 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
3903 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
3904 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
3905 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
3906 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3907 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3908 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3909 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3910 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
3911 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
3912 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
3913 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
3914 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3915 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3916 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
3917
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3918 fail:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3919 if (res)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3920 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3921 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3922 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3923
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3924 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
3925 "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
3926 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3927 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
3928
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3929
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3930 /* 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
3931
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3932 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3933 socket_getdefaulttimeout(PyObject *self)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3934 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3935 if (defaulttimeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3936 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3937 return Py_None;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3938 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3939 else
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3940 return PyFloat_FromDouble(defaulttimeout);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3941 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3942
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3943 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
3944 "getdefaulttimeout() -> timeout\n\
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3945 \n\
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3946 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
3947 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
3948 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
3949
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3950 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3951 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
3952 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3953 double timeout;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3954
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3955 if (arg == Py_None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3956 timeout = -1.0;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3957 else {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3958 timeout = PyFloat_AsDouble(arg);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3959 if (timeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3960 if (!PyErr_Occurred())
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3961 PyErr_SetString(PyExc_ValueError,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3962 "Timeout value out of range");
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3963 return NULL;
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 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3966
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3967 defaulttimeout = timeout;
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 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3970 return Py_None;
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(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
3974 "setdefaulttimeout(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 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
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
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3981 /* 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
3982
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3983 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
3984 {"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
3985 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
3986 {"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
3987 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
3988 {"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
3989 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
3990 {"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
3991 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
3992 {"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
3993 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
3994 {"getservbyport", socket_getservbyport,
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3995 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
3996 {"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
3997 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
3998 #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
3999 {"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
4000 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
4001 #endif
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4002 #ifdef HAVE_SOCKETPAIR
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4003 {"socketpair", socket_socketpair,
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4004 METH_VARARGS, socketpair_doc},
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4005 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4006 {"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
4007 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
4008 {"ntohl", socket_ntohl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
4009 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
4010 {"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
4011 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
4012 {"htonl", socket_htonl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
4013 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
4014 {"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
4015 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
4016 {"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
4017 METH_VARARGS, inet_ntoa_doc},
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4018 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4019 {"inet_pton", socket_inet_pton,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4020 METH_VARARGS, inet_pton_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4021 {"inet_ntop", socket_inet_ntop,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4022 METH_VARARGS, inet_ntop_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4023 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4024 {"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
4025 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
4026 {"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
4027 METH_VARARGS, getnameinfo_doc},
24303
93434bc0899d Silence warning about getdefaulttimeout in PyMethodDef.
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
4028 {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout,
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4029 METH_NOARGS, getdefaulttimeout_doc},
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4030 {"setdefaulttimeout", socket_setdefaulttimeout,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4031 METH_O, setdefaulttimeout_doc},
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
4032 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4033 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4034
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
4035
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
4036 #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
4037 #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
4038
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4039 /* 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
4040
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
4041 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
4042 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
4043 {
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
4044 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
4045 }
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
4046
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
4047 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
4048 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
4049 {
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
4050 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
4051 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
4052 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
4053 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
4054 case 0: /* No error */
29790
1037feacb54f Fix [ 766669 ] Consistent GPF on exit
Mark Hammond <mhammond@skippinet.com.au>
parents: 29651
diff changeset
4055 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
4056 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
4057 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
4058 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
4059 "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
4060 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
4061 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
4062 case WSAEINVAL:
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4063 PyErr_SetString(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4064 PyExc_ImportError,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4065 "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
4066 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
4067 default:
41943
8bcfc46e444b Simplify os_init() implementations by using PyErr_Format()
Walter Dörwald <walter@livinglogic.de>
parents: 41942
diff changeset
4068 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
4069 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
4070 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4071 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
4072 }
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
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
4074 #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
4075
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4076
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4077 #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
4078 #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
4079
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4080 /* Additional initialization for OS/2 */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4081
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4082 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
4083 os_init(void)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4084 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4085 #ifndef PYCC_GCC
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4086 int rc = sock_init();
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4087
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4088 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
4089 return 1; /* Success */
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4090 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4091
41943
8bcfc46e444b Simplify os_init() implementations by using PyErr_Format()
Walter Dörwald <walter@livinglogic.de>
parents: 41942
diff changeset
4092 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
4093
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4094 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
4095 #else
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4096 /* 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
4097 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
4098 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4099 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4100
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4101 #endif /* PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4102
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4103
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4104 #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
4105 static int
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4106 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
4107 {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4108 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
4109 }
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4110 #endif
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4111
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4112
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
4113 /* 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
4114 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
4115 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
4116 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
4117 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4118 &sock_type,
31790
29da8bdfeb4e Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents: 31541
diff changeset
4119 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
4120 };
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4121
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4122
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4123 /* 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
4124
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4125 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
4126 "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
4127 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
4128 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
4129 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
4130 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
4131 */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4132
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
4133 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
4134 "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
4135 \n\
980767c6cd97 Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents: 24619
diff changeset
4136 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
4137
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4138 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
4139 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
4140 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
4141 socket_doc,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4142 -1,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4143 socket_methods,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4144 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4145 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4146 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4147 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4148 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
4149
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24411
diff changeset
4150 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
4151 PyInit__socket(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4152 {
44643
d8e4342c145e Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44568
diff changeset
4153 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
4154
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4155 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
4156 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
4157
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
4158 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
4159 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
4160 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
4161 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
4162
43300
b355d2dba9b6 merge this from trunk:
Gregory P. Smith <greg@mad-scientist.com>
parents: 42918
diff changeset
4163 socket_error = PyErr_NewException("socket.error",
b355d2dba9b6 merge this from trunk:
Gregory P. Smith <greg@mad-scientist.com>
parents: 42918
diff changeset
4164 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
4165 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
4166 return NULL;
31790
29da8bdfeb4e Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents: 31541
diff changeset
4167 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
4168 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
4169 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
4170 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
4171 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
4172 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
4173 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
4174 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
4175 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
4176 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
4177 NULL);
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4178 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
4179 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
4180 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
4181 PyModule_AddObject(m, "gaierror", socket_gaierror);
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4182 socket_timeout = PyErr_NewException("socket.timeout",
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4183 socket_error, NULL);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4184 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
4185 return NULL;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4186 Py_INCREF(socket_timeout);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4187 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
4188 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
4189 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
4190 (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
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 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
4193 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
4194 (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
4195 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
4196
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4197 #ifdef ENABLE_IPV6
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4198 has_ipv6 = Py_True;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4199 #else
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4200 has_ipv6 = Py_False;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4201 #endif
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4202 Py_INCREF(has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4203 PyModule_AddObject(m, "has_ipv6", has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4204
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
4205 /* 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
4206 if (PyModule_AddObject(m, PySocket_CAPI_NAME,
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4207 PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL)
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4208 ) != 0)
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;
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
4210
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4211 /* 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
4212 #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
4213 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
4214 #endif
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4215 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
4216 #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
4217 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
4218 #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
4219 #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
4220 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
4221 #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
4222 #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
4223 /* 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
4224 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
4225 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4226 #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
4227 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
4228 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4229 #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
4230 /* Appletalk DDP */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4231 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
4232 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4233 #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
4234 /* Amateur radio NetROM */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4235 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
4236 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4237 #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
4238 /* Multiprotocol bridge */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4239 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
4240 #endif
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4241 #ifdef AF_ATMPVC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4242 /* ATM PVCs */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4243 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
4244 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4245 #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
4246 /* 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
4247 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
4248 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4249 #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
4250 /* 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
4251 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
4252 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4253 #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
4254 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
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_ROSE
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4257 /* 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
4258 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
4259 #endif
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4260 #ifdef AF_DECnet
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4261 /* Reserved for DECnet project */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4262 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
4263 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4264 #ifdef AF_NETBEUI
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4265 /* 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
4266 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
4267 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4268 #ifdef AF_SECURITY
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4269 /* Security callback pseudo AF */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4270 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
4271 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4272 #ifdef AF_KEY
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4273 /* 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
4274 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
4275 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4276 #ifdef AF_NETLINK
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4277 /* */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4278 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
4279 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
4280 #ifdef NETLINK_SKIP
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4281 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
4282 #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
4283 #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
4284 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
4285 #endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4286 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
4287 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
4288 #ifdef NETLINK_TCPDIAG
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4289 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
4290 #endif
4d988dda6478 NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents: 36610
diff changeset
4291 #ifdef NETLINK_NFLOG
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4292 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
4293 #endif
36298
9eeaa33f9640 Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36289
diff changeset
4294 #ifdef NETLINK_XFRM
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4295 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
4296 #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
4297 #ifdef NETLINK_ARPD
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4298 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
4299 #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
4300 #ifdef NETLINK_ROUTE6
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4301 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
4302 #endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4303 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
4304 #ifdef NETLINK_DNRTMSG
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4305 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
4306 #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
4307 #ifdef NETLINK_TAPBASE
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4308 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
4309 #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
4310 #endif /* AF_NETLINK */
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4311 #ifdef AF_ROUTE
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4312 /* 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
4313 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
4314 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4315 #ifdef AF_ASH
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4316 /* Ash */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4317 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
4318 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4319 #ifdef AF_ECONET
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4320 /* Acorn Econet */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4321 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
4322 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4323 #ifdef AF_ATMSVC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4324 /* ATM SVCs */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4325 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
4326 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4327 #ifdef AF_SNA
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4328 /* Linux SNA Project (nutters!) */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4329 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
4330 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4331 #ifdef AF_IRDA
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4332 /* IRDA sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4333 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
4334 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4335 #ifdef AF_PPPOX
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4336 /* PPPoX sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4337 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
4338 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4339 #ifdef AF_WANPIPE
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4340 /* Wanpipe API Sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4341 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
4342 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4343 #ifdef AF_LLC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4344 /* Linux LLC */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4345 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
4346 #endif
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4347
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
4348 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4349 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
4350 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
4351 PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI);
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
4352 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
4353 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
4354 #if !defined(__FreeBSD__)
40893
32c4897b5d46 Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40638
diff changeset
4355 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
4356 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
4357 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
4358 #endif
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4359 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
4360 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
4361 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
4362 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4363
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
4364 #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
4365 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
4366 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
4367 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
4368 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
4369 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
4370 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
4371 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
4372 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
4373 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
4374 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4375
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4376 #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
4377 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
4378
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4379 /* for addresses */
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4380 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
4381 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
4382 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
4383
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4384 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
4385 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
4386 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
4387
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4388 /* for setsockopt() */
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4389 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
4390 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
4391 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
4392 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
4393 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
4394 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
4395
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4396 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
4397 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
4398 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
4399 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
4400 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
4401 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
4402 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
4403 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
4404
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4405 /* for subscriptions */
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4406 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
4407 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
4408 #ifdef TIPC_SUB_CANCEL
d8e4342c145e Merged revisions 59883-59920 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44568
diff changeset
4409 /* 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
4410 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
4411 #endif
44568
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_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
4413 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
4414 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
4415 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
4416 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
4417 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
4418 #endif
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
4419
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4420 /* Socket types */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4421 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
4422 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
4423 /* 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
4424 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
4425 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
4426 #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
4427 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
4428 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4429
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4430 #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
4431 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4432 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4433 #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
4434 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4435 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4436 #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
4437 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4438 #endif
32578
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4439 #ifdef SO_EXCLUSIVEADDRUSE
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4440 PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE);
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4441 #endif
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4442
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4443 #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
4444 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4445 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4446 #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
4447 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4448 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4449 #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
4450 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4451 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4452 #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
4453 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4454 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4455 #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
4456 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4457 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4458 #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
4459 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4460 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4461 #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
4462 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4463 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4464 #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
4465 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4466 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4467 #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
4468 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4469 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4470 #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
4471 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4472 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4473 #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
4474 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT);
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_SNDTIMEO
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_SNDTIMEO", SO_SNDTIMEO);
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_RCVTIMEO
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_RCVTIMEO", SO_RCVTIMEO);
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_ERROR
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_ERROR", SO_ERROR);
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_TYPE
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_TYPE", SO_TYPE);
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
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4489 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4490 #ifdef SOMAXCONN
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4491 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4492 #else
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4493 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4494 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4495
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4496 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4497 #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
4498 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB);
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 MSG_PEEK
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, "MSG_PEEK", MSG_PEEK);
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 MSG_DONTROUTE
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, "MSG_DONTROUTE", MSG_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4505 #endif
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
4506 #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
4507 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT);
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
4508 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4509 #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
4510 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR);
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 MSG_TRUNC
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, "MSG_TRUNC", MSG_TRUNC);
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 MSG_CTRUNC
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, "MSG_CTRUNC", MSG_CTRUNC);
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 #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
4519 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4520 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4521 #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
4522 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4523 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4524 #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
4525 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4526 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4527
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4528 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4529 #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
4530 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4531 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4532 #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
4533 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
4534 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4535 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
4536 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4537 #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
4538 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
4539 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4540 #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
4541 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
4542 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4543 #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
4544 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
4545 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4546 #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
4547 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
4548 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4549 #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
4550 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
4551 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4552 #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
4553 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
4554 #else
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, "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
4556 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4557 #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
4558 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
4559 #else
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_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
4561 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4562 #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
4563 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
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, "IPPROTO_IP", 0);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4566 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4567 #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
4568 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
4569 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4570 #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
4571 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
4572 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4573 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4574 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4575 #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
4576 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4577 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4578 #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
4579 PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4580 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4581 #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
4582 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
4583 #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
4584 #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
4585 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
4586 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4587 #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
4588 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
4589 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4590 #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
4591 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
4592 #else
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_TCP", 6);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4594 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4595 #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
4596 PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4597 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4598 #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
4599 PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4600 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4601 #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
4602 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
4603 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4604 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4605 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4606 #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
4607 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4608 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4609 #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
4610 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4611 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4612 #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
4613 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4614 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4615 #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
4616 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4617 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4618 #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
4619 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
4620 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4621 #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
4622 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
4623 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4624 #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
4625 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
4626 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4627 #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
4628 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
4629 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4630 #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
4631 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
4632 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4633 #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
4634 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
4635 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4636 #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
4637 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
4638 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4639 #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
4640 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
4641 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4642 #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
4643 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
4644 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4645 #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
4646 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
4647 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4648 #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
4649 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
4650 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4651 #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
4652 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4653 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4654 #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
4655 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4656 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4657 #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
4658 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
4659 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4660 #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
4661 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
4662 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4663 #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
4664 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
4665 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4666 #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
4667 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4668 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4669 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4670 #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
4671 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
4672 #else
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_RAW", 255);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4674 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4675 #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
4676 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4677 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4678
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4679 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4680 #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
4681 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4682 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4683 PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4684 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4685 #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
4686 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4687 #else
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, "IPPORT_USERRESERVED", 5000);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4689 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4690
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4691 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4692 #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
4693 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4694 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4695 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4696 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4697 #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
4698 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4699 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4700 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4701 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4702 #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
4703 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4704 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4705 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4706 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4707 #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
4708 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4709 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4710 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4711 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4712 #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
4713 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
4714 INADDR_ALLHOSTS_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4715 #else
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, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4717 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4718 #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
4719 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
4720 INADDR_MAX_LOCAL_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4721 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4722 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4723 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4724 #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
4725 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4726 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4727 PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4728 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4729
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4730 /* IPv4 [gs]etsockopt options */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4731 #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
4732 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4733 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4734 #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
4735 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4736 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4737 #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
4738 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4739 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4740 #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
4741 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4742 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4743 #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
4744 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4745 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4746 #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
4747 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4748 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4749 #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
4750 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4751 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4752 #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
4753 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4754 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4755 #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
4756 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
4757 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4758 #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
4759 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
4760 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4761 #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
4762 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
4763 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4764 #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
4765 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
4766 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4767 #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
4768 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
4769 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4770 #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
4771 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
4772 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
4773 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4774 #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
4775 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
4776 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
4777 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4778 #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
4779 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
4780 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4781
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4782 /* 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
4783 #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
4784 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
4785 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4786 #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
4787 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
4788 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4789 #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
4790 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
4791 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4792 #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
4793 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
4794 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4795 #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
4796 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
4797 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4798 #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
4799 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
4800 #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
4801 /* 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
4802 #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
4803 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
4804 #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
4805 /* 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
4806 #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
4807 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
4808 #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
4809 #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
4810 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
4811 #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
4812 #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
4813 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
4814 #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
4815 #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
4816 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
4817 #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
4818 #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
4819 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
4820 #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
4821 #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
4822 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
4823 #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
4824 #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
4825 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
4826 #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
4827 #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
4828 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
4829 #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
4830 #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
4831 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
4832 #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
4833 #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
4834 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
4835 #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
4836 #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
4837 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
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_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
4840 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
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_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
4843 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
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_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
4846 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
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_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
4849 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
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_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
4852 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
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_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
4855 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
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_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
4858 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
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_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
4861 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
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_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
4864 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
4865 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4866
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4867 /* TCP options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4868 #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
4869 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
4870 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4871 #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
4872 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
4873 #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
4874 #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
4875 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
4876 #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
4877 #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
4878 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
4879 #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
4880 #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
4881 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
4882 #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
4883 #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
4884 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
4885 #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
4886 #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
4887 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
4888 #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
4889 #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
4890 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
4891 #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
4892 #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
4893 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
4894 #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
4895 #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
4896 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
4897 #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
4898 #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
4899 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
4900 #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
4901 #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
4902 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
4903 #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
4904
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4905
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4906 /* IPX options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4907 #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
4908 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
4909 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
4910
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4911 /* 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
4912 #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
4913 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
4914 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4915 #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
4916 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
4917 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4918 #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
4919 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
4920 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4921 #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
4922 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
4923 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4924 #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
4925 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
4926 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4927 #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
4928 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
4929 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4930 #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
4931 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
4932 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4933 #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
4934 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
4935 #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
4936 #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
4937 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
4938 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4939 #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
4940 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
4941 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4942 #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
4943 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
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_SYSTEM
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_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
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_BADHINTS
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_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
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_PROTOCOL
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_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
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_MAX
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_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
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 AI_PASSIVE
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, "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
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 AI_CANONNAME
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, "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
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 AI_NUMERICHOST
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, "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
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 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
4967 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
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 AI_MASK
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, "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
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 AI_ALL
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, "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
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 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
4976 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
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 AI_ADDRCONFIG
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, "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
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 AI_V4MAPPED
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, "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
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 AI_DEFAULT
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, "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
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 NI_MAXHOST
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, "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
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 NI_MAXSERV
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, "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
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 NI_NOFQDN
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, "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
4995 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4996 #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
4997 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
4998 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4999 #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
5000 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
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 NI_NUMERICSERV
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, "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
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 NI_DGRAM
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, "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
5007 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5008
31027
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5009 /* shutdown() parameters */
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5010 #ifdef SHUT_RD
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5011 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
5012 #elif defined(SD_RECEIVE)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5013 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
5014 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5015 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
5016 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5017 #ifdef SHUT_WR
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5018 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
5019 #elif defined(SD_SEND)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5020 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
5021 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5022 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
5023 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5024 #ifdef SHUT_RDWR
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5025 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
5026 #elif defined(SD_BOTH)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5027 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
5028 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5029 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
5030 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5031
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5032 #ifdef SIO_RCVALL
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5033 {
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5034 PyObject *tmp;
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5035 tmp = PyLong_FromUnsignedLong(SIO_RCVALL);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5036 if (tmp == NULL)
47583
b82e0545d111 Add missing NULL return value.
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
5037 return NULL;
44674
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5038 PyModule_AddObject(m, "SIO_RCVALL", tmp);
1154158a199f Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44643
diff changeset
5039 }
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5040 PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF);
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5041 PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON);
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5042 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
5043 #ifdef RCVALL_IPLEVEL
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5044 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
5045 #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
5046 #ifdef RCVALL_MAX
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5047 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
5048 #endif
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5049 #endif /* _MSTCPIP_ */
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
5050
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
5051 /* Initialize gethostbyname lock */
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
5052 #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
5053 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
5054 #endif
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
5055 return m;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5056 }
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
5057
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5058
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5059 #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
5060 #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
5061
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
5062 /* 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
5063 /* 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
5064
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
5065 int
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5066 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
5067 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5068 if (af == AF_INET) {
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
5069 long packed_addr;
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
5070 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
5071 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
5072 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
5073 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
5074 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
5075 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
5076 /* 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
5077 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
5078 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
5079
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
5080 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
5081 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
5082 {
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
5083 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
5084 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
5085 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
5086 /* 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
5087 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
5088 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
5089 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
5090 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
5091 /* 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
5092 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
5093 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5094
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
5095 #endif
43874
6b012f01a889 Fix for VS 2008
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
5096 #endif