annotate Modules/socketmodule.c @ 39354:85fdcdfca85c legacy-trunk

Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during a socket operation on a socket with a timeout, the exception will be caught correctly. Previously, the exception was not caught.
author Neal Norwitz <nnorwitz@gmail.com>
date Wed, 02 Aug 2006 06:46:21 +0000
parents c4ac6ea497a1
children 799bcf0ccbfd
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
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
10 portable manner, though AF_PACKET and AF_NETLINK are supported 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
11 - 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
12 - 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
13 for by socket.py).
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
15 Module interface:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
17 - 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
18 - 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
19 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
20 - 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
21 a subclass of socket.error
25105
39e09f30f7ef Update the module doc comment.
Guido van Rossum <guido@python.org>
parents: 24687
diff changeset
22 - socket.fromfd(fd, family, type[, proto]) --> new socket object (created
39e09f30f7ef Update the module doc comment.
Guido van Rossum <guido@python.org>
parents: 24687
diff changeset
23 from an existing file descriptor)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
24 - 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
25 - 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
26 - 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
27 - 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
28 - 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
29 - socket.getservbyport(portnumber[, protocolname]) --> service name
25105
39e09f30f7ef Update the module doc comment.
Guido van Rossum <guido@python.org>
parents: 24687
diff changeset
30 - socket.socket([family[, type [, proto]]]) --> new socket object
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.
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
56 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
57
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
58 - 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
59 - 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
60 - 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
61
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
64 #ifdef __APPLE__
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
65 /*
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
66 * inet_aton is not available on OSX 10.3, yet we want to use a binary
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
67 * that was build on 10.4 or later to work on that release, weak linking
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
68 * comes to the rescue.
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
69 */
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
70 # pragma weak inet_aton
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
71 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
72
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
73 #include "Python.h"
37069
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
74 #include "structmember.h"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
75
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
76 #undef MAX
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
77 #define MAX(x, y) ((x) < (y) ? (y) : (x))
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
78
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
79 /* Socket object documentation */
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
80 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
81 "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
82 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
83 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
84 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
85 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
86 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
87 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
88 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
89 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
90 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
91 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
92 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
93 accept() -- accept a connection, returning new socket and client address\n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
94 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
95 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
96 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
97 connect_ex(addr) -- connect, return an error code instead of an exception\n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
98 dup() -- return a new socket object identical to the current one [*]\n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
99 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
100 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
101 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
102 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
103 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
104 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
105 makefile([mode, [bufsize]]) -- return a file object for 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
106 recv(buflen[, flags]) -- receive data\n\
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
107 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
108 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
109 recvfrom_into(buffer[, nbytes, [, flags])\n\
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
110 -- 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
111 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
112 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
113 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
114 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
115 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
116 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
117 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
118 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
119 [*] not available on all platforms!");
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
120
30722
651fc8d98d99 Fix a bunch of typos in documentation, docstrings and comments.
Walter Dörwald <walter@livinglogic.de>
parents: 30683
diff changeset
121 /* 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
122 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
123
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
124 /* 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
125 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
126 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
127 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
128
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
129 #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
130 # 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
131 # 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
132 # 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
133 #endif
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
134
10579
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
135 #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
136 # 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
137 #endif
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
138
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
139 #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
140 # 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
141 # 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
142 # 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
143 # 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
144 # 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
145 /* 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
146 # 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
147 # 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
148 # endif
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
149 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
150
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
151 #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
152 !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
153 # define USE_GETHOSTBYNAME_LOCK
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
154 #endif
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
155
35635
27e1426b7f31 Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents: 35551
diff changeset
156 /* To use __FreeBSD_version */
27e1426b7f31 Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents: 35551
diff changeset
157 #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
158 #include <sys/param.h>
27e1426b7f31 Patch #1288833: Removed thread lock from socket.getaddrinfo on
Hye-Shik Chang <hyeshik@gmail.com>
parents: 35551
diff changeset
159 #endif
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
160 /* 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
161 (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
162 #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
163 (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
164 defined(__OpenBSD__) || defined(__NetBSD__) || \
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
165 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
166 #define USE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
167 #endif
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
168
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
169 #ifdef USE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
170 #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
171 #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
172 #else
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
173 #define ACQUIRE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
174 #define RELEASE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
175 #endif
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
176
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
177 #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
178 # include "pythread.h"
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
179 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
181 #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
182 # 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
183 # 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
184 # 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
185 # 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
186 # include <ctype.h>
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
187 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
188
26551
0c995cd07026 Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26550
diff changeset
189 #if defined(__VMS)
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
190 # include <ioctl.h>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
191 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
192
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
193 #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
194 # 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
195 # 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
196 # 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
197 # include <os2.h>
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
198 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
199
29929
08d2636b8e58 Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29790
diff changeset
200 #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
201 /* 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
202 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
203 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
204
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
205 /* 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
206 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
207 #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
208 #define _SGIAPI 1
29929
08d2636b8e58 Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29790
diff changeset
209
33478
1b3ac674a57c Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents: 33427
diff changeset
210 #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
211 #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
212 #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
213 #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
214 #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
215 #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
216 #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
217 #endif
1b3ac674a57c Patch for compilation on IRIX from rwgk on http://python.org/sf/728330
Trent Mick <trentm@activestate.com>
parents: 33427
diff changeset
218
29929
08d2636b8e58 Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29790
diff changeset
219 #define HAVE_INET_PTON
08d2636b8e58 Get socketmodule compiling on IRIX 6.5.10.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29790
diff changeset
220 #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
221 #endif
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
222
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
223 /* Irix 6.5 fails to define this variable at all. This is needed
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
224 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
225 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
226 #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
227 #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
228 #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
229
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
230 /* Generic includes */
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
231 #ifdef HAVE_SYS_TYPES_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
232 #include <sys/types.h>
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
233 #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
234
21961
ea23e6e49290 Also fix the comment.
Marc-André Lemburg <mal@egenix.com>
parents: 21960
diff changeset
235 /* 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
236 #define PySocket_BUILDING_SOCKET
21960
7a917ad8f442 Fix the name of the header file.
Marc-André Lemburg <mal@egenix.com>
parents: 21959
diff changeset
237 #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
238
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
239 /* 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
240
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
241 #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
242
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
243 /* 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
244 # 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
245
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
246 /* Headers needed for inet_ntoa() and inet_addr() */
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
247 # ifdef __BEOS__
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
248 # include <net/netdb.h>
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
249 # elif defined(PYOS_OS2) && defined(PYCC_VACPP)
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
250 # 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
251 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
252 # 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
253 # 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
254 # 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
255
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 # ifndef RISCOS
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
257 # 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
258 # else
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
259 # include <sys/ioctl.h>
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
260 # include <socklib.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
261 # define NO_DUP
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
262 int h_errno; /* not used */
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
263 # define INET_ADDRSTRLEN 16
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
264 # 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
265
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
266 #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
267
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 /* MS_WINDOWS includes */
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
269 # ifdef HAVE_FCNTL_H
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
270 # include <fcntl.h>
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
271 # 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
272
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
273 #endif
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
274
31504
2abc52c3d4c2 remove support for missing ANSI C header files (limits.h, stddef.h, etc).
Skip Montanaro <skip@pobox.com>
parents: 31443
diff changeset
275 #include <stddef.h>
18263
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
276
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
277 #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
278 # 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
279 #endif
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
280
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
281 #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
282 # define O_NONBLOCK O_NDELAY
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
283 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
284
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
285 /* 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
286 #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
287 /* 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
288 * _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
289 * 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
290 */
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38655
diff changeset
291 #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
292 /* 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
293 * 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
294 */
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 #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
296 # 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
297 #endif
33066
cda0455bd0a0 Bug #1001857: socketmodule does not build under cygwin
Jason Tishler <jason@tishler.net>
parents: 33063
diff changeset
298
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
299 #ifndef HAVE_INET_PTON
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
300 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
301 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
302 #endif
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
303
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
304 #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
305 /* 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 #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
314 /* 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
315 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
316 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
317 #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
318 #endif
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
319
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
320 #ifdef HAVE_INET_ATON
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
321 #define USE_INET_ATON_WEAKLINK
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
322 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
323
24078
702a5900df7d Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents: 23832
diff changeset
324 #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
325
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
326 /* 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
327 #if !defined(HAVE_GETADDRINFO)
28913
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
328 /* 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
329 #define getaddrinfo fake_getaddrinfo
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
330 #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
331 #define freeaddrinfo fake_freeaddrinfo
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
332 #include "getaddrinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
333 #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
334 #if !defined(HAVE_GETNAMEINFO)
28913
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
335 #define getnameinfo fake_getnameinfo
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
336 #include "getnameinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
337 #endif
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
338
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
339 #if defined(MS_WINDOWS) || defined(__BEOS__)
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
340 /* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
341 /* seem to be a few differences in the API */
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
342 #define SOCKETCLOSE closesocket
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
343 #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
344 #endif
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
345
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
346 #ifdef MS_WIN32
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
347 #define EAFNOSUPPORT WSAEAFNOSUPPORT
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
348 #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
349 #endif
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
350
22115
d104bb50a194 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 22096
diff changeset
351 #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
352 #define SOCKETCLOSE soclose
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
353 #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
354 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
355
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
356 #ifndef SOCKETCLOSE
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
357 #define SOCKETCLOSE close
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
358 #endif
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
359
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
360 #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
361 #define USE_BLUETOOTH 1
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
362 #if defined(__FreeBSD__)
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
363 #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
364 #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
365 #define sockaddr_l2 sockaddr_l2cap
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
366 #define sockaddr_rc sockaddr_rfcomm
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
367 #define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr)
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
368 #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
369 #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb)
39242
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
370 #elif defined(__NetBSD__)
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
371 #define sockaddr_l2 sockaddr_bt
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
372 #define sockaddr_rc sockaddr_bt
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
373 #define sockaddr_sco sockaddr_bt
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
374 #define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr)
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
375 #define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb)
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
376 #define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb)
0e9a269a2189 Allow socketmodule to compile on NetBSD -current, whose bluetooth API
Matt Fleming <mattjfleming@googlemail.com>
parents: 39059
diff changeset
377 #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
378 #else
31541
ec6232ed9115 Make socketmodule compile again on a modern Linux (that supports Bluetooth).
Anthony Baxter <anthonybaxter@gmail.com>
parents: 31504
diff changeset
379 #define _BT_SOCKADDR_MEMB(s, proto) (&((s)->sock_addr).bt_##proto)
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
380 #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
381 #define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb)
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
382 #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
383 #endif
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
384 #endif
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
385
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
386 #ifdef __VMS
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
387 /* TCP/IP Services for VMS uses a maximum send/recv buffer length */
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
388 #define SEGMENT_SIZE (32 * 1024 -1)
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
389 #endif
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
390
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
391 /*
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
392 * 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
393 */
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
394 #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
395 #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
396 #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
397 #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
398 #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
399 #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
400
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
401 /* 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
402 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
403
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
404 /* 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
405 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
406 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
407 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
408 static PyObject *socket_gaierror;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
409 static PyObject *socket_timeout;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
410
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
411 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
412 /* Global variable which is !=0 if Python is running in a RISC OS taskwindow */
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
413 static int taskwindow;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
414 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
415
21970
b1a871dc5196 Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents: 21964
diff changeset
416 /* 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
417 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
418 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
419 there has to be a circular reference. */
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24078
diff changeset
420 static PyTypeObject sock_type;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
421
39059
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
422 #if defined(HAVE_POLL_H)
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
423 #include <poll.h>
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
424 #elif defined(HAVE_SYS_POLL_H)
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
425 #include <sys/poll.h>
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
426 #endif
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
427
36476
c073dffbe70e Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents: 36452
diff changeset
428 #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
429 /* 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
430 #define IS_SELECTABLE(s) 1
39059
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
431 #elif defined(HAVE_POLL)
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
432 /* Instead of select(), we'll use poll() since poll() works on any fd. */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
433 #define IS_SELECTABLE(s) 1
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
434 /* 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
435 #else
c073dffbe70e Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Martin v. Löwis <martin@v.loewis.de>
parents: 36452
diff changeset
436 /* POSIX says selecting file descriptors beyond FD_SETSIZE
39059
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
437 has undefined behaviour. If there's no timeout left, we don't have to
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
438 call select, so it's a safe, little white lie. */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
439 #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
440 #endif
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
441
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
442 static PyObject*
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
443 select_error(void)
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
444 {
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
445 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
446 return NULL;
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
447 }
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
448
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
449 /* 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
450 and return a NULL pointer from a function. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
451
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
452 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
453 set_error(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
455 #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
456 int err_no = WSAGetLastError();
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
457 static struct {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
458 int no;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
459 const char *msg;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
460 } *msgp, msgs[] = {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
461 {WSAEINTR, "Interrupted system call"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
462 {WSAEBADF, "Bad file descriptor"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
463 {WSAEACCES, "Permission denied"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
464 {WSAEFAULT, "Bad address"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
465 {WSAEINVAL, "Invalid argument"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
466 {WSAEMFILE, "Too many open files"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
467 {WSAEWOULDBLOCK,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
468 "The socket operation could not complete "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
469 "without blocking"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
470 {WSAEINPROGRESS, "Operation now in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
471 {WSAEALREADY, "Operation already in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
472 {WSAENOTSOCK, "Socket operation on non-socket"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
473 {WSAEDESTADDRREQ, "Destination address required"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
474 {WSAEMSGSIZE, "Message too long"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
475 {WSAEPROTOTYPE, "Protocol wrong type for socket"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
476 {WSAENOPROTOOPT, "Protocol not available"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
477 {WSAEPROTONOSUPPORT, "Protocol not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
478 {WSAESOCKTNOSUPPORT, "Socket type not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
479 {WSAEOPNOTSUPP, "Operation not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
480 {WSAEPFNOSUPPORT, "Protocol family not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
481 {WSAEAFNOSUPPORT, "Address family not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
482 {WSAEADDRINUSE, "Address already in use"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
483 {WSAEADDRNOTAVAIL, "Can't assign requested address"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
484 {WSAENETDOWN, "Network is down"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
485 {WSAENETUNREACH, "Network is unreachable"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
486 {WSAENETRESET, "Network dropped connection on reset"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
487 {WSAECONNABORTED, "Software caused connection abort"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
488 {WSAECONNRESET, "Connection reset by peer"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
489 {WSAENOBUFS, "No buffer space available"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
490 {WSAEISCONN, "Socket is already connected"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
491 {WSAENOTCONN, "Socket is not connected"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
492 {WSAESHUTDOWN, "Can't send after socket shutdown"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
493 {WSAETOOMANYREFS, "Too many references: can't splice"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
494 {WSAETIMEDOUT, "Operation timed out"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
495 {WSAECONNREFUSED, "Connection refused"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
496 {WSAELOOP, "Too many levels of symbolic links"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
497 {WSAENAMETOOLONG, "File name too long"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
498 {WSAEHOSTDOWN, "Host is down"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
499 {WSAEHOSTUNREACH, "No route to host"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
500 {WSAENOTEMPTY, "Directory not empty"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
501 {WSAEPROCLIM, "Too many processes"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
502 {WSAEUSERS, "Too many users"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
503 {WSAEDQUOT, "Disc quota exceeded"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
504 {WSAESTALE, "Stale NFS file handle"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
505 {WSAEREMOTE, "Too many levels of remote in path"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
506 {WSASYSNOTREADY, "Network subsystem is unvailable"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
507 {WSAVERNOTSUPPORTED, "WinSock version is not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
508 {WSANOTINITIALISED,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
509 "Successful WSAStartup() not yet performed"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
510 {WSAEDISCON, "Graceful shutdown in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
511 /* Resolver errors */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
512 {WSAHOST_NOT_FOUND, "No such host is known"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
513 {WSATRY_AGAIN, "Host not found, or server failed"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
514 {WSANO_RECOVERY, "Unexpected server error encountered"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
515 {WSANO_DATA, "Valid name without requested data"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
516 {WSANO_ADDRESS, "No address, look for MX record"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
517 {0, NULL}
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
518 };
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
519 if (err_no) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
520 PyObject *v;
13680
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
521 const char *msg = "winsock error";
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
522
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
523 for (msgp = msgs; msgp->msg; msgp++) {
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
524 if (err_no == msgp->no) {
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
525 msg = msgp->msg;
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
526 break;
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
527 }
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
528 }
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
529
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
530 v = Py_BuildValue("(is)", err_no, msg);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
531 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
532 PyErr_SetObject(socket_error, v);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
533 Py_DECREF(v);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
534 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
535 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
536 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
537 else
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
538 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
539
22115
d104bb50a194 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 22096
diff changeset
540 #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
541 if (sock_errno() != NO_ERROR) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
542 APIRET rc;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
543 ULONG msglen;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
544 char outbuf[100];
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
545 int myerrorcode = sock_errno();
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
546
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
547 /* 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
548 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
549 myerrorcode - SOCBASEERR + 26,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
550 "mptn.msg",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
551 &msglen);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
552 if (rc == NO_ERROR) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
553 PyObject *v;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
554
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
555 /* 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
556 outbuf[msglen] = '\0';
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
557 if (strlen(outbuf) > 0) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
558 /* If non-empty msg, trim CRLF */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
559 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
560 while (lastc > outbuf &&
8cb686dd6e64 Fix SF bug #1072182, problems with signed characters.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35999
diff changeset
561 isspace(Py_CHARMASK(*lastc))) {
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
562 /* Trim trailing whitespace (CRLF) */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
563 *lastc-- = '\0';
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
564 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
565 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
566 v = Py_BuildValue("(is)", myerrorcode, outbuf);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
567 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
568 PyErr_SetObject(socket_error, v);
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
569 Py_DECREF(v);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
570 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
571 return NULL;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
572 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
573 }
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
574 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
575
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
576 #if defined(RISCOS)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
577 if (_inet_error.errnum != NULL) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
578 PyObject *v;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
579 v = Py_BuildValue("(is)", errno, _inet_err());
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
580 if (v != NULL) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
581 PyErr_SetObject(socket_error, v);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
582 Py_DECREF(v);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
583 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
584 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
585 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
586 #endif
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
587
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
588 return PyErr_SetFromErrno(socket_error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
591
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
592 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
593 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
594 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
595 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
596
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
597 #ifdef HAVE_HSTRERROR
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
598 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
599 #else
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
600 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
601 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
602 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
603 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
604 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
605 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
606
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
607 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
608 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
609
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
610
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
611 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
612 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
613 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
614 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
615
22096
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
616 #ifdef EAI_SYSTEM
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
617 /* 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
618 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
619 return set_error();
22096
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
620 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
621
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
622 #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
623 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
624 #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
625 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
626 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
627 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
628 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
629 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
630 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
631
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
632 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
633 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
634
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
635 #ifdef __VMS
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
636 /* Function to send in segments */
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
637 static int
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
638 sendsegmented(int sock_fd, char *buf, int len, int flags)
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
639 {
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
640 int n = 0;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
641 int remaining = len;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
642
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
643 while (remaining > 0) {
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
644 unsigned int segment;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
645
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
646 segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining);
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
647 n = send(sock_fd, buf, segment, flags);
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
648 if (n < 0) {
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
649 return n;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
650 }
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
651 remaining -= segment;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
652 buf += segment;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
653 } /* end while */
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
654
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
655 return len;
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
656 }
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
657 #endif
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
658
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
659 /* 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
660 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
661 static int
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
662 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
663 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
664 #ifndef RISCOS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
665 #ifndef MS_WINDOWS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
666 int delay_flag;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
667 #endif
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
668 #endif
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
669
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
670 Py_BEGIN_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
671 #ifdef __BEOS__
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
672 block = !block;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
673 setsockopt(s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
674 (void *)(&block), sizeof(int));
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
675 #else
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
676 #ifndef RISCOS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
677 #ifndef MS_WINDOWS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
678 #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
679 block = !block;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
680 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
681 #elif defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
682 block = !block;
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
683 ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block);
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
684 #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
685 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
686 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
687 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
688 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
689 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
690 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
691 #endif /* !PYOS_OS2 */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
692 #else /* MS_WINDOWS */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
693 block = !block;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
694 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
695 #endif /* MS_WINDOWS */
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
696 #else /* RISCOS */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
697 block = !block;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
698 socketioctl(s->sock_fd, FIONBIO, (u_long*)&block);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
699 #endif /* RISCOS */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
700 #endif /* __BEOS__ */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
701 Py_END_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
702
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
703 /* 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
704 return 1;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
705 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
706
39059
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
707 /* 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
708 The argument writing indicates the direction.
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
709 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
710 after they've reacquired the interpreter lock.
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
711 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
712 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
713 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
714 {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
715 int n;
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
716
24317
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
717 /* 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
718 if (s->sock_timeout <= 0.0)
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
719 return 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
720
24317
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
721 /* 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
722 if (s->sock_fd < 0)
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
723 return 0;
24317
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
724
39059
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
725 /* Prefer poll, if available, since you can poll() any fd
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
726 * which can't be done with select(). */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
727 #ifdef HAVE_POLL
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
728 {
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
729 struct pollfd pollfd;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
730 int timeout;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
731
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
732 pollfd.fd = s->sock_fd;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
733 pollfd.events = writing ? POLLOUT : POLLIN;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
734
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
735 /* s->sock_timeout is in seconds, timeout in ms */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
736 timeout = (int)(s->sock_timeout * 1000 + 0.5);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
737 n = poll(&pollfd, 1, timeout);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
738 }
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
739 #else
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
740 {
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
741 /* Construct the arguments to select */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
742 fd_set fds;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
743 struct timeval tv;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
744 tv.tv_sec = (int)s->sock_timeout;
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
745 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
746 FD_ZERO(&fds);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
747 FD_SET(s->sock_fd, &fds);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
748
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
749 /* See if the socket is ready */
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
750 if (writing)
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
751 n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
752 else
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
753 n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
754 }
52a8738f5ab4 #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
Anthony Baxter <anthonybaxter@gmail.com>
parents: 39043
diff changeset
755 #endif
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
756
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
757 if (n < 0)
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
758 return -1;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
759 if (n == 0)
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
760 return 1;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
761 return 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
762 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
763
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
764 /* 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
765
24305
428cbbf05639 A Python float is a C double; redeclare defaulttimeout as such; stops
Tim Peters <tim.peters@gmail.com>
parents: 24303
diff changeset
766 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
767
24363
979ff5d0ae07 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents: 24317
diff changeset
768 PyMODINIT_FUNC
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
769 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
770 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
771 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
772 #ifdef RISCOS
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
773 int block = 1;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
774 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
775 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
776 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
777 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
778 s->sock_proto = proto;
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
779 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
780
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
781 s->errorhandler = &set_error;
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
782
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
783 if (defaulttimeout >= 0.0)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
784 internal_setblocking(s, 0);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
785
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
786 #ifdef RISCOS
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
787 if (taskwindow)
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
788 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
789 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
790 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
791
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
792
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
793 /* Create a new socket object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
794 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
795 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
796 in NEWOBJ()). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
797
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
798 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
799 new_sockobject(SOCKET_T fd, int family, int type, int proto)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
800 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
801 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
802 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
803 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
804 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
805 init_sockobject(s, fd, family, type, proto);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
808
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
809
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
810 /* 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
811 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
812 #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
813 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
814 #endif
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
815
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
816
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
817 /* 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
818 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
819 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
820 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
821 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
822
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
823 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
824 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
825 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
826 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
827 int error;
28925
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
828 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
829 char ch;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
830
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
831 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
832 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
833 int siz;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
834 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
835 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
836 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
837 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
838 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
839 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
840 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
841 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
842 /* 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
843 *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
844 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
845 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
846 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
847 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
848 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
849 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
850 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
851 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
852 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
853 siz = 4;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
854 break;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
855 #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
856 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
857 siz = 16;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
858 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
859 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
860 default:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
861 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
862 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
863 "unsupported address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
864 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
865 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
866 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
867 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
868 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
869 "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
870 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
871 }
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
872 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
873 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
874 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
875 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
876 return siz;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
877 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
878 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
879 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
880 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
881 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
882 "address family mismatched");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
883 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
884 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
885 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
886 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
887 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
888 #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
889 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
890 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
891 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
892 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
893 }
28925
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
894 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
895 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
896 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
897 struct sockaddr_in *sin;
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
898 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
899 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
900 ((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
901 ((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
902 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
903 #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
904 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
905 #endif
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
906 return 4;
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
907 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
908 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
909 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
910 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
911 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
912 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
913 #if defined(__digital__) && defined(__unix__)
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
914 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
915 /* 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
916 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
917 hints.ai_family = AF_INET;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
918 error = getaddrinfo(name, NULL, &hints, &res);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
919 }
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
920 #endif
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
921 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
922 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
923 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
924 set_gaierror(error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
925 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
926 }
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
927 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
928 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
929 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
930 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
931 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
932 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
933 return 4;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
934 #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
935 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
936 return 16;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
937 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
938 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
939 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
940 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
941 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
942 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
943
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
944
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
945 /* 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
946 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
947 size numbers). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
948
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
949 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
950 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
951 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
952 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
953 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
954
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
955 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
956 NI_NUMERICHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
957 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
958 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
959 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
960 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
961 return PyString_FromString(buf);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
962 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
963
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
964
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
965 #ifdef USE_BLUETOOTH
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
966 /* 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
967 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
968 an error occurred. */
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
969
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
970 static int
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
971 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
972 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
973 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
974 char ch;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
975 int n;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
976
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
977 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
978 &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
979 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
980 bdaddr->b[0] = b0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
981 bdaddr->b[1] = b1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
982 bdaddr->b[2] = b2;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
983 bdaddr->b[3] = b3;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
984 bdaddr->b[4] = b4;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
985 bdaddr->b[5] = b5;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
986 return 6;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
987 } else {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
988 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
989 return -1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
990 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
991 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
992
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
993 /* 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
994 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
995 value (zero padded if necessary). */
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
996
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
997 static PyObject *
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
998 makebdaddr(bdaddr_t *bdaddr)
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
999 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1000 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
1001
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1002 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
1003 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
1004 bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1005 return PyString_FromString(buf);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1006 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1007 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1008
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1009
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1010 /* 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
1011 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
1012 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
1013 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
1014
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1015 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1016 static PyObject *
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1017 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1018 {
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
1019 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
1020 /* No address -- may be recvfrom() from known socket */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1021 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1022 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
1023 }
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
1024
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1025 #ifdef __BEOS__
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
1026 /* XXX: BeOS version of accept() doesn't set family correctly */
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1027 addr->sa_family = AF_INET;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1028 #endif
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1029
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1030 switch (addr->sa_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1031
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1032 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1033 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1034 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
1035 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
1036 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1037 if (addrobj) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1038 a = (struct sockaddr_in *)addr;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1039 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
1040 Py_DECREF(addrobj);
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1041 }
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
1042 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1043 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1044
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
1045 #if defined(AF_UNIX)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1046 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1047 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1048 struct sockaddr_un *a = (struct sockaddr_un *) addr;
37853
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1049 #ifdef linux
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1050 if (a->sun_path[0] == 0) { /* Linux abstract namespace */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1051 addrlen -= (sizeof(*a) - sizeof(a->sun_path));
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1052 return PyString_FromStringAndSize(a->sun_path,
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1053 addrlen);
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1054 }
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1055 else
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1056 #endif /* linux */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1057 {
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1058 /* regular NULL-terminated string */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1059 return PyString_FromString(a->sun_path);
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1060 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1061 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1062 #endif /* AF_UNIX */
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1063
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1064 #if defined(AF_NETLINK)
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1065 case AF_NETLINK:
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1066 {
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1067 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
1068 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
1069 }
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1070 #endif /* AF_NETLINK */
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1071
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1072 #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
1073 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1074 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1075 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
1076 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
1077 PyObject *ret = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1078 if (addrobj) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1079 a = (struct sockaddr_in6 *)addr;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1080 ret = Py_BuildValue("Oiii",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1081 addrobj,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1082 ntohs(a->sin6_port),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1083 a->sin6_flowinfo,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1084 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
1085 Py_DECREF(addrobj);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1086 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1087 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1088 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1089 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1090
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1091 #ifdef USE_BLUETOOTH
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1092 case AF_BLUETOOTH:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1093 switch (proto) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1094
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1095 case BTPROTO_L2CAP:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1096 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1097 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
1098 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
1099 PyObject *ret = NULL;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1100 if (addrobj) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1101 ret = Py_BuildValue("Oi",
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1102 addrobj,
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1103 _BT_L2_MEMB(a, psm));
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1104 Py_DECREF(addrobj);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1105 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1106 return ret;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1107 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1108
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1109 case BTPROTO_RFCOMM:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1110 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1111 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
1112 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
1113 PyObject *ret = NULL;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1114 if (addrobj) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1115 ret = Py_BuildValue("Oi",
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1116 addrobj,
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1117 _BT_RC_MEMB(a, channel));
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1118 Py_DECREF(addrobj);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1119 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1120 return ret;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1121 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1122
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1123 #if !defined(__FreeBSD__)
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1124 case BTPROTO_SCO:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1125 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1126 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
1127 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
1128 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1129 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1130
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1131 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1132 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1133
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
1134 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1135 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1136 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1137 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
1138 char *ifname = "";
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1139 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
1140 /* 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
1141 if (a->sll_ifindex) {
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1142 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
1143 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0)
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1144 ifname = ifr.ifr_name;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1145 }
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1146 return Py_BuildValue("shbhs#",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1147 ifname,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1148 ntohs(a->sll_protocol),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1149 a->sll_pkttype,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1150 a->sll_hatype,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1151 a->sll_addr,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1152 a->sll_halen);
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1153 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1154 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1155
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1156 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1157
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1158 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
1159 /* If we don't know the address family, don't raise an
cf818b70da3e In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1160 exception -- return it as a tuple. */
cf818b70da3e In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1161 return Py_BuildValue("is#",
cf818b70da3e In makesockaddr(), if we don't know the address family, don't raise an
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
1162 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
1163 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
1164 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
1165
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1166 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1167 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1168
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1169
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1170 /* 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
1171 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
1172 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
1173 through len_ret. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1174
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1175 static int
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1176 getsockaddrarg(PySocketSockObject *s, PyObject *args,
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1177 struct sockaddr **addr_ret, int *len_ret)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1178 {
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1179 switch (s->sock_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1180
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
1181 #if defined(AF_UNIX)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1182 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1183 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1184 struct sockaddr_un* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1185 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1186 int len;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1187 addr = (struct sockaddr_un*)&(s->sock_addr).un;
9307
928ea5a409e5 Use the t# format where appropriate. Greg Stein.
Guido van Rossum <guido@python.org>
parents: 9203
diff changeset
1188 if (!PyArg_Parse(args, "t#", &path, &len))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1189 return 0;
37853
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1190 #ifdef linux
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1191 if (len > 0 && path[0] == 0) {
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1192 /* Linux abstract namespace extension */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1193 if (len > sizeof addr->sun_path) {
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1194 PyErr_SetString(socket_error,
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1195 "AF_UNIX path too long");
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1196 return 0;
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1197 }
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1198 }
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1199 else
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1200 #endif /* linux */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1201 {
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1202 /* regular NULL-terminated string */
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1203 if (len >= sizeof addr->sun_path) {
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1204 PyErr_SetString(socket_error,
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1205 "AF_UNIX path too long");
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1206 return 0;
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1207 }
29257ef6abeb SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents: 37732
diff changeset
1208 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
1209 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1210 addr->sun_family = s->sock_family;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1211 memcpy(addr->sun_path, path, len);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1212 *addr_ret = (struct sockaddr *) addr;
31896
ca2fb5cf2fd5 Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 31867
diff changeset
1213 #if defined(PYOS_OS2)
ca2fb5cf2fd5 Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 31867
diff changeset
1214 *len_ret = sizeof(*addr);
ca2fb5cf2fd5 Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 31867
diff changeset
1215 #else
3666
556ec82f4d93 Calculate length of AF_UNIX addr struct portably in getsockaddrarg().
Guido van Rossum <guido@python.org>
parents: 3665
diff changeset
1216 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
31896
ca2fb5cf2fd5 Fixes for AF_UNIX support on OS/2:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 31867
diff changeset
1217 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1218 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1219 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1220 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1221
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1222 #if defined(AF_NETLINK)
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1223 case AF_NETLINK:
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1224 {
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1225 struct sockaddr_nl* addr;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1226 int pid, groups;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1227 addr = (struct sockaddr_nl *)&(s->sock_addr).nl;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1228 if (!PyTuple_Check(args)) {
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1229 PyErr_Format(
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1230 PyExc_TypeError,
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1231 "getsockaddrarg: "
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1232 "AF_NETLINK address must be tuple, not %.500s",
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1233 args->ob_type->tp_name);
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1234 return 0;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1235 }
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1236 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
1237 return 0;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1238 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
1239 addr->nl_pid = pid;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1240 addr->nl_groups = groups;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1241 *addr_ret = (struct sockaddr *) addr;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1242 *len_ret = sizeof(*addr);
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1243 return 1;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1244 }
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1245 #endif
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1246
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1247 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1248 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1249 struct sockaddr_in* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1250 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
1251 int port, result;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1252 addr=(struct sockaddr_in*)&(s->sock_addr).in;
15466
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
1253 if (!PyTuple_Check(args)) {
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1254 PyErr_Format(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1255 PyExc_TypeError,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1256 "getsockaddrarg: "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1257 "AF_INET address must be tuple, not %.500s",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1258 args->ob_type->tp_name);
15466
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
1259 return 0;
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
1260 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
1261 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
1262 "idna", &host, &port))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1263 return 0;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
1264 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
1265 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
1266 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
1267 if (result < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1268 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1269 addr->sin_family = AF_INET;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
1270 addr->sin_port = htons((short)port);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1271 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1272 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1273 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1274 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1275
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1276 #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
1277 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1278 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1279 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
1280 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
1281 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
1282 addr = (struct sockaddr_in6*)&(s->sock_addr).in6;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1283 flowinfo = scope_id = 0;
37979
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1284 if (!PyTuple_Check(args)) {
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1285 PyErr_Format(
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1286 PyExc_TypeError,
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1287 "getsockaddrarg: "
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1288 "AF_INET6 address must be tuple, not %.500s",
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1289 args->ob_type->tp_name);
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1290 return 0;
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1291 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
1292 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
1293 "idna", &host, &port, &flowinfo,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1294 &scope_id)) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1295 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1296 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
1297 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
1298 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
1299 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
1300 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
1301 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1302 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
1303 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
1304 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
1305 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
1306 *addr_ret = (struct sockaddr *) addr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1307 *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
1308 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1309 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1310 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1311
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1312 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1313 case AF_BLUETOOTH:
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1314 {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1315 switch (s->sock_proto) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1316 case BTPROTO_L2CAP:
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1317 {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1318 struct sockaddr_l2 *addr = (struct sockaddr_l2 *) _BT_SOCKADDR_MEMB(s, l2);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1319 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1320
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1321 _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
1322 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
1323 &_BT_L2_MEMB(addr, psm))) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1324 PyErr_SetString(socket_error, "getsockaddrarg: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1325 "wrong format");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1326 return 0;
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1327 }
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1328 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
1329 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1330
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1331 *addr_ret = (struct sockaddr *) addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1332 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1333 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1334 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1335 case BTPROTO_RFCOMM:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1336 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1337 struct sockaddr_rc *addr = (struct sockaddr_rc *) _BT_SOCKADDR_MEMB(s, rc);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1338 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1339
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1340 _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
1341 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
1342 &_BT_RC_MEMB(addr, channel))) {
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: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1344 "wrong format");
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1345 return 0;
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1346 }
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1347 if (setbdaddr(straddr, &_BT_RC_MEMB(addr, bdaddr)) < 0)
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1348 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1349
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1350 *addr_ret = (struct sockaddr *) addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1351 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1352 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1353 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1354 #if !defined(__FreeBSD__)
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1355 case BTPROTO_SCO:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1356 {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1357 struct sockaddr_sco *addr = (struct sockaddr_sco *) _BT_SOCKADDR_MEMB(s, sco);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1358 char *straddr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1359
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1360 _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1361 straddr = PyString_AsString(args);
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1362 if (straddr == NULL) {
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1363 PyErr_SetString(socket_error, "getsockaddrarg: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1364 "wrong format");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1365 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1366 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1367 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
1368 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1369
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1370 *addr_ret = (struct sockaddr *) addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1371 *len_ret = sizeof *addr;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1372 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1373 }
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1374 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1375 default:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1376 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
1377 return 0;
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1378 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1379 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1380 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1381
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
1382 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1383 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1384 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1385 struct sockaddr_ll* addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1386 struct ifreq ifr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1387 char *interfaceName;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1388 int protoNumber;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1389 int hatype = 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1390 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
1391 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
1392 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
1393
37979
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1394 if (!PyTuple_Check(args)) {
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1395 PyErr_Format(
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1396 PyExc_TypeError,
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1397 "getsockaddrarg: "
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1398 "AF_PACKET address must be tuple, not %.500s",
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1399 args->ob_type->tp_name);
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1400 return 0;
704b80529664 Fix SF bug #1476111: SystemError in socket sendto. The AF_INET6 and
Thomas Wouters <thomas@python.org>
parents: 37934
diff changeset
1401 }
32611
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1402 if (!PyArg_ParseTuple(args, "si|iis#", &interfaceName,
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1403 &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
1404 &haddr, &halen))
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1405 return 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1406 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
1407 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
1408 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
1409 s->errorhandler();
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1410 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
1411 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1412 addr = &(s->sock_addr.ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1413 addr->sll_family = AF_PACKET;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1414 addr->sll_protocol = htons((short)protoNumber);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1415 addr->sll_ifindex = ifr.ifr_ifindex;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1416 addr->sll_pkttype = pkttype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1417 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
1418 if (halen > 8) {
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1419 PyErr_SetString(PyExc_ValueError,
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1420 "Hardware address must be 8 bytes or less");
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1421 return 0;
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1422 }
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1423 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
1424 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
1425 }
8b3288f607e1 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses
Andrew M. Kuchling <amk@amk.ca>
parents: 32578
diff changeset
1426 addr->sll_halen = halen;
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1427 *addr_ret = (struct sockaddr *) addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1428 *len_ret = sizeof *addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1429 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1430 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1431 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1432
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1433 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1434
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1435 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1436 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
1437 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1438
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1439 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1440 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1441
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1442
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1443 /* 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
1444 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
1445 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
1446
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1447 static int
13554
906efc1da247 Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13538
diff changeset
1448 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
1449 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1450 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
1451
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
1452 #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
1453 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
1454 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1455 *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
1456 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1457 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1458 #endif /* AF_UNIX */
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1459 #if defined(AF_NETLINK)
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1460 case AF_NETLINK:
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1461 {
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1462 *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
1463 return 1;
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1464 }
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
1465 #endif
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1466
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1467 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
1468 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1469 *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
1470 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1471 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1472
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1473 #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
1474 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1475 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1476 *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
1477 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1478 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1479 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1480
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1481 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1482 case AF_BLUETOOTH:
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1483 {
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1484 switch(s->sock_proto)
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1485 {
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1486
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1487 case BTPROTO_L2CAP:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1488 *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
1489 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1490 case BTPROTO_RFCOMM:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1491 *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
1492 return 1;
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
1493 #if !defined(__FreeBSD__)
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1494 case BTPROTO_SCO:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1495 *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
1496 return 1;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1497 #endif
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1498 default:
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1499 PyErr_SetString(socket_error, "getsockaddrlen: "
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1500 "unknown BT protocol");
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1501 return 0;
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1502
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1503 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1504 }
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1505 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
1506
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
1507 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1508 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1509 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1510 *len_ret = sizeof (struct sockaddr_ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1511 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1512 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1513 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1514
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1515 /* 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
1516
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1517 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1518 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
1519 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1520
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1521 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1522 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1523
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1524
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1525 /* s.accept() method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1526
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1527 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
1528 sock_accept(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1529 {
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
1530 sock_addr_t addrbuf;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1531 SOCKET_T newfd;
12479
a3e1fecb43c6 Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents: 12436
diff changeset
1532 socklen_t addrlen;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1533 PyObject *sock = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1534 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1535 PyObject *res = NULL;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1536 int timeout;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1537
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1538 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
1539 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
1540 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
1541
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1542 #ifdef MS_WINDOWS
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1543 newfd = INVALID_SOCKET;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1544 #else
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1545 newfd = -1;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1546 #endif
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1547
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1548 if (!IS_SELECTABLE(s))
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1549 return select_error();
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1550
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1551 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1552 timeout = internal_select(s, 0);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1553 if (!timeout)
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
1554 newfd = accept(s->sock_fd, (struct sockaddr *) &addrbuf,
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1555 &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1556 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
1557
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1558 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1559 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1560 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1561 }
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1562
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1563 #ifdef MS_WINDOWS
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1564 if (newfd == INVALID_SOCKET)
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1565 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1566 if (newfd < 0)
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1567 #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
1568 return s->errorhandler();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1569
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1570 /* Create the new object with unspecified family,
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1571 to avoid calls to bind() etc. on it. */
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1572 sock = (PyObject *) new_sockobject(newfd,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1573 s->sock_family,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1574 s->sock_type,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1575 s->sock_proto);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1576
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1577 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
1578 SOCKETCLOSE(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1579 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1580 }
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
1581 addr = makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf,
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
1582 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
1583 if (addr == NULL)
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1584 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1585
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30646
diff changeset
1586 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
1587
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1588 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1589 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1590 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1591 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1592 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1593
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1594 PyDoc_STRVAR(accept_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1595 "accept() -> (socket object, address info)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1596 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1597 Wait for an incoming connection. Return a new socket representing the\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1598 connection, and the address of the client. 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
1599 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
1600
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1601 /* s.setblocking(flag) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1602 False -- non-blocking mode; same as settimeout(0)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1603 True -- blocking mode; same as settimeout(None)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1604 */
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1605
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1606 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
1607 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
1608 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1609 int block;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1610
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1611 block = PyInt_AsLong(arg);
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1612 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
1613 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1614
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1615 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
1616 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
1617
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1618 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1619 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
1620 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1621
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1622 PyDoc_STRVAR(setblocking_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1623 "setblocking(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1624 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1625 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
1626 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
1627 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
1628
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1629 /* s.settimeout(timeout) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1630 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
1631 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
1632 > 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
1633 < 0 -- illegal; raises an exception
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1634 */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1635 static PyObject *
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1636 sock_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
1637 {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1638 double timeout;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1639
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1640 if (arg == Py_None)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1641 timeout = -1.0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1642 else {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1643 timeout = PyFloat_AsDouble(arg);
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1644 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
1645 if (!PyErr_Occurred())
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1646 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1647 "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
1648 return NULL;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1649 }
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
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1652 s->sock_timeout = timeout;
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1653 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
1654
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1655 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1656 return Py_None;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1657 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1658
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1659 PyDoc_STRVAR(settimeout_doc,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1660 "settimeout(timeout)\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1661 \n\
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1662 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
1663 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
1664 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
1665 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
1666
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1667 /* s.gettimeout() method.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1668 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
1669 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
1670 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
1671 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1672 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
1673 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1674 return Py_None;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1675 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1676 else
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1677 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
1678 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1679
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1680 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
1681 "gettimeout() -> timeout\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1682 \n\
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1683 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
1684 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
1685 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
1686
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1687 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1688 /* s.sleeptaskw(1 | 0) method */
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1689
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1690 static PyObject *
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
1691 sock_sleeptaskw(PySocketSockObject *s,PyObject *arg)
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1692 {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1693 int block;
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
1694 block = PyInt_AsLong(arg);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
1695 if (block == -1 && PyErr_Occurred())
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1696 return NULL;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1697 Py_BEGIN_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1698 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1699 Py_END_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1700
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1701 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1702 return Py_None;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1703 }
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1704 PyDoc_STRVAR(sleeptaskw_doc,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1705 "sleeptaskw(flag)\n\
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1706 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1707 Allow sleeps in taskwindows.");
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1708 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1709
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1710
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
1711 /* 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
1712 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
1713 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
1714 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
1715
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1716 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
1717 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
1718 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1719 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1720 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
1721 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
1722 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
1723 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1724 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1725
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1726 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
1727 &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
1728 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
1729 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
1730 }
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
1731 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1732 PyErr_Clear();
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1733 if (!PyArg_ParseTuple(args, "iis#:setsockopt",
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1734 &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
1735 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
1736 }
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
1737 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
1738 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
1739 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1740 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1741 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1742 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1743
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1744 PyDoc_STRVAR(setsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1745 "setsockopt(level, option, value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1746 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1747 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
1748 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
1749
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1750
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
1751 /* 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
1752 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
1753 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
1754 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
1755
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1756 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
1757 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
1758 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1759 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1760 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
1761 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1762 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
1763 socklen_t buflen = 0;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1764
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1765 #ifdef __BEOS__
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1766 /* We have incomplete socket support. */
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1767 PyErr_SetString(socket_error, "getsockopt not supported");
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1768 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1769 #else
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1770
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1771 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
1772 &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
1773 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1774
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
1775 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
1776 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
1777 socklen_t flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1778 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
1779 (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
1780 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
1781 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1782 return PyInt_FromLong(flag);
1039
6aa0ee14ac2e Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1783 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1784 #ifdef __VMS
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
1785 /* socklen_t is unsigned so no negative test is needed,
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
1786 test buflen == 0 is previously done */
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1787 if (buflen > 1024) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1788 #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
1789 if (buflen <= 0 || buflen > 1024) {
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1790 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1791 PyErr_SetString(socket_error,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1792 "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
1793 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
1794 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1795 buf = PyString_FromStringAndSize((char *)NULL, buflen);
1039
6aa0ee14ac2e Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1796 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
1797 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1798 res = getsockopt(s->sock_fd, level, optname,
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1799 (void *)PyString_AS_STRING(buf), &buflen);
1039
6aa0ee14ac2e Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1800 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1801 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
1802 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
1803 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1804 _PyString_Resize(&buf, buflen);
1039
6aa0ee14ac2e Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1805 return buf;
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1806 #endif /* __BEOS__ */
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1807 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1808
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1809 PyDoc_STRVAR(getsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1810 "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
1811 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1812 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
1813 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
1814 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
1815
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1816
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1817 /* s.bind(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1818
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1819 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
1820 sock_bind(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1821 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1822 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1823 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1824 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
1825
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1826 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1827 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1828 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1829 res = bind(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1830 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1831 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
1832 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1833 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1834 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1835 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1836
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1837 PyDoc_STRVAR(bind_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1838 "bind(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1839 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1840 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
1841 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
1842 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
1843
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1844
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1845 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1846 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
1847 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1848
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1849 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
1850 sock_close(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1851 {
15604
15e1eb1019b8 Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
Guido van Rossum <guido@python.org>
parents: 15466
diff changeset
1852 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
1853
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
1854 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
1855 s->sock_fd = -1;
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1856 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
1857 (void) SOCKETCLOSE(fd);
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1858 Py_END_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1859 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1860 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1861 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1862 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1863
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1864 PyDoc_STRVAR(close_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1865 "close()\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1866 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1867 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
1868
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1869 static int
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1870 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
1871 int *timeoutp)
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1872 {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1873 int res, timeout;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1874
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1875 timeout = 0;
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1876 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
1877
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1878 #ifdef MS_WINDOWS
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1879
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1880 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
1881 if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK &&
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
1882 IS_SELECTABLE(s)) {
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1883 /* 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
1884 fd_set fds;
32909
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1885 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
1886 struct timeval tv;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1887 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
1888 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
1889 FD_ZERO(&fds);
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1890 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
1891 FD_ZERO(&fds_exc);
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1892 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
1893 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
1894 if (res == 0) {
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1895 res = WSAEWOULDBLOCK;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1896 timeout = 1;
32909
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1897 } else if (res > 0) {
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1898 if (FD_ISSET(s->sock_fd, &fds))
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1899 /* The socket is in the writeable set - this
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1900 means connected */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1901 res = 0;
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1902 else {
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1903 /* 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
1904 to get the underlying error */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1905 int res_size = sizeof res;
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1906 /* 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
1907 assert(FD_ISSET(s->sock_fd, &fds_exc));
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
1908 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
1909 (char *)&res, &res_size))
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1910 /* getsockopt also clears WSAGetLastError,
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1911 so reset it back. */
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1912 WSASetLastError(res);
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1913 else
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1914 res = WSAGetLastError();
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1915 }
65319607bed8 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
Mark Hammond <mhammond@skippinet.com.au>
parents: 32764
diff changeset
1916 }
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1917 /* 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
1918 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1919 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1920
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1921 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1922 res = WSAGetLastError();
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1923
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1924 #else
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 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
1927 if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1928 timeout = internal_select(s, 1);
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1929 if (timeout == 0) {
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1930 res = connect(s->sock_fd, addr, addrlen);
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1931 if (res < 0 && errno == EISCONN)
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1932 res = 0;
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1933 }
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1934 else if (timeout == -1)
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1935 res = errno; /* had error */
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1936 else
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1937 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
1938 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1939 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1940
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1941 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1942 res = errno;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1943
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1944 #endif
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1945 *timeoutp = timeout;
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1946
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1947 return res;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1948 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1949
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1950 /* s.connect(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1951
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1952 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
1953 sock_connect(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1954 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1955 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1956 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1957 int res;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1958 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
1959
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1960 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1961 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1962
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1963 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1964 res = internal_connect(s, addr, addrlen, &timeout);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1965 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
1966
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
1967 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1968 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1969 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1970 }
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1971 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
1972 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1973 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1974 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1975 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1976
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1977 PyDoc_STRVAR(connect_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1978 "connect(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1979 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1980 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
1981 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
1982
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1983
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1984 /* 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
1985
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1986 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
1987 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
1988 {
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1989 struct sockaddr *addr;
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1990 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
1991 int res;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1992 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
1993
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1994 if (!getsockaddrarg(s, addro, &addr, &addrlen))
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1995 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1996
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1997 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
1998 res = internal_connect(s, addr, 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
1999 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
2000
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2001 /* Signals are not errors (though they may raise exceptions). Adapted
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2002 from PyErr_SetFromErrnoWithFilenameObject(). */
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2003 #ifdef EINTR
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2004 if (res == EINTR && PyErr_CheckSignals())
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2005 return NULL;
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2006 #endif
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2007
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
2008 return PyInt_FromLong((long) res);
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
2009 }
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
2010
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2011 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
2012 "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
2013 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2014 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
2015 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
2016
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
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 /* 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
2019
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2020 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
2021 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
2022 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2023 #if SIZEOF_SOCKET_T <= SIZEOF_LONG
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2024 return PyInt_FromLong((long) s->sock_fd);
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2025 #else
28437
871da703e4c0 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents: 27981
diff changeset
2026 return PyLong_FromLongLong((PY_LONG_LONG)s->sock_fd);
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2027 #endif
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
2028 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
2029
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2030 PyDoc_STRVAR(fileno_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2031 "fileno() -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2032 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2033 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
2034
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
2035
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
2036 #ifndef NO_DUP
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2037 /* s.dup() method */
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2038
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
2039 static PyObject *
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2040 sock_dup(PySocketSockObject *s)
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2041 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2042 SOCKET_T newfd;
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2043 PyObject *sock;
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2044
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
2045 newfd = dup(s->sock_fd);
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2046 if (newfd < 0)
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
2047 return s->errorhandler();
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2048 sock = (PyObject *) new_sockobject(newfd,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2049 s->sock_family,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2050 s->sock_type,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2051 s->sock_proto);
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2052 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
2053 SOCKETCLOSE(newfd);
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2054 return sock;
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2055 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2056
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2057 PyDoc_STRVAR(dup_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2058 "dup() -> socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2059 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2060 Return a new socket object connected to the same system resource.");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2061
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
2062 #endif
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2063
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
2064
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2065 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2066
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2067 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
2068 sock_getsockname(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2069 {
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
2070 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
2071 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
2072 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
2073
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2074 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2075 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
2076 memset(&addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2077 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
2078 res = getsockname(s->sock_fd, (struct sockaddr *) &addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2079 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2080 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
2081 return s->errorhandler();
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
2082 return makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, addrlen,
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
2083 s->sock_proto);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2084 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2085
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2086 PyDoc_STRVAR(getsockname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2087 "getsockname() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2088 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2089 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
2090 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
2091
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2092
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2093 #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
2094 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2095
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2096 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
2097 sock_getpeername(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2098 {
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
2099 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
2100 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
2101 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
2102
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2103 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2104 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
2105 memset(&addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2106 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
2107 res = getpeername(s->sock_fd, (struct sockaddr *) &addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2108 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2109 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
2110 return s->errorhandler();
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
2111 return makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf, addrlen,
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
2112 s->sock_proto);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2113 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2114
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2115 PyDoc_STRVAR(getpeername_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2116 "getpeername() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2117 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2118 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
2119 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
2120
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2121 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2122
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
2123
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2124 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2125
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2126 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
2127 sock_listen(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2128 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2129 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2130 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
2131
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2132 backlog = PyInt_AsLong(arg);
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2133 if (backlog == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2134 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2135 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2136 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2137 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2138 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2139 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2140 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
2141 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2142 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2143 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2144 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2145
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2146 PyDoc_STRVAR(listen_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2147 "listen(backlog)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2148 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2149 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
2150 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
2151 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
2152
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2153
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2154 #ifndef NO_DUP
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2155 /* s.makefile(mode) method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2156 Create a new open file object referring to a dupped version of
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2157 the socket's file descriptor. (The dup() call is necessary so
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2158 that the open file and socket objects may be closed independent
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2159 of each other.)
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2160 The mode argument specifies 'r' or 'w' passed to fdopen(). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2161
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2162 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
2163 sock_makefile(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2164 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13403
diff changeset
2165 extern int fclose(FILE *);
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2166 char *mode = "r";
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2167 int bufsize = -1;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2168 #ifdef MS_WIN32
19568
b0f5278a2ab4 SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents: 19415
diff changeset
2169 Py_intptr_t fd;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2170 #else
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2171 int fd;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2172 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2173 FILE *fp;
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2174 PyObject *f;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2175 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2176 char *mode_r = "r";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2177 char *mode_w = "w";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2178 #endif
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2179
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
2180 if (!PyArg_ParseTuple(args, "|si:makefile", &mode, &bufsize))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2181 return NULL;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2182 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2183 if (strcmp(mode,"rb") == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2184 mode = mode_r;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2185 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2186 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2187 if (strcmp(mode,"wb") == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2188 mode = mode_w;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2189 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2190 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
2191 #endif
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2192 #ifdef MS_WIN32
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2193 if (((fd = _open_osfhandle(s->sock_fd, _O_BINARY)) < 0) ||
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2194 ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL))
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
2195 #else
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2196 if ((fd = dup(s->sock_fd)) < 0 || (fp = fdopen(fd, mode)) == NULL)
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
2197 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2198 {
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2199 if (fd >= 0)
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
2200 SOCKETCLOSE(fd);
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
2201 return s->errorhandler();
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2202 }
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2203 f = PyFile_FromFile(fp, "<socket>", mode, fclose);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2204 if (f != NULL)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2205 PyFile_SetBufSize(f, bufsize);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
2206 return f;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2207 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2208
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2209 PyDoc_STRVAR(makefile_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2210 "makefile([mode[, buffersize]]) -> file object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2211 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2212 Return a regular file object corresponding to the socket.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2213 The mode and buffersize arguments are as for the built-in open() function.");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2214
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2215 #endif /* NO_DUP */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2216
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2217 /*
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2218 * This is the guts of the recv() and recv_into() methods, which reads into a
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2219 * char buffer. If you have any inc/def ref to do to the objects that contain
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2220 * the buffer, do it in the caller. This function returns the number of bytes
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2221 * succesfully read. If there was an error, it returns -1. Note that it is
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2222 * also possible that we return a number of bytes smaller than the request
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2223 * bytes.
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2224 */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2225 static ssize_t
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2226 sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2227 {
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2228 ssize_t outlen = -1;
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2229 int timeout;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2230 #ifdef __VMS
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2231 int remaining;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2232 char *read_buf;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2233 #endif
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2234
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2235 if (!IS_SELECTABLE(s)) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2236 select_error();
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2237 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2238 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2239
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2240 #ifndef __VMS
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2241 Py_BEGIN_ALLOW_THREADS
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2242 timeout = internal_select(s, 0);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2243 if (!timeout)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2244 outlen = recv(s->sock_fd, cbuf, len, flags);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2245 Py_END_ALLOW_THREADS
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2246
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2247 if (timeout == 1) {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2248 PyErr_SetString(socket_timeout, "timed out");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2249 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2250 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2251 if (outlen < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2252 /* Note: the call to errorhandler() ALWAYS indirectly returned
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2253 NULL, so ignore its return value */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2254 s->errorhandler();
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2255 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2256 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2257 #else
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2258 read_buf = cbuf;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2259 remaining = len;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2260 while (remaining != 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2261 unsigned int segment;
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2262 int nread = -1;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2263
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2264 segment = remaining /SEGMENT_SIZE;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2265 if (segment != 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2266 segment = SEGMENT_SIZE;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2267 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2268 else {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2269 segment = remaining;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2270 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2271
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2272 Py_BEGIN_ALLOW_THREADS
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2273 timeout = internal_select(s, 0);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2274 if (!timeout)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2275 nread = recv(s->sock_fd, read_buf, segment, flags);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2276 Py_END_ALLOW_THREADS
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2277
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2278 if (timeout == 1) {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2279 PyErr_SetString(socket_timeout, "timed out");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2280 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2281 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2282 if (nread < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2283 s->errorhandler();
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2284 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2285 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2286 if (nread != remaining) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2287 read_buf += nread;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2288 break;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2289 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2290
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2291 remaining -= segment;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2292 read_buf += segment;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2293 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2294 outlen = read_buf - cbuf;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2295 #endif /* !__VMS */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2296
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2297 return outlen;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2298 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2299
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2300
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
2301 /* 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
2302
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2303 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
2304 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
2305 {
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2306 int recvlen, flags = 0;
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2307 ssize_t outlen;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2308 PyObject *buf;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2309
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2310 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
2311 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2312
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2313 if (recvlen < 0) {
21022
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
2314 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
2315 "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
2316 return NULL;
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
2317 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2318
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2319 /* Allocate a new string. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2320 buf = PyString_FromStringAndSize((char *) 0, recvlen);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2321 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2322 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2323
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2324 /* Call the guts */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2325 outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags);
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2326 if (outlen < 0) {
39251
c4ac6ea497a1 Fix spelling.
Georg Brandl <georg@python.org>
parents: 39242
diff changeset
2327 /* An error occurred, release the string and return an
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2328 error. */
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2329 Py_DECREF(buf);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2330 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2331 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2332 if (outlen != recvlen) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2333 /* We did not read as many bytes as we anticipated, resize the
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2334 string if possible and be succesful. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2335 if (_PyString_Resize(&buf, outlen) < 0)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2336 /* Oopsy, not so succesful after all. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2337 return NULL;
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
2338 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2339
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2340 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2341 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2342
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2343 PyDoc_STRVAR(recv_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2344 "recv(buffersize[, flags]) -> data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2345 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2346 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
2347 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
2348 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
2349 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
2350
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2351
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2352 /* s.recv_into(buffer, [nbytes [,flags]]) method */
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2354 static PyObject*
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2355 sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds)
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2356 {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2357 static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2358
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2359 int recvlen = 0, flags = 0;
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2360 ssize_t readlen;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2361 char *buf;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2362 int buflen;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2363
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2364 /* Get the buffer's memory */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2365 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recv", kwlist,
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2366 &buf, &buflen, &recvlen, &flags))
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2367 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2368 assert(buf != 0 && buflen > 0);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2369
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2370 if (recvlen < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2371 PyErr_SetString(PyExc_ValueError,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2372 "negative buffersize in recv");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2373 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2374 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2375 if (recvlen == 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2376 /* If nbytes was not specified, use the buffer's length */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2377 recvlen = buflen;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2378 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2379
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2380 /* Check if the buffer is large enough */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2381 if (buflen < recvlen) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2382 PyErr_SetString(PyExc_ValueError,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2383 "buffer too small for requested bytes");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2384 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2385 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2386
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2387 /* Call the guts */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2388 readlen = sock_recv_guts(s, buf, recvlen, flags);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2389 if (readlen < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2390 /* Return an error. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2391 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2392 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2393
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2394 /* Return the number of bytes read. Note that we do not do anything
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2395 special here in the case that readlen < recvlen. */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2396 return PyInt_FromSsize_t(readlen);
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2397 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2398
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2399 PyDoc_STRVAR(recv_into_doc,
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2400 "recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2401 \n\
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2402 A version of recv() that stores its data into a buffer rather than creating \n\
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2403 a new string. Receive up to buffersize bytes from the socket. If buffersize \n\
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2404 is not specified (or 0), receive up to the size available in the given buffer.\n\
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2405 \n\
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2406 See recv() for documentation about the flags.");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2407
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2408
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2409 /*
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2410 * This is the guts of the recv() and recv_into() methods, which reads into a
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2411 * char buffer. If you have any inc/def ref to do to the objects that contain
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2412 * the buffer, do it in the caller. This function returns the number of bytes
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2413 * succesfully read. If there was an error, it returns -1. Note that it is
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2414 * also possible that we return a number of bytes smaller than the request
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2415 * bytes.
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2416 *
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2417 * 'addr' is a return value for the address object. Note that you must decref
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2418 * it yourself.
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2419 */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2420 static ssize_t
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2421 sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2422 PyObject** addr)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2423 {
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
2424 sock_addr_t addrbuf;
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2425 int timeout;
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2426 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
2427 socklen_t addrlen;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2428
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2429 *addr = NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2430
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
2431 if (!getsockaddrlen(s, &addrlen))
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2432 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2433
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2434 if (!IS_SELECTABLE(s)) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2435 select_error();
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2436 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2437 }
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2438
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2439 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
2440 memset(&addrbuf, 0, addrlen);
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2441 timeout = internal_select(s, 0);
37732
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2442 if (!timeout) {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2443 #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
2444 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2445 n = recvfrom(s->sock_fd, cbuf, len, flags,
37732
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2446 (struct sockaddr *) &addrbuf, &addrlen);
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2447 #else
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2448 n = recvfrom(s->sock_fd, cbuf, len, flags,
37732
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2449 (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
2450 #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
2451 #else
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2452 n = recvfrom(s->sock_fd, cbuf, len, flags,
37732
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2453 (struct sockaddr *) &addrbuf, &addrlen);
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2454 #endif
bfc48ad81e80 Patch #1191065: Fix preprocessor problems on systems where recvfrom
Martin v. Löwis <martin@v.loewis.de>
parents: 37629
diff changeset
2455 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2456 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
2457
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2458 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2459 PyErr_SetString(socket_timeout, "timed out");
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2460 return -1;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2461 }
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
2462 if (n < 0) {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2463 s->errorhandler();
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2464 return -1;
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
2465 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2466
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2467 if (!(*addr = makesockaddr(s->sock_fd, (struct sockaddr *) &addrbuf,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2468 addrlen, s->sock_proto)))
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2469 return -1;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2470
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2471 return n;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2472 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2473
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2474 /* s.recvfrom(nbytes [,flags]) method */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2475
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2476 static PyObject *
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2477 sock_recvfrom(PySocketSockObject *s, PyObject *args)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2478 {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2479 PyObject *buf = NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2480 PyObject *addr = NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2481 PyObject *ret = NULL;
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2482 int recvlen, flags = 0;
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2483 ssize_t outlen;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2484
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2485 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2486 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2487
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2488 buf = PyString_FromStringAndSize((char *) 0, recvlen);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2489 if (buf == NULL)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2490 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2491
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2492 outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf),
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2493 recvlen, flags, &addr);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2494 if (outlen < 0) {
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2495 goto finally;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2496 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2497
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2498 if (outlen != recvlen) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2499 /* We did not read as many bytes as we anticipated, resize the
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2500 string if possible and be succesful. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2501 if (_PyString_Resize(&buf, outlen) < 0)
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2502 /* Oopsy, not so succesful after all. */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2503 goto finally;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2504 }
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2505
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30646
diff changeset
2506 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
2507
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2508 finally:
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2509 Py_XDECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2510 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
2511 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2512 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2513
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2514 PyDoc_STRVAR(recvfrom_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2515 "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
2516 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2517 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
2518
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2519
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2520 /* s.recvfrom_into(buffer[, nbytes [,flags]]) method */
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2521
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2522 static PyObject *
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2523 sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2524 {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2525 static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2526
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2527 int recvlen = 0, flags = 0;
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2528 ssize_t readlen;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2529 char *buf;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2530 int buflen;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2531
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2532 PyObject *addr = NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2533
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2534 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recvfrom", kwlist,
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2535 &buf, &buflen, &recvlen, &flags))
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2536 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2537 assert(buf != 0 && buflen > 0);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2538
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2539 if (recvlen < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2540 PyErr_SetString(PyExc_ValueError,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2541 "negative buffersize in recv");
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2542 return NULL;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2543 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2544 if (recvlen == 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2545 /* If nbytes was not specified, use the buffer's length */
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2546 recvlen = buflen;
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2547 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2548
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2549 readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr);
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2550 if (readlen < 0) {
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2551 /* Return an error */
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2552 Py_XDECREF(addr);
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2553 return NULL;
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2554 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2555
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2556 /* Return the number of bytes read and the address. Note that we do
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2557 not do anything special here in the case that readlen < recvlen. */
38655
e3c08f066eb8 Fix a refleak in recvfrom_into
Neal Norwitz <nnorwitz@gmail.com>
parents: 38623
diff changeset
2558 return Py_BuildValue("lN", readlen, addr);
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2559 }
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2560
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2561 PyDoc_STRVAR(recvfrom_into_doc,
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2562 "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2563 \n\
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2564 Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info.");
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2565
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2566
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
2567 /* 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
2568
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2569 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
2570 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
2571 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2572 char *buf;
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2573 int len, n = -1, flags = 0, timeout;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2574
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
2575 if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags))
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2576 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2577
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2578 if (!IS_SELECTABLE(s))
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2579 return select_error();
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2580
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2581 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2582 timeout = internal_select(s, 1);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2583 if (!timeout)
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2584 #ifdef __VMS
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2585 n = sendsegmented(s->sock_fd, buf, len, flags);
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2586 #else
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2587 n = send(s->sock_fd, buf, len, flags);
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2588 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2589 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
2590
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2591 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2592 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2593 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2594 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2595 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
2596 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2597 return PyInt_FromLong((long)n);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2598 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2599
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2600 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
2601 "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
2602 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2603 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
2604 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
2605 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
2606
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2607
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2608 /* 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
2609
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2610 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
2611 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
2612 {
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2613 char *buf;
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2614 int len, n = -1, flags = 0, timeout;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2615
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2616 if (!PyArg_ParseTuple(args, "s#|i:sendall", &buf, &len, &flags))
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2617 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2618
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2619 if (!IS_SELECTABLE(s))
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2620 return select_error();
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2621
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2622 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
2623 do {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2624 timeout = internal_select(s, 1);
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2625 n = -1;
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2626 if (timeout)
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2627 break;
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2628 #ifdef __VMS
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2629 n = sendsegmented(s->sock_fd, buf, len, flags);
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2630 #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
2631 n = send(s->sock_fd, buf, len, flags);
39043
c67b23397f30 Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
2632 #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
2633 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
2634 break;
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2635 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
2636 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
2637 } 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
2638 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
2639
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2640 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2641 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2642 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2643 }
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2644 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
2645 return s->errorhandler();
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2646
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2647 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
2648 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
2649 }
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2650
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2651 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
2652 "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
2653 \n\
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2654 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
2655 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
2656 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
2657 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
2658
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2659
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
2660 /* 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
2661
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2662 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
2663 sock_sendto(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2664 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2665 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2666 char *buf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2667 struct sockaddr *addr;
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2668 int addrlen, len, 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
2669
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
2670 flags = 0;
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2671 if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2672 PyErr_Clear();
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2673 if (!PyArg_ParseTuple(args, "s#iO:sendto",
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2674 &buf, &len, &flags, &addro))
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
2675 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2676 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2677
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
2678 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2679 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2680
36452
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2681 if (!IS_SELECTABLE(s))
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2682 return select_error();
7789cc557e1e Bug #876637, prevent stack corruption when socket descriptor
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
2683
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2684 Py_BEGIN_ALLOW_THREADS
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2685 timeout = internal_select(s, 1);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2686 if (!timeout)
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2687 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2688 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
2689
39354
85fdcdfca85c Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents: 39251
diff changeset
2690 if (timeout == 1) {
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2691 PyErr_SetString(socket_timeout, "timed out");
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2692 return NULL;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
2693 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2694 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
2695 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2696 return PyInt_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2697 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2698
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2699 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
2700 "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
2701 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2702 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
2703 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
2704
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2705
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2706 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2707
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2708 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
2709 sock_shutdown(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2710 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2711 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2712 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
2713
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2714 how = PyInt_AsLong(arg);
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2715 if (how == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2716 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2717 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2718 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2719 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2720 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
2721 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2722 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2723 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2724 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2725
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2726 PyDoc_STRVAR(shutdown_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2727 "shutdown(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2728 \n\
31027
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
2729 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
2730 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
2731
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2732
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2733 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2734
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2735 static PyMethodDef sock_methods[] = {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2736 {"accept", (PyCFunction)sock_accept, METH_NOARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2737 accept_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2738 {"bind", (PyCFunction)sock_bind, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2739 bind_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2740 {"close", (PyCFunction)sock_close, METH_NOARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2741 close_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2742 {"connect", (PyCFunction)sock_connect, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2743 connect_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2744 {"connect_ex", (PyCFunction)sock_connect_ex, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2745 connect_ex_doc},
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2746 #ifndef NO_DUP
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2747 {"dup", (PyCFunction)sock_dup, METH_NOARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2748 dup_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2749 #endif
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2750 {"fileno", (PyCFunction)sock_fileno, METH_NOARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2751 fileno_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2752 #ifdef HAVE_GETPEERNAME
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2753 {"getpeername", (PyCFunction)sock_getpeername,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2754 METH_NOARGS, getpeername_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2755 #endif
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2756 {"getsockname", (PyCFunction)sock_getsockname,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2757 METH_NOARGS, getsockname_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2758 {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2759 getsockopt_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2760 {"listen", (PyCFunction)sock_listen, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2761 listen_doc},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2762 #ifndef NO_DUP
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2763 {"makefile", (PyCFunction)sock_makefile, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2764 makefile_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2765 #endif
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2766 {"recv", (PyCFunction)sock_recv, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2767 recv_doc},
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2768 {"recv_into", (PyCFunction)sock_recv_into, METH_VARARGS | METH_KEYWORDS,
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2769 recv_into_doc},
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2770 {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2771 recvfrom_doc},
38580
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2772 {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS | METH_KEYWORDS,
a114003aa3d3 Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents: 38498
diff changeset
2773 recvfrom_into_doc},
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2774 {"send", (PyCFunction)sock_send, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2775 send_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2776 {"sendall", (PyCFunction)sock_sendall, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2777 sendall_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2778 {"sendto", (PyCFunction)sock_sendto, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2779 sendto_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2780 {"setblocking", (PyCFunction)sock_setblocking, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2781 setblocking_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2782 {"settimeout", (PyCFunction)sock_settimeout, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2783 settimeout_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2784 {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2785 gettimeout_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2786 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2787 setsockopt_doc},
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2788 {"shutdown", (PyCFunction)sock_shutdown, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2789 shutdown_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2790 #ifdef RISCOS
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2791 {"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O,
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
2792 sleeptaskw_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2793 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2794 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2795 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2796
37069
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2797 /* SockObject members */
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2798 static PyMemberDef sock_memberlist[] = {
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2799 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "the socket family"},
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2800 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the socket type"},
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2801 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"},
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2802 {"timeout", T_DOUBLE, offsetof(PySocketSockObject, sock_timeout), READONLY, "the socket timeout"},
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2803 {0},
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2804 };
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2805
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2806 /* 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
2807 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2808
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2809 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
2810 sock_dealloc(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2811 {
12319
57f34e162e67 In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents: 12229
diff changeset
2812 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
2813 (void) SOCKETCLOSE(s->sock_fd);
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2814 s->ob_type->tp_free((PyObject *)s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2815 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2816
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2817
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2818 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
2819 sock_repr(PySocketSockObject *s)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2820 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2821 char buf[512];
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2822 #if SIZEOF_SOCKET_T > SIZEOF_LONG
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2823 if (s->sock_fd > LONG_MAX) {
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2824 /* 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
2825 ugly printf formatter for decimal pointer length integer
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2826 printing, only bother if necessary*/
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2827 PyErr_SetString(PyExc_OverflowError,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2828 "no printf formatter to display "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2829 "the socket descriptor in decimal");
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2830 return NULL;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2831 }
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2832 #endif
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2833 PyOS_snprintf(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2834 buf, sizeof(buf),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2835 "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2836 (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
2837 s->sock_type,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2838 s->sock_proto);
3421
90b54312661a remove unused variables
Guido van Rossum <guido@python.org>
parents: 3390
diff changeset
2839 return PyString_FromString(buf);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2840 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2841
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2842
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2843 /* 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
2844
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2845 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
2846 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
2847 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2848 PyObject *new;
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 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
2851 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
2852 ((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
2853 ((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
2854 ((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
2855 }
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2856 return new;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2857 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2858
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2859
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2860 /* 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
2861
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2862 /*ARGSUSED*/
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2863 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
2864 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
2865 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2866 PySocketSockObject *s = (PySocketSockObject *)self;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2867 SOCKET_T fd;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2868 int family = AF_INET, type = SOCK_STREAM, proto = 0;
36684
0bebeb393045 More unconsting.
Martin v. Löwis <martin@v.loewis.de>
parents: 36632
diff changeset
2869 static char *keywords[] = {"family", "type", "proto", 0};
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2870
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2871 if (!PyArg_ParseTupleAndKeywords(args, kwds,
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2872 "|iii:socket", keywords,
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2873 &family, &type, &proto))
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2874 return -1;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2875
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2876 Py_BEGIN_ALLOW_THREADS
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2877 fd = socket(family, type, proto);
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2878 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
2879
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2880 #ifdef MS_WINDOWS
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2881 if (fd == INVALID_SOCKET)
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2882 #else
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2883 if (fd < 0)
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2884 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2885 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2886 set_error();
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2887 return -1;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2888 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2889 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
2890
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2891 return 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2892
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2893 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2894
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2895
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2896 /* 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
2897
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2898 static PyTypeObject sock_type = {
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
2899 PyObject_HEAD_INIT(0) /* Must fill in type value later */
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2900 0, /* ob_size */
20730
73cabe664c11 Oops. In the tp_name field, the name should be "_socket.socket", not
Guido van Rossum <guido@python.org>
parents: 20727
diff changeset
2901 "_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
2902 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
2903 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
2904 (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
2905 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
2906 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
2907 0, /* tp_setattr */
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2908 0, /* tp_compare */
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2909 (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
2910 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
2911 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
2912 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
2913 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
2914 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
2915 0, /* tp_str */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2916 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
2917 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
2918 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
2919 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
2920 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
2921 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
2922 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
2923 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
2924 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
2925 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
2926 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
2927 sock_methods, /* tp_methods */
37069
dd49847a60d3 RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents: 36684
diff changeset
2928 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
2929 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
2930 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
2931 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
2932 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
2933 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
2934 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
2935 sock_initobj, /* tp_init */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2936 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
2937 sock_new, /* tp_new */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2938 PyObject_Del, /* tp_free */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2939 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2940
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2941
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2942 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2943
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2944 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2945 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38476
diff changeset
2946 socket_gethostname(PyObject *self, PyObject *unused)
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2947 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2948 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2949 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2950 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2951 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2952 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2953 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
2954 return set_error();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2955 buf[sizeof buf - 1] = '\0';
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2956 return PyString_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2957 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2958
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2959 PyDoc_STRVAR(gethostname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2960 "gethostname() -> string\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2961 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2962 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
2963
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2964
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2965 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2966
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2967 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2968 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
2969 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
2970 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2971 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
2972 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
2973
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2974 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
2975 return NULL;
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
2976 if (setipaddr(name, (struct sockaddr *)&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
2977 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2978 return makeipaddr((struct sockaddr *)&addrbuf,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2979 sizeof(struct sockaddr_in));
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2980 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2981
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2982 PyDoc_STRVAR(gethostbyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2983 "gethostbyname(host) -> address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2984 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2985 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
2986
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2987
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2988 /* 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
2989
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2990 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2991 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
2992 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2993 char **pch;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2994 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
2995 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
2996 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
2997 PyObject *tmp;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2998
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2999 if (h == NULL) {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3000 /* Let's get real error message to return */
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
3001 #ifndef RISCOS
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3002 set_herror(h_errno);
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
3003 #else
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3004 PyErr_SetString(socket_error, "host not found");
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
3005 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3006 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3007 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3008
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3009 if (h->h_addrtype != af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3010 #ifdef HAVE_STRERROR
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3011 /* 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
3012 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3013 (char *)strerror(EAFNOSUPPORT));
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3014 #else
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3015 PyErr_SetString(
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3016 socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3017 "Address family not supported by protocol family");
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3018 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3019 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3020 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3021
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3022 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3023
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3024 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3025 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
3026 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3027 break;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3028
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3029 #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
3030 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3031 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
3032 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3033 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3034 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3035
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3036 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3037
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3038 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
3039 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3040
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3041 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
3042 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3043
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3044 for (pch = h->h_aliases; *pch != NULL; pch++) {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3045 int status;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3046 tmp = PyString_FromString(*pch);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3047 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
3048 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3049
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3050 status = PyList_Append(name_list, tmp);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3051 Py_DECREF(tmp);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3052
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3053 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3054 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3055 }
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 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
3058 int status;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3059
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3060 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3061
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3062 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3063 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3064 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
3065 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
3066 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
3067 #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
3068 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
3069 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3070 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
3071 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
3072
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3073 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
3074 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
3075 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3076 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3077
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3078 #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
3079 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3080 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3081 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
3082 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
3083 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
3084 #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
3085 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
3086 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3087 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
3088 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
3089 sizeof(sin6));
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3090
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3091 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
3092 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
3093 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3094 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3095 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3096
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3097 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
3098 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3099 "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
3100 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3101 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3102
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3103 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
3104 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3105
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3106 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
3107 Py_DECREF(tmp);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3108
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3109 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3110 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3111 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
3112
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3113 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
3114
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3115 err:
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3116 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
3117 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
3118 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
3119 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3120
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3121
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3122 /* 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
3123
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3124 /*ARGSUSED*/
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3125 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
3126 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
3127 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3128 char *name;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3129 struct hostent *h;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3130 #ifdef ENABLE_IPV6
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3131 struct sockaddr_storage addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3132 #else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3133 struct sockaddr_in addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
3134 #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
3135 struct sockaddr *sa;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3136 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
3137 #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
3138 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
3139 #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
3140 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
3141 #else
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3142 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
3143 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
3144 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3145 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3146 #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
3147 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
3148 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3149 #endif /* 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
3150
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3151 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
3152 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
3153 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
3154 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3155 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
3156 #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
3157 #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
3158 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
3159 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3160 #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
3161 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
3162 #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
3163 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
3164 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
3165 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
3166 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3167 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3168 #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
3169 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
3170 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3171 h = gethostbyname(name);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3172 #endif /* HAVE_GETHOSTBYNAME_R */
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3173 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
3174 /* 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
3175 addr.ss_family.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3176 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
3177 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
3178 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
3179 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
3180 sa->sa_family);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3181 #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
3182 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
3183 #endif
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
3184 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
3185 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3186
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3187 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
3188 "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
3189 \n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3190 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
3191 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
3192
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
3193
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3194 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3195
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3196 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3197 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
3198 socket_gethostbyaddr(PyObject *self, PyObject *args)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3199 {
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3200 #ifdef ENABLE_IPV6
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3201 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
3202 #else
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3203 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
3204 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3205 struct sockaddr *sa = (struct sockaddr *)&addr;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3206 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3207 struct hostent *h;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3208 PyObject *ret;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3209 #ifdef HAVE_GETHOSTBYNAME_R
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3210 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
3211 #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
3212 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
3213 #else
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3214 char buf[16384];
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3215 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
3216 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3217 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3218 #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
3219 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
3220 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3221 #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
3222 char *ap;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3223 int al;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3224 int af;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3225
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3226 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
3227 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
3228 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
3229 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
3230 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3231 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
3232 ap = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3233 al = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3234 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3235 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3236 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
3237 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
3238 break;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3239 #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
3240 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3241 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
3242 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
3243 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3244 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3245 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3246 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
3247 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3248 }
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3249 Py_BEGIN_ALLOW_THREADS
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3250 #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
3251 #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
3252 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
3253 &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
3254 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
3255 #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
3256 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
3257 &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
3258 #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
3259 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
3260 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
3261 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
3262 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3263 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3264 #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
3265 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
3266 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3267 h = gethostbyaddr(ap, al, af);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3268 #endif /* HAVE_GETHOSTBYNAME_R */
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3269 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
3270 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
3271 #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
3272 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
3273 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3274 return ret;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3275 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
3276
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3277 PyDoc_STRVAR(gethostbyaddr_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3278 "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
3279 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3280 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
3281 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
3282
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3283
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3284 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3285 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
3286 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
3287
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3288 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3289 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
3290 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
3291 {
32429
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3292 char *name, *proto=NULL;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3293 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
3294 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
3295 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3296 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
3297 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3298 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3299 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
3300 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
3301 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3302 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3303 return PyInt_FromLong((long) ntohs(sp->s_port));
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3304 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3305
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3306 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
3307 "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
3308 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3309 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
3310 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
3311 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
3312
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3313
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3314 /* 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
3315 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
3316 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
3317
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3318 /*ARGSUSED*/
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3319 static PyObject *
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3320 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
3321 {
33606
4d7b0d206bc7 Silence a compiler warning by supplying the correct argument type to
Raymond Hettinger <python@rcn.com>
parents: 33478
diff changeset
3322 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
3323 char *proto=NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3324 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
3325 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
3326 return NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3327 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
3328 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
3329 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
3330 if (sp == NULL) {
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3331 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
3332 return NULL;
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3333 }
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3334 return PyString_FromString(sp->s_name);
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3335 }
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3336
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3337 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
3338 "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
3339 \n\
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
3340 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
3341 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
3342 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
3343
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3344 /* Python interface to getprotobyname(name).
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3345 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
3346 already known or not useful (like the list of aliases). */
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3347
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3348 /*ARGSUSED*/
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3349 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
3350 socket_getprotobyname(PyObject *self, PyObject *args)
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3351 {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3352 char *name;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3353 struct protoent *sp;
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3354 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3355 /* Not available in BeOS yet. - [cjh] */
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3356 PyErr_SetString(socket_error, "getprotobyname not supported");
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3357 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3358 #else
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3359 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3360 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3361 Py_BEGIN_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3362 sp = getprotobyname(name);
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3363 Py_END_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3364 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
3365 PyErr_SetString(socket_error, "protocol not found");
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3366 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3367 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3368 return PyInt_FromLong((long) sp->p_proto);
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3369 #endif
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3370 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3371
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3372 PyDoc_STRVAR(getprotobyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3373 "getprotobyname(name) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3374 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3375 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
3376
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
3377
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3378 #ifdef HAVE_SOCKETPAIR
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3379 /* 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
3380 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
3381 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
3382
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3383 /*ARGSUSED*/
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3384 static PyObject *
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3385 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
3386 {
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3387 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
3388 SOCKET_T sv[2];
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3389 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
3390 PyObject *res = NULL;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3391
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3392 #if defined(AF_UNIX)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3393 family = AF_UNIX;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3394 #else
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3395 family = AF_INET;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3396 #endif
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3397 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
3398 &family, &type, &proto))
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3399 return NULL;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3400 /* 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
3401 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
3402 return set_error();
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3403 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
3404 if (s0 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3405 goto finally;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3406 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
3407 if (s1 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3408 goto finally;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3409 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
3410
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3411 finally:
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3412 if (res == NULL) {
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3413 if (s0 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3414 SOCKETCLOSE(sv[0]);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3415 if (s1 == NULL)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3416 SOCKETCLOSE(sv[1]);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3417 }
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3418 Py_XDECREF(s0);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3419 Py_XDECREF(s1);
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3420 return res;
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3421 }
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3422
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3423 PyDoc_STRVAR(socketpair_doc,
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3424 "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
3425 \n\
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3426 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
3427 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
3428 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
3429 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
3430
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3431 #endif /* HAVE_SOCKETPAIR */
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3432
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
3433
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
3434 #ifndef NO_DUP
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3435 /* Create a socket object from a numeric file description.
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3436 Useful e.g. if stdin is a socket.
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3437 Additional arguments as for socket(). */
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3438
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3439 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3440 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
3441 socket_fromfd(PyObject *self, PyObject *args)
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3442 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3443 PySocketSockObject *s;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
3444 SOCKET_T fd;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
3445 int family, type, proto = 0;
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3446 if (!PyArg_ParseTuple(args, "iii|i:fromfd",
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3447 &fd, &family, &type, &proto))
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
3448 return NULL;
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents: 1099
diff changeset
3449 /* Dup the fd so it and the socket can be closed independently */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents: 1099
diff changeset
3450 fd = dup(fd);
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents: 1099
diff changeset
3451 if (fd < 0)
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3452 return set_error();
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3453 s = new_sockobject(fd, family, type, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3454 return (PyObject *) s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3455 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3456
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3457 PyDoc_STRVAR(fromfd_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3458 "fromfd(fd, family, type[, proto]) -> socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3459 \n\
37371
492044034a87 Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents: 37069
diff changeset
3460 Create a socket object from a duplicate of the given\n\
492044034a87 Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents: 37069
diff changeset
3461 file descriptor.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3462 The remaining arguments are the same as for socket().");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3463
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
3464 #endif /* NO_DUP */
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
3465
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3466
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3467 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
3468 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
3469 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3470 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3471
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3472 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
3473 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3474 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3475 x2 = (int)ntohs((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3476 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3477 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3478
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3479 PyDoc_STRVAR(ntohs_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3480 "ntohs(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3481 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3482 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
3483
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3484
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3485 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3486 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
3487 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3488 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3489
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3490 if (PyInt_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3491 x = PyInt_AS_LONG(arg);
24380
672843ee4b61 Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24375
diff changeset
3492 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
3493 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3494 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3495 else if (PyLong_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3496 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
3497 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
3498 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3499 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3500 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3501 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3502 /* 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
3503 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3504 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3505 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3506 "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
3507 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3508 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3509 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3510 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3511 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3512 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
3513 "expected int/long, %s found",
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3514 arg->ob_type->tp_name);
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3515 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
3516 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3517 return PyInt_FromLong(ntohl(x));
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3518 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3519
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3520 PyDoc_STRVAR(ntohl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3521 "ntohl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3522 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3523 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
3524
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3525
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3526 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
3527 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
3528 {
31207
f388e83f8e43 Fix erroneus argument parsing of socket.htons() on 64bit big endian
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31027
diff changeset
3529 int x1, x2;
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3530
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3531 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
3532 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3533 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3534 x2 = (int)htons((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3535 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3536 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3537
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3538 PyDoc_STRVAR(htons_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3539 "htons(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3540 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3541 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
3542
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3543
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3544 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3545 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
3546 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3547 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3548
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3549 if (PyInt_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3550 x = PyInt_AS_LONG(arg);
24380
672843ee4b61 Put checks for error returns in the right place.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24375
diff changeset
3551 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
3552 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3553 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3554 else if (PyLong_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3555 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
3556 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
3557 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3558 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3559 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3560 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3561 /* 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
3562 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3563 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3564 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3565 "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
3566 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3567 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3568 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3569 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3570 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
3571 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
3572 "expected int/long, %s found",
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3573 arg->ob_type->tp_name);
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3574 return PyInt_FromLong(htonl(x));
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3575 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
3576
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3577 PyDoc_STRVAR(htonl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3578 "htonl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3579 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3580 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
3581
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3582 /* 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
3583
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3584 PyDoc_STRVAR(inet_aton_doc,
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3585 "inet_aton(string) -> packed 32-bit IP representation\n\
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3586 \n\
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3587 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
3588 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
3589
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3590 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
3591 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
3592 {
11268
3fe8d13328c8 It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents: 11219
diff changeset
3593 #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
3594 #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
3595 #endif
27858
9453d8cdd01e Ummm, try to get it right this time
Neal Norwitz <nnorwitz@gmail.com>
parents: 27857
diff changeset
3596 #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
3597 struct in_addr buf;
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3598 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3599
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3600 #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
3601 /* 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
3602 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
3603 #endif
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3604 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
3605
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3606 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
3607 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
3608
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3609
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
3610 #ifdef HAVE_INET_ATON
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3611
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3612 #ifdef USE_INET_ATON_WEAKLINK
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3613 if (inet_aton != NULL) {
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3614 #endif
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3615 if (inet_aton(ip_addr, &buf))
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3616 return PyString_FromStringAndSize((char *)(&buf),
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3617 sizeof(buf));
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3618
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3619 PyErr_SetString(socket_error,
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3620 "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
3621 return NULL;
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3622
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3623 #ifdef USE_INET_ATON_WEAKLINK
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3624 } else {
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3625 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3626
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3627 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3628
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3629 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK)
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3630
35452
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3631 /* 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
3632 * 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
3633 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
3634 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
3635 } else {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
3636
35452
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3637 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
3638
59a63b09a4c2 backport patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents: 33928
diff changeset
3639 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
3640 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
3641 "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
3642 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
3643 }
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3644 }
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3645 return PyString_FromStringAndSize((char *) &packed_addr,
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3646 sizeof(packed_addr));
37934
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3647
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3648 #ifdef USE_INET_ATON_WEAKLINK
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3649 }
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3650 #endif
ea67628ddae5 Patch 1471925 - Weak linking support for OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 37853
diff changeset
3651
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
3652 #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
3653 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3654
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3655 PyDoc_STRVAR(inet_ntoa_doc,
11937
ef98ee6aeb42 Fixed inet_ntoa() docstring.
Fred Drake <fdrake@acm.org>
parents: 11882
diff changeset
3656 "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
3657 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3658 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
3659
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3660 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
3661 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
3662 {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3663 char *packed_str;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
3664 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
3665 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
3666
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
3667 if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) {
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3668 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
3669 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3670
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3671 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
3672 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
3673 "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
3674 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
3675 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3676
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3677 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
3678
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3679 return PyString_FromString(inet_ntoa(packed_addr));
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
3680 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3681
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3682 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3683
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3684 PyDoc_STRVAR(inet_pton_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3685 "inet_pton(af, ip) -> packed IP address string\n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3686 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3687 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
3688 for use with low-level network functions.");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3689
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3690 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3691 socket_inet_pton(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3692 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3693 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3694 char* ip;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3695 int retval;
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3696 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3697 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
3698 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3699 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
3700 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3701 if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) {
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
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
3705 #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
3706 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
3707 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
3708 "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
3709 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
3710 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
3711 #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
3712
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3713 retval = inet_pton(af, ip, packed);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3714 if (retval < 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3715 PyErr_SetFromErrno(socket_error);
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 } else if (retval == 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3718 PyErr_SetString(socket_error,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3719 "illegal IP address string passed to inet_pton");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3720 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3721 } else if (af == AF_INET) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3722 return PyString_FromStringAndSize(packed,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3723 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
3724 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3725 } else if (af == AF_INET6) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3726 return PyString_FromStringAndSize(packed,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3727 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
3728 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3729 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3730 PyErr_SetString(socket_error, "unknown address family");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3731 return NULL;
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 }
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
3734
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3735 PyDoc_STRVAR(inet_ntop_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3736 "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
3737 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3738 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
3739
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3740 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3741 socket_inet_ntop(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3742 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3743 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3744 char* packed;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3745 int len;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3746 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
3747 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3748 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
3749 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3750 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
3751 #endif
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
3752
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3753 /* Guarantee NUL-termination for PyString_FromString() below */
33928
0d4ecc31cfd8 Fix apparently trivial buffer overflow (SF bug 1060396).
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 33760
diff changeset
3754 memset((void *) &ip[0], '\0', sizeof(ip));
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3755
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3756 if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3757 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3758 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3759
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3760 if (af == AF_INET) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3761 if (len != sizeof(struct in_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3762 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3763 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3764 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3765 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3766 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3767 } else if (af == AF_INET6) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3768 if (len != sizeof(struct in6_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3769 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3770 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3771 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3772 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3773 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3774 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3775 PyErr_Format(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3776 "unknown address family %d", af);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3777 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3778 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3779
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3780 retval = inet_ntop(af, packed, ip, sizeof(ip));
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3781 if (!retval) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3782 PyErr_SetFromErrno(socket_error);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3783 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3784 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3785 return PyString_FromString(retval);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3786 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3787
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3788 /* NOTREACHED */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3789 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3790 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3791 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3792
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3793 #endif /* HAVE_INET_PTON */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3794
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3795 /* 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
3796
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3797 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3798 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
3799 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
3800 {
20912
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
3801 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
3802 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
3803 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
3804 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
3805 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
3806 char *hptr, *pptr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3807 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
3808 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3809 PyObject *all = (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3810 PyObject *single = (PyObject *)NULL;
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3811 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
3812
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3813 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
3814 family = AF_UNSPEC;
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3815 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
3816 &hobj, &pobj, &family, &socktype,
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3817 &protocol, &flags)) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3818 return NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3819 }
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3820 if (hobj == Py_None) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3821 hptr = NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3822 } 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
3823 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
3824 if (!idna)
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3825 return NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3826 hptr = PyString_AsString(idna);
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3827 } else if (PyString_Check(hobj)) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3828 hptr = PyString_AsString(hobj);
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3829 } else {
38353
36cd4a4ab8f7 Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents: 37979
diff changeset
3830 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
3831 "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
3832 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3833 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3834 if (PyInt_Check(pobj)) {
18915
510f7f6a877e Enable PyOS_snprintf() et al. during alpha phase of 2.2.0 and
Marc-André Lemburg <mal@egenix.com>
parents: 18879
diff changeset
3835 PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3836 pptr = pbuf;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3837 } else if (PyString_Check(pobj)) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3838 pptr = PyString_AsString(pobj);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3839 } 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
3840 pptr = (char *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3841 } else {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3842 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
3843 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3844 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3845 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
3846 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
3847 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
3848 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
3849 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
3850 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3851 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
3852 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
3853 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3854 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
3855 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
3856 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
3857 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3858 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3859
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3860 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
3861 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3862 for (res = res0; res; res = res->ai_next) {
20389
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3863 PyObject *addr =
32213
70dee2b193f7 Patch #929192: Improvements to bluetooth support.
Martin v. Löwis <martin@v.loewis.de>
parents: 32183
diff changeset
3864 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
3865 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
3866 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3867 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
3868 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
3869 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
3870 addr);
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3871 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
3872 if (single == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3873 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3874
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3875 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
3876 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3877 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3878 }
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3879 Py_XDECREF(idna);
24687
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3880 if (res0)
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3881 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3882 return all;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3883 err:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3884 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3885 Py_XDECREF(all);
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3886 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
3887 if (res0)
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
3888 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3889 return (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3890 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3891
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3892 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
3893 "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
3894 -> 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
3895 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3896 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
3897
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3898 /* 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
3899
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3900 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3901 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
3902 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
3903 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3904 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
3905 int flags;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3906 char *hostp;
20853
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20756
diff changeset
3907 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
3908 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
3909 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
3910 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3911 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
3912
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3913 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
3914 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
3915 return NULL;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3916 if (!PyArg_ParseTuple(sa, "si|ii",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3917 &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
3918 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
3919 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
3920 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
3921 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
3922 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
3923 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3924 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
3925 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
3926 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3927 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
3928 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
3929 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
3930 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3931 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3932 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
3933 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
3934 "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
3935 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3936 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3937 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
3938 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3939 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3940 char *t1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3941 int t2;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3942 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
3943 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
3944 "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
3945 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3946 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3947 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3948 }
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3949 #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
3950 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3951 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3952 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
3953 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
3954 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
3955 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
3956 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3957 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3958 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3959 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3960 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
3961 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
3962 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
3963 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
3964 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3965 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3966 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
3967
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3968 fail:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3969 if (res)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3970 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3971 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3972 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3973
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3974 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
3975 "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
3976 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3977 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
3978
24293
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 /* 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
3981
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3982 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3983 socket_getdefaulttimeout(PyObject *self)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3984 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3985 if (defaulttimeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3986 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3987 return Py_None;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3988 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3989 else
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3990 return PyFloat_FromDouble(defaulttimeout);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3991 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3992
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3993 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
3994 "getdefaulttimeout() -> timeout\n\
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3995 \n\
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3996 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
3997 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
3998 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
3999
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4000 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4001 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
4002 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4003 double timeout;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4004
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4005 if (arg == Py_None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4006 timeout = -1.0;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4007 else {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4008 timeout = PyFloat_AsDouble(arg);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4009 if (timeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4010 if (!PyErr_Occurred())
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4011 PyErr_SetString(PyExc_ValueError,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4012 "Timeout value out of range");
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4013 return NULL;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4014 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4015 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4016
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4017 defaulttimeout = timeout;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4018
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4019 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4020 return Py_None;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4021 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4022
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4023 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
4024 "setdefaulttimeout(timeout)\n\
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4025 \n\
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4026 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
4027 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
4028 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
4029
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4030
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
4031 /* 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
4032
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4033 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
4034 {"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
4035 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
4036 {"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
4037 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
4038 {"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
4039 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
4040 {"gethostname", socket_gethostname,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38476
diff changeset
4041 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
4042 {"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
4043 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
4044 {"getservbyport", socket_getservbyport,
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32213
diff changeset
4045 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
4046 {"getprotobyname", socket_getprotobyname,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38476
diff changeset
4047 METH_VARARGS, getprotobyname_doc},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
4048 #ifndef NO_DUP
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4049 {"fromfd", socket_fromfd,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
4050 METH_VARARGS, fromfd_doc},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
4051 #endif
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4052 #ifdef HAVE_SOCKETPAIR
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4053 {"socketpair", socket_socketpair,
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4054 METH_VARARGS, socketpair_doc},
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32913
diff changeset
4055 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4056 {"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
4057 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
4058 {"ntohl", socket_ntohl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
4059 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
4060 {"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
4061 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
4062 {"htonl", socket_htonl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
4063 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
4064 {"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
4065 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
4066 {"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
4067 METH_VARARGS, inet_ntoa_doc},
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4068 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4069 {"inet_pton", socket_inet_pton,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4070 METH_VARARGS, inet_pton_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4071 {"inet_ntop", socket_inet_ntop,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4072 METH_VARARGS, inet_ntop_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4073 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4074 {"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
4075 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
4076 {"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
4077 METH_VARARGS, getnameinfo_doc},
24303
93434bc0899d Silence warning about getdefaulttimeout in PyMethodDef.
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
4078 {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout,
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4079 METH_NOARGS, getdefaulttimeout_doc},
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4080 {"setdefaulttimeout", socket_setdefaulttimeout,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
4081 METH_O, setdefaulttimeout_doc},
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
4082 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4083 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4084
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
4085
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4086 #ifdef RISCOS
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4087 #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
4088
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4089 static int
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4090 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
4091 {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4092 _kernel_swi_regs r;
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4093
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4094 r.r[0] = 0;
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4095 _kernel_swi(0x43380, &r, &r);
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4096 taskwindow = r.r[0];
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4097
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
4098 return 1;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4099 }
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4100
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4101 #endif /* RISCOS */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4102
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4103
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
4104 #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
4105 #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
4106
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4107 /* 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
4108
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
4109 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
4110 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
4111 {
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
4112 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
4113 }
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
4114
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
4115 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
4116 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
4117 {
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
4118 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
4119 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
4120 char buf[100];
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
4121 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
4122 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
4123 case 0: /* No error */
29790
1037feacb54f Fix [ 766669 ] Consistent GPF on exit
Mark Hammond <mhammond@skippinet.com.au>
parents: 29651
diff changeset
4124 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
4125 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
4126 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
4127 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
4128 "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
4129 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
4130 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
4131 case WSAEINVAL:
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4132 PyErr_SetString(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4133 PyExc_ImportError,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4134 "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
4135 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
4136 default:
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21060
diff changeset
4137 PyOS_snprintf(buf, sizeof(buf),
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21060
diff changeset
4138 "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
4139 PyErr_SetString(PyExc_ImportError, buf);
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
4140 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
4141 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4142 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
4143 }
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
4144
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
4145 #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
4146
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4147
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4148 #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
4149 #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
4150
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4151 /* Additional initialization for OS/2 */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4152
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4153 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
4154 os_init(void)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4155 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4156 #ifndef PYCC_GCC
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4157 char reason[64];
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4158 int rc = sock_init();
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4159
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4160 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
4161 return 1; /* Success */
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4162 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4163
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4164 PyOS_snprintf(reason, sizeof(reason),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4165 "OS/2 TCP/IP Error# %d", sock_errno());
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4166 PyErr_SetString(PyExc_ImportError, reason);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4167
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4168 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
4169 #else
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4170 /* 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
4171 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
4172 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4173 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4174
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4175 #endif /* PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
4176
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4177
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4178 #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
4179 static int
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4180 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
4181 {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4182 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
4183 }
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4184 #endif
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4185
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4186
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
4187 /* 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
4188 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
4189 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
4190 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
4191 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4192 &sock_type,
31790
29da8bdfeb4e Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents: 31541
diff changeset
4193 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
4194 };
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4195
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4196
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4197 /* 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
4198
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4199 This module is actually called "_socket", and there's a wrapper
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4200 "socket.py" which implements some additional functionality. On some
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4201 platforms (e.g. Windows and OS/2), socket.py also implements a
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4202 wrapper for the socket type that provides missing functionality such
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4203 as makefile(), dup() and fromfd(). The import of "_socket" may fail
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4204 with an ImportError exception if os-specific initialization fails.
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4205 On Windows, this does WINSOCK initialization. When WINSOCK is
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4206 initialized succesfully, a call to WSACleanup() is scheduled to be
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4207 made at exit time.
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4208 */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4209
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
4210 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
4211 "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
4212 \n\
980767c6cd97 Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents: 24619
diff changeset
4213 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
4214
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24411
diff changeset
4215 PyMODINIT_FUNC
13694
b54f11ada91e Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents: 13680
diff changeset
4216 init_socket(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4217 {
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4218 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
4219
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4220 if (!os_init())
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
4221 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4222
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4223 sock_type.ob_type = &PyType_Type;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4224 m = Py_InitModule3(PySocket_MODULE_NAME,
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4225 socket_methods,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4226 socket_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36298
diff changeset
4227 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36298
diff changeset
4228 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4229
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4230 socket_error = PyErr_NewException("socket.error", NULL, NULL);
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4231 if (socket_error == NULL)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
4232 return;
31790
29da8bdfeb4e Make socket.sslerror a subclass of socket.error .
Brett Cannon <bcannon@gmail.com>
parents: 31541
diff changeset
4233 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
4234 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
4235 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
4236 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
4237 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
4238 if (socket_herror == NULL)
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4239 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4240 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
4241 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
4242 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
4243 NULL);
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4244 if (socket_gaierror == NULL)
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4245 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4246 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
4247 PyModule_AddObject(m, "gaierror", socket_gaierror);
29651
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4248 socket_timeout = PyErr_NewException("socket.timeout",
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4249 socket_error, NULL);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4250 if (socket_timeout == NULL)
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4251 return;
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4252 Py_INCREF(socket_timeout);
0a3751df4195 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29066
diff changeset
4253 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
4254 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
4255 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
4256 (PyObject *)&sock_type) != 0)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
4257 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4258 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
4259 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
4260 (PyObject *)&sock_type) != 0)
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
4261 return;
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4262
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4263 #ifdef ENABLE_IPV6
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4264 has_ipv6 = Py_True;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4265 #else
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4266 has_ipv6 = Py_False;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4267 #endif
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4268 Py_INCREF(has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4269 PyModule_AddObject(m, "has_ipv6", has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
4270
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
4271 /* 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
4272 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
4273 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
4274 ) != 0)
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4275 return;
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
4276
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4277 /* 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
4278 #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
4279 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
4280 #endif
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4281 PyModule_AddIntConstant(m, "AF_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
4282 #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
4283 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
4284 #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
4285 #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
4286 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
4287 #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
4288 #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
4289 /* 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
4290 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
4291 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4292 #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
4293 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
4294 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4295 #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
4296 /* Appletalk DDP */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4297 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
4298 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4299 #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
4300 /* Amateur radio NetROM */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4301 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
4302 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4303 #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
4304 /* Multiprotocol bridge */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4305 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
4306 #endif
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4307 #ifdef AF_ATMPVC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4308 /* ATM PVCs */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4309 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
4310 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4311 #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
4312 /* 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
4313 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
4314 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4315 #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
4316 /* 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
4317 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
4318 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4319 #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
4320 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
4321 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4322 #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
4323 /* 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
4324 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
4325 #endif
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4326 #ifdef AF_DECnet
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4327 /* Reserved for DECnet project */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4328 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
4329 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4330 #ifdef AF_NETBEUI
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4331 /* 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
4332 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
4333 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4334 #ifdef AF_SECURITY
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4335 /* Security callback pseudo AF */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4336 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
4337 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4338 #ifdef AF_KEY
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4339 /* 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
4340 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
4341 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4342 #ifdef AF_NETLINK
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4343 /* */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4344 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
4345 PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4346 #ifdef NETLINK_SKIP
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4347 PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4348 #endif
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4349 #ifdef NETLINK_W1
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4350 PyModule_AddIntConstant(m, "NETLINK_W1", NETLINK_W1);
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4351 #endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4352 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
4353 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
4354 #ifdef NETLINK_TCPDIAG
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4355 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
4356 #endif
4d988dda6478 NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
Guido van Rossum <guido@python.org>
parents: 36610
diff changeset
4357 #ifdef NETLINK_NFLOG
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4358 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
4359 #endif
36298
9eeaa33f9640 Get socketmodule to build after adding netlink support.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36289
diff changeset
4360 #ifdef NETLINK_XFRM
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4361 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
4362 #endif
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4363 #ifdef NETLINK_ARPD
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4364 PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4365 #endif
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4366 #ifdef NETLINK_ROUTE6
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4367 PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4368 #endif
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4369 PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW);
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4370 PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4371 #ifdef NETLINK_TAPBASE
36286
ae4480935016 Patch #1103116: AF_NETLINK sockets basic support.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
4372 PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE);
37530
3c7ea50518be Patch #1462080: Conditionalize some NETLINK defines.
Martin v. Löwis <martin@v.loewis.de>
parents: 37371
diff changeset
4373 #endif
37371
492044034a87 Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents: 37069
diff changeset
4374 #endif /* AF_NETLINK */
32764
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4375 #ifdef AF_ROUTE
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4376 /* 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
4377 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
4378 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4379 #ifdef AF_ASH
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4380 /* Ash */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4381 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
4382 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4383 #ifdef AF_ECONET
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4384 /* Acorn Econet */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4385 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
4386 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4387 #ifdef AF_ATMSVC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4388 /* ATM SVCs */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4389 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
4390 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4391 #ifdef AF_SNA
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4392 /* Linux SNA Project (nutters!) */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4393 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
4394 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4395 #ifdef AF_IRDA
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4396 /* IRDA sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4397 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
4398 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4399 #ifdef AF_PPPOX
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4400 /* PPPoX sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4401 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
4402 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4403 #ifdef AF_WANPIPE
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4404 /* Wanpipe API Sockets */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4405 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
4406 #endif
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4407 #ifdef AF_LLC
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4408 /* Linux LLC */
ecb0c97f1e42 Patch #984654: Add more address family constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 32611
diff changeset
4409 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
4410 #endif
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4411
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
4412 #ifdef USE_BLUETOOTH
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4413 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
4414 PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP);
31443
afb4c9726d1a Add FreeBSD support for bluetooth sockets.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31441
diff changeset
4415 #if !defined(__FreeBSD__)
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4416 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
4417 #endif
31441
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4418 PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM);
38498
8dfba087dc07 Simplify further by using AddStringConstant
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
4419 PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00");
8dfba087dc07 Simplify further by using AddStringConstant
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
4420 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
4421 #endif
493707692671 Patch #874083: Bluetooth support for socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 31274
diff changeset
4422
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
4423 #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
4424 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
4425 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
4426 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
4427 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
4428 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
4429 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
4430 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
4431 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
4432 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
4433 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4434
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4435 /* Socket types */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4436 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
4437 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
4438 #ifndef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
4439 /* 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
4440 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
4441 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
4442 #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
4443 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
4444 #endif
26597
7ddea4dfa519 Patch #650422: Use Posix AF_ constants instead of PF_ ones.
Martin v. Löwis <martin@v.loewis.de>
parents: 26551
diff changeset
4445 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4446
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4447 #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
4448 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4449 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4450 #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
4451 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4452 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4453 #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
4454 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4455 #endif
32578
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4456 #ifdef SO_EXCLUSIVEADDRUSE
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4457 PyModule_AddIntConstant(m, "SO_EXCLUSIVEADDRUSE", SO_EXCLUSIVEADDRUSE);
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4458 #endif
21fd6e62cd27 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant
Andrew M. Kuchling <amk@amk.ca>
parents: 32521
diff changeset
4459
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4460 #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
4461 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4462 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4463 #ifdef SO_DONTROUTE
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4464 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4465 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4466 #ifdef SO_BROADCAST
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4467 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4468 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4469 #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
4470 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4471 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4472 #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
4473 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4474 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4475 #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
4476 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4477 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4478 #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
4479 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4480 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4481 #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
4482 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4483 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4484 #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
4485 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4486 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4487 #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
4488 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4489 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4490 #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
4491 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4492 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4493 #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
4494 PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4495 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4496 #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
4497 PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4498 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4499 #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
4500 PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4501 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4502 #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
4503 PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4504 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4505
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4506 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4507 #ifdef SOMAXCONN
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4508 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4509 #else
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4510 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
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
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4513 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4514 #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
4515 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4516 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4517 #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
4518 PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4519 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4520 #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
4521 PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4522 #endif
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
4523 #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
4524 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT);
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
4525 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4526 #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
4527 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4528 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4529 #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
4530 PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4531 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4532 #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
4533 PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4534 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4535 #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
4536 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4537 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4538 #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
4539 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4540 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4541 #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
4542 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4543 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4544
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4545 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4546 #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
4547 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4548 #endif
11182
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_IP
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_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
4551 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4552 PyModule_AddIntConstant(m, "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
4553 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4554 #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
4555 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
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_AX25
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_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
4559 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4560 #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
4561 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
4562 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4563 #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
4564 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
4565 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4566 #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
4567 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
4568 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4569 #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
4570 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
4571 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4572 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
4573 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4574 #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
4575 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
4576 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4577 PyModule_AddIntConstant(m, "SOL_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
4578 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4579 #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
4580 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
4581 #else
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_IP", 0);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4583 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4584 #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
4585 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
4586 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4587 #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
4588 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
4589 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4590 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4591 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4592 #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
4593 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP);
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_GGP
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_GGP", IPPROTO_GGP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4597 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4598 #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
4599 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
4600 #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
4601 #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
4602 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
4603 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4604 #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
4605 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
4606 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4607 #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
4608 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
4609 #else
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_TCP", 6);
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_EGP
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_EGP", IPPROTO_EGP);
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_PUP
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_PUP", IPPROTO_PUP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4617 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4618 #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
4619 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
4620 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4621 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4622 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4623 #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
4624 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4625 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4626 #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
4627 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4628 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4629 #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
4630 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4631 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4632 #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
4633 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4634 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4635 #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
4636 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
4637 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4638 #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
4639 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
4640 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4641 #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
4642 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
4643 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4644 #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
4645 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
4646 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4647 #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
4648 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
4649 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4650 #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
4651 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
4652 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4653 #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
4654 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
4655 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4656 #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
4657 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
4658 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4659 #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
4660 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
4661 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4662 #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
4663 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
4664 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4665 #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
4666 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
4667 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4668 #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
4669 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4670 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4671 #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
4672 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4673 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4674 #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
4675 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
4676 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4677 #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
4678 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
4679 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4680 #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
4681 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
4682 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4683 #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
4684 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4685 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4686 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4687 #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
4688 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
4689 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4690 PyModule_AddIntConstant(m, "IPPROTO_RAW", 255);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4691 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4692 #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
4693 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4694 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4695
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4696 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4697 #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
4698 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
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, "IPPORT_RESERVED", 1024);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4701 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4702 #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
4703 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
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, "IPPORT_USERRESERVED", 5000);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4706 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4707
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4708 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4709 #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
4710 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4711 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4712 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4713 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4714 #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
4715 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4716 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4717 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4718 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4719 #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
4720 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK);
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_LOOPBACK", 0x7F000001);
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_UNSPEC_GROUP
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_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
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_UNSPEC_GROUP", 0xe0000000);
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 #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
4730 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
4731 INADDR_ALLHOSTS_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4732 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4733 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4734 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4735 #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
4736 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
4737 INADDR_MAX_LOCAL_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4738 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
4739 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4740 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4741 #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
4742 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4743 #else
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, "INADDR_NONE", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4745 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
4746
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4747 /* IPv4 [gs]etsockopt options */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4748 #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
4749 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4750 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4751 #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
4752 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4753 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4754 #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
4755 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4756 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4757 #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
4758 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4759 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4760 #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
4761 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4762 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4763 #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
4764 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4765 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4766 #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
4767 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4768 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4769 #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
4770 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4771 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4772 #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
4773 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
4774 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4775 #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
4776 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
4777 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4778 #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
4779 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
4780 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4781 #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
4782 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
4783 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
4784 #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
4785 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
4786 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4787 #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
4788 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
4789 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
4790 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4791 #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
4792 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
4793 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
4794 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4795 #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
4796 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
4797 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4798
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4799 /* 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
4800 #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
4801 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
4802 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4803 #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
4804 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
4805 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4806 #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
4807 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
4808 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4809 #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
4810 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
4811 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4812 #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
4813 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
4814 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4815 #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
4816 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
4817 #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
4818 /* 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
4819 #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
4820 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
4821 #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
4822 /* 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
4823 #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
4824 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
4825 #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
4826 #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
4827 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
4828 #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
4829 #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
4830 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
4831 #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
4832 #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
4833 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
4834 #endif
24d34ab4ef75 Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012.
Martin v. Löwis <martin@v.loewis.de>
parents: 31207
diff changeset
4835 #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
4836 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
4837 #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
4838 #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
4839 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
4840 #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
4841 #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
4842 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
4843 #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
4844 #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
4845 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
4846 #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
4847 #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
4848 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
4849 #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
4850 #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
4851 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
4852 #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
4853 #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
4854 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
4855 #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
4856 #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
4857 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
4858 #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
4859 #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
4860 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
4861 #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
4862 #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
4863 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
4864 #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
4865 #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
4866 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
4867 #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
4868 #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
4869 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
4870 #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
4871 #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
4872 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
4873 #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
4874 #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
4875 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
4876 #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
4877 #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
4878 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
4879 #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
4880 #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
4881 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
4882 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
4883
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4884 /* TCP options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4885 #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
4886 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
4887 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4888 #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
4889 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
4890 #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
4891 #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
4892 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
4893 #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
4894 #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
4895 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
4896 #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
4897 #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
4898 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
4899 #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
4900 #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
4901 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
4902 #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
4903 #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
4904 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
4905 #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
4906 #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
4907 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
4908 #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
4909 #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
4910 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
4911 #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
4912 #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
4913 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
4914 #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
4915 #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
4916 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
4917 #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
4918 #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
4919 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
4920 #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
4921
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4922
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4923 /* IPX options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
4924 #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
4925 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
4926 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
4927
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4928 /* 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
4929 #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
4930 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
4931 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4932 #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
4933 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
4934 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4935 #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
4936 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
4937 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4938 #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
4939 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
4940 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4941 #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
4942 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
4943 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4944 #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
4945 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
4946 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4947 #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
4948 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
4949 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4950 #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
4951 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
4952 #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
4953 #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
4954 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
4955 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4956 #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
4957 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
4958 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4959 #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
4960 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
4961 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4962 #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
4963 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
4964 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4965 #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
4966 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
4967 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4968 #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
4969 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
4970 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4971 #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
4972 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
4973 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4974 #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
4975 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
4976 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4977 #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
4978 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
4979 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4980 #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
4981 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
4982 #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
4983 #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
4984 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
4985 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4986 #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
4987 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
4988 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4989 #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
4990 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
4991 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4992 #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
4993 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
4994 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4995 #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
4996 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
4997 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4998 #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
4999 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
5000 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5001 #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
5002 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
5003 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5004 #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
5005 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
5006 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5007 #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
5008 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
5009 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5010 #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
5011 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
5012 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5013 #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
5014 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
5015 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5016 #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
5017 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
5018 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5019 #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
5020 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
5021 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5022 #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
5023 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
5024 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
5025
31027
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5026 /* shutdown() parameters */
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5027 #ifdef SHUT_RD
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5028 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
5029 #elif defined(SD_RECEIVE)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5030 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
5031 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5032 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
5033 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5034 #ifdef SHUT_WR
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5035 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
5036 #elif defined(SD_SEND)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5037 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
5038 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5039 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
5040 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5041 #ifdef SHUT_RDWR
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5042 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
5043 #elif defined(SD_BOTH)
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5044 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
5045 #else
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5046 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
5047 #endif
bf038986cb8f Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents: 30978
diff changeset
5048
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
5049 /* Initialize gethostbyname lock */
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
5050 #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
5051 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
5052 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5053 }
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
5054
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5055
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5056 #ifndef HAVE_INET_PTON
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5057
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
5058 /* 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
5059 /* 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
5060
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
5061 int
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5062 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
5063 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5064 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
5065 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
5066 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
5067 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
5068 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
5069 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
5070 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
5071 }
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 /* 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
5073 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
5074 }
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
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
5076 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
5077 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
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 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
5080 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
5081 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
5082 /* 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
5083 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
5084 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
5085 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
5086 }
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 /* 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
5088 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
5089 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
5090
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
5091 #endif