annotate Modules/socketmodule.c @ 29066:90342f395721 legacy-trunk

Patch #734231: Update RiscOS support. In particular, correct riscospath.extsep, and use os.extsep throughout.
author Martin v. Löwis <martin@v.loewis.de>
date Sat, 10 May 2003 07:36:56 +0000
parents db90843b00fc
children 0a3751df4195
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
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
10 portable manner, though AF_PACKET is 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
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
28 - socket.getservbyname(servicename, protocolname) --> port number
25105
39e09f30f7ef Update the module doc comment.
Guido van Rossum <guido@python.org>
parents: 24687
diff changeset
29 - socket.socket([family[, type [, proto]]]) --> new socket object
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
30 - 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
31 - 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
32 - 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
33 - 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
34 - 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
35 --> 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
36 - socket.getnameinfo(sockaddr, flags) --> (host, port)
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
37 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h>
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
38 - 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
39 - 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
40 - 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
41 - socket.getdefaulttimeout() -> None | float
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
42 - socket.setdefaulttimeout(None | float)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 - an Internet socket address is a pair (hostname, port)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 where hostname can be anything recognized by gethostbyname()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 (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
46 - 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
47 - 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
48 - 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
49 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
50 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
51 ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
52 specify packet-type and ha-type/addr -- these are ignored by
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
53 networking code, but accepted since they are returned by the
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
54 getsockname() method.
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
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
64 #include "Python.h"
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
65
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
66 #undef MAX
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
67 #define MAX(x, y) ((x) < (y) ? (y) : (x))
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
68
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
69 /* Socket object documentation */
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
70 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
71 "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
72 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
73 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
74 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
75 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
76 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
77 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
78 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
79 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
80 \n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
81 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
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 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 recv(buflen[, flags]) -- receive data\n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
97 recvfrom(buflen[, flags]) -- receive data and sender's address\n\
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
106 [*] not available on all platforms!");
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
107
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
108 /* XXX This is a terrible mess of of platform-dependent preprocessor hacks.
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
109 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
110
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
111 /* 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
112 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
113 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
114 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
115
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
116 #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
117 # 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
118 # 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
119 # 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
120 #endif
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
121
10579
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
122 #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
123 # 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
124 #endif
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
125
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
126 #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
127 # 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
128 # 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
129 # 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
130 # 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
131 # 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
132 /* 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
133 # 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
134 # 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
135 # endif
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
136 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
137
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
138 #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
139 !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
140 # define USE_GETHOSTBYNAME_LOCK
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
141 #endif
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
142
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
143 /* 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
144 (this includes the getaddrinfo emulation) protect access with a lock. */
29037
db90843b00fc Yet another addition to [731644]: only use the lock if thread-support
Just van Rossum <just@letterror.com>
parents: 29036
diff changeset
145 #if defined(WITH_THREAD) && (defined(__APPLE__) || defined(__FreeBSD__) || \
db90843b00fc Yet another addition to [731644]: only use the lock if thread-support
Just van Rossum <just@letterror.com>
parents: 29036
diff changeset
146 defined(__OpenBSD__) || defined(__NetBSD__) || !defined(HAVE_GETADDRINFO))
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
147 #define USE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
148 #endif
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
149
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
150 #ifdef USE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
151 #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
152 #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
153 #else
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
154 #define ACQUIRE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
155 #define RELEASE_GETADDRINFO_LOCK
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
156 #endif
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
157
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
158 #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
159 # include "pythread.h"
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
160 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
162 #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
163 # 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
164 # 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
165 # 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
166 # 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
167 # include <ctype.h>
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
168 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
169
26551
0c995cd07026 Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26550
diff changeset
170 #if defined(__VMS)
0c995cd07026 Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26550
diff changeset
171 #if ! defined(_SOCKADDR_LEN)
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
172 # ifdef getaddrinfo
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
173 # undef getaddrinfo
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
174 # endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
175 # include "TCPIP_IOCTL_ROUTINE"
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
176 #else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
177 # include <ioctl.h>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
178 #endif
26551
0c995cd07026 Don't include <ioctl.h> unless on __VMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26550
diff changeset
179 #endif
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
180
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
181 #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
182 # 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
183 # 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
184 # 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
185 # include <os2.h>
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
186 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
187
25327
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
188 #if defined(__sgi)&&_COMPILER_VERSION>700 && !_SGIAPI
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
189 /* 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
190 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
191 MIPSPro 7.x in ANSI C mode (default) */
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
192 #define _SGIAPI 1
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
193 #include "netdb.h"
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
194 #endif
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25105
diff changeset
195
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
196 /* Generic includes */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
197 #include <sys/types.h>
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
198 #include <signal.h>
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
199
21961
ea23e6e49290 Also fix the comment.
Marc-André Lemburg <mal@egenix.com>
parents: 21960
diff changeset
200 /* 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
201 #define PySocket_BUILDING_SOCKET
21960
7a917ad8f442 Fix the name of the header file.
Marc-André Lemburg <mal@egenix.com>
parents: 21959
diff changeset
202 #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
203
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
204 /* 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
205
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
206 #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
207
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
208 /* 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
209 # 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
210
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
211 /* 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
212 # 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
213 # 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
214 # 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
215 # 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
216 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
217 # 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
218 # 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
219 # 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
220
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
221 # 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
222 # 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
223 # else
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
224 # 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
225 # 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
226 # define NO_DUP
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
227 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
228 # 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
229 # 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
230
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
231 #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
232
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
233 /* 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
234 # 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
235
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
236 #endif
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
237
18263
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
238 #ifdef HAVE_STDDEF_H
21959
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
239 # include <stddef.h>
18263
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
240 #endif
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
241
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
242 #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
243 # 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
244 #endif
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
245
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
246 #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
247 # define O_NONBLOCK O_NDELAY
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
248 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
249
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
250 #include "addrinfo.h"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
251
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
252 #ifndef HAVE_INET_PTON
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
253 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
254 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
255 #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
256
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
257 #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
258 /* 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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 #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
267 /* 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
268 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
269 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
270 #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
271 #endif
24078
702a5900df7d Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo().
Jack Jansen <jack.jansen@cwi.nl>
parents: 23832
diff changeset
272 #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
273
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
274 /* 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
275 #if !defined(HAVE_GETADDRINFO)
28913
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
276 /* 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
277 #define getaddrinfo fake_getaddrinfo
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
278 #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
279 #define freeaddrinfo fake_freeaddrinfo
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
280 #include "getaddrinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
281 #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
282 #if !defined(HAVE_GETNAMEINFO)
28913
b04c074586aa Patch #725942: Always rename emulation functions.
Martin v. Löwis <martin@v.loewis.de>
parents: 28818
diff changeset
283 #define getnameinfo fake_getnameinfo
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
284 #include "getnameinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
285 #endif
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
286
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
287 #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
288 /* 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
289 /* 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
290 #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
291 #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
292 #endif
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
293
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
294 #ifdef MS_WIN32
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
295 #define EAFNOSUPPORT WSAEAFNOSUPPORT
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
296 #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
297 #endif
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
298
22115
d104bb50a194 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 22096
diff changeset
299 #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
300 #define SOCKETCLOSE soclose
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
301 #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
302 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
303
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
304 #ifndef SOCKETCLOSE
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
305 #define SOCKETCLOSE close
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
306 #endif
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
307
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
308 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
309 /* TCP/IP Services for VMS uses a maximum send/revc buffer length of 65535 */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
310 #define SEGMENT_SIZE 65535
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
311 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
312
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
313 /*
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
314 * 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
315 */
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
316 #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
317 #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
318 #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
319 #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
320 #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
321 #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
322
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
323 /* 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
324 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
325
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
326 /* 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
327 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
328 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
329 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
330 static PyObject *socket_gaierror;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
331
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
332 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
333 /* 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
334 static int taskwindow;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
335 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
336
21970
b1a871dc5196 Moved the declaration of PySocketSock_Type from socketmodule.h to
Tim Peters <tim.peters@gmail.com>
parents: 21964
diff changeset
337 /* 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
338 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
339 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
340 there has to be a circular reference. */
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24078
diff changeset
341 static PyTypeObject sock_type;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
342
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
343 /* 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
344 and return a NULL pointer from a function. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
346 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
347 set_error(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
349 #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
350 int err_no = WSAGetLastError();
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
351 static struct {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
352 int no;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
353 const char *msg;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
354 } *msgp, msgs[] = {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
355 {WSAEINTR, "Interrupted system call"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
356 {WSAEBADF, "Bad file descriptor"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
357 {WSAEACCES, "Permission denied"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
358 {WSAEFAULT, "Bad address"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
359 {WSAEINVAL, "Invalid argument"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
360 {WSAEMFILE, "Too many open files"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
361 {WSAEWOULDBLOCK,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
362 "The socket operation could not complete "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
363 "without blocking"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
364 {WSAEINPROGRESS, "Operation now in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
365 {WSAEALREADY, "Operation already in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
366 {WSAENOTSOCK, "Socket operation on non-socket"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
367 {WSAEDESTADDRREQ, "Destination address required"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
368 {WSAEMSGSIZE, "Message too long"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
369 {WSAEPROTOTYPE, "Protocol wrong type for socket"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
370 {WSAENOPROTOOPT, "Protocol not available"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
371 {WSAEPROTONOSUPPORT, "Protocol not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
372 {WSAESOCKTNOSUPPORT, "Socket type not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
373 {WSAEOPNOTSUPP, "Operation not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
374 {WSAEPFNOSUPPORT, "Protocol family not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
375 {WSAEAFNOSUPPORT, "Address family not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
376 {WSAEADDRINUSE, "Address already in use"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
377 {WSAEADDRNOTAVAIL, "Can't assign requested address"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
378 {WSAENETDOWN, "Network is down"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
379 {WSAENETUNREACH, "Network is unreachable"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
380 {WSAENETRESET, "Network dropped connection on reset"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
381 {WSAECONNABORTED, "Software caused connection abort"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
382 {WSAECONNRESET, "Connection reset by peer"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
383 {WSAENOBUFS, "No buffer space available"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
384 {WSAEISCONN, "Socket is already connected"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
385 {WSAENOTCONN, "Socket is not connected"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
386 {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
387 {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
388 {WSAETIMEDOUT, "Operation timed out"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
389 {WSAECONNREFUSED, "Connection refused"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
390 {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
391 {WSAENAMETOOLONG, "File name too long"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
392 {WSAEHOSTDOWN, "Host is down"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
393 {WSAEHOSTUNREACH, "No route to host"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
394 {WSAENOTEMPTY, "Directory not empty"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
395 {WSAEPROCLIM, "Too many processes"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
396 {WSAEUSERS, "Too many users"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
397 {WSAEDQUOT, "Disc quota exceeded"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
398 {WSAESTALE, "Stale NFS file handle"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
399 {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
400 {WSASYSNOTREADY, "Network subsystem is unvailable"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
401 {WSAVERNOTSUPPORTED, "WinSock version is not supported"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
402 {WSANOTINITIALISED,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
403 "Successful WSAStartup() not yet performed"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
404 {WSAEDISCON, "Graceful shutdown in progress"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
405 /* Resolver errors */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
406 {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
407 {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
408 {WSANO_RECOVERY, "Unexpected server error encountered"},
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
409 {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
410 {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
411 {0, NULL}
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
412 };
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
413 if (err_no) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
414 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
415 const char *msg = "winsock error";
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
416
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
417 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
418 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
419 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
420 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
421 }
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
422 }
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
423
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
424 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
425 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
426 PyErr_SetObject(socket_error, v);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
427 Py_DECREF(v);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
428 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
429 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
430 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
431 else
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
432 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
433
22115
d104bb50a194 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 22096
diff changeset
434 #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
435 if (sock_errno() != NO_ERROR) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
436 APIRET rc;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
437 ULONG msglen;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
438 char outbuf[100];
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
439 int myerrorcode = sock_errno();
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
440
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
441 /* 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
442 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
443 myerrorcode - SOCBASEERR + 26,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
444 "mptn.msg",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
445 &msglen);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
446 if (rc == NO_ERROR) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
447 PyObject *v;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
448
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
449 /* 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
450 outbuf[msglen] = '\0';
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
451 if (strlen(outbuf) > 0) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
452 /* If non-empty msg, trim CRLF */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
453 char *lastc = &outbuf[ strlen(outbuf)-1 ];
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
454 while (lastc > outbuf && isspace(*lastc)) {
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
455 /* Trim trailing whitespace (CRLF) */
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
456 *lastc-- = '\0';
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
457 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
458 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
459 v = Py_BuildValue("(is)", myerrorcode, outbuf);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
460 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
461 PyErr_SetObject(socket_error, v);
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
462 Py_DECREF(v);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
463 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
464 return NULL;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
465 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
466 }
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
467 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
468
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
469 #if defined(RISCOS)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
470 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
471 PyObject *v;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
472 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
473 if (v != NULL) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
474 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
475 Py_DECREF(v);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
476 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
477 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
478 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
479 #endif
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
480
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
481 return PyErr_SetFromErrno(socket_error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
483
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
484
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
485 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
486 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
487 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
488 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
489
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
490 #ifdef HAVE_HSTRERROR
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
491 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
492 #else
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
493 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
494 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
495 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
496 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
497 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
498 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
499
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
500 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
501 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
502
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
503
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
504 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
505 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
506 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
507 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
508
22096
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
509 #ifdef EAI_SYSTEM
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
510 /* 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
511 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
512 return set_error();
22096
9e5ff6747437 Patch #520062: Support IPv6 with VC.NET.
Martin v. Löwis <martin@v.loewis.de>
parents: 21970
diff changeset
513 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
514
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
515 #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
516 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
517 #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
518 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
519 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
520 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
521 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
522 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
523 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
524
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
525 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
526 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
527
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
528 /* 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
529 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
530 static int
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
531 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
532 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
533 #ifndef RISCOS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
534 #ifndef MS_WINDOWS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
535 int delay_flag;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
536 #endif
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
537 #endif
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
538
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
539 Py_BEGIN_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
540 #ifdef __BEOS__
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
541 block = !block;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
542 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
543 (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
544 #else
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
545 #ifndef RISCOS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
546 #ifndef MS_WINDOWS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
547 #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
548 block = !block;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
549 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
550 #elif defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
551 block = !block;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
552 ioctl(s->sock_fd, FIONBIO, (char *)&block);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
553 #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
554 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
555 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
556 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
557 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
558 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
559 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
560 #endif /* !PYOS_OS2 */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
561 #else /* MS_WINDOWS */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
562 block = !block;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
563 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
564 #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
565 #else /* RISCOS */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
566 block = !block;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
567 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
568 #endif /* RISCOS */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
569 #endif /* __BEOS__ */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
570 Py_END_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
571
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
572 /* 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
573 return 1;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
574 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
575
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
576 /* Do a select() on the socket, if necessary (sock_timeout > 0).
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
577 The argument writing indicates the direction.
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
578 This does not raise an exception or return a success indicator;
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
579 we'll let the actual socket call do that. */
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
580 static void
23722
75c51999c8d5 Correct several blunders in the timeout code, mostly my own fault (for
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
581 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
582 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
583 fd_set fds;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
584 struct timeval tv;
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
585
24317
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
586 /* 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
587 if (s->sock_timeout <= 0.0)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
588 return;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
589
24317
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
590 /* 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
591 if (s->sock_fd < 0)
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
592 return;
29ae8e89153b Bail out early from internal_select() when socket file descriptor
Guido van Rossum <guido@python.org>
parents: 24305
diff changeset
593
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
594 /* Construct the arguments to select */
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
595 tv.tv_sec = (int)s->sock_timeout;
23722
75c51999c8d5 Correct several blunders in the timeout code, mostly my own fault (for
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
596 tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
597 FD_ZERO(&fds);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
598 FD_SET(s->sock_fd, &fds);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
599
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
600 /* See if the socket is ready */
23722
75c51999c8d5 Correct several blunders in the timeout code, mostly my own fault (for
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
601 if (writing)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
602 select(s->sock_fd+1, NULL, &fds, NULL, &tv);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
603 else
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
604 select(s->sock_fd+1, &fds, NULL, NULL, &tv);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
605 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
606
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
607 /* 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
608
24305
428cbbf05639 A Python float is a C double; redeclare defaulttimeout as such; stops
Tim Peters <tim.peters@gmail.com>
parents: 24303
diff changeset
609 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
610
24363
979ff5d0ae07 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents: 24317
diff changeset
611 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
612 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
613 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
614 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
615 #ifdef RISCOS
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
616 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
617 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
618 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
619 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
620 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
621 s->sock_proto = proto;
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
622 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
623
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
624 s->errorhandler = &set_error;
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
625
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
626 if (defaulttimeout >= 0.0)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
627 internal_setblocking(s, 0);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
628
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
629 #ifdef RISCOS
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
630 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
631 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
632 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
633 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
634
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
635
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
636 /* Create a new socket object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
637 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
638 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
639 in NEWOBJ()). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
640
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
641 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
642 new_sockobject(SOCKET_T fd, int family, int type, int proto)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
644 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
645 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
646 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
647 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
648 init_sockobject(s, fd, family, type, proto);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
651
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
652
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
653 /* 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
654 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
655 #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
656 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
657 #endif
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
658
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
659
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
660 /* 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
661 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
662 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
663 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
664 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
665
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 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
667 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
668 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
669 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
670 int error;
28925
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
671 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
672 char ch;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
673
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
674 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
675 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
676 int siz;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
677 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
678 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
679 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
680 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
681 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
682 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
683 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
684 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
685 /* 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
686 *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
687 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
688 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
689 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
690 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
691 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
692 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
693 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
694 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
695 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
696 siz = 4;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
697 break;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
698 #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
699 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
700 siz = 16;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
701 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
702 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
703 default:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
704 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
705 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
706 "unsupported address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
707 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
708 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
709 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
710 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
711 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
712 "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
713 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
714 }
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
715 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
716 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
717 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
718 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
719 return siz;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
720 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
721 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
722 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
723 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
724 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
725 "address family mismatched");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
726 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
727 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
728 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
729 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
730 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
731 #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
732 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
733 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
734 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
735 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
736 }
28925
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
737 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
738 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
739 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
740 struct sockaddr_in *sin;
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
741 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
742 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
743 ((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
744 ((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
745 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
746 #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
747 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
748 #endif
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
749 return 4;
a769e079bb12 Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28913
diff changeset
750 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
751 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
752 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
753 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
754 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
755 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
756 #if defined(__digital__) && defined(__unix__)
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
757 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
758 /* 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
759 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
760 hints.ai_family = AF_INET;
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
761 error = getaddrinfo(name, NULL, &hints, &res);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
762 }
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
763 #endif
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
764 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
765 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
766 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
767 set_gaierror(error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
769 }
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
770 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
771 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
772 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
773 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
774 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
775 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
776 return 4;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
777 #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
778 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
779 return 16;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
780 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
781 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
782 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
783 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
784 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
786
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
787
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
788 /* 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
789 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
790 size numbers). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
791
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
792 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
793 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
794 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
795 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
796 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
797
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
798 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
799 NI_NUMERICHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
800 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
801 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
802 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
803 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
804 return PyString_FromString(buf);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
805 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
806
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
807
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
808 /* 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
809 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
810 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
811 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
812
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
814 static PyObject *
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
815 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
816 {
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
817 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
818 /* No address -- may be recvfrom() from known socket */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
819 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
820 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
821 }
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
822
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
823 #ifdef __BEOS__
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
824 /* 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
825 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
826 #endif
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
827
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
828 switch (addr->sa_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
829
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
830 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
831 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
832 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
833 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
834 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
835 if (addrobj) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
836 a = (struct sockaddr_in *)addr;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
837 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
838 Py_DECREF(addrobj);
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
839 }
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
840 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
841 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
842
27019
9ee4fd05d3cb OS/2 sockets do not support AF_UNIX, even though EMX headers define it
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26597
diff changeset
843 #if defined(AF_UNIX) && !defined(PYOS_OS2)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
844 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
845 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 struct sockaddr_un *a = (struct sockaddr_un *) addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
847 return PyString_FromString(a->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
849 #endif /* AF_UNIX */
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
850
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
851 #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
852 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
853 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
854 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
855 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
856 PyObject *ret = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
857 if (addrobj) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
858 a = (struct sockaddr_in6 *)addr;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
859 ret = Py_BuildValue("Oiii",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
860 addrobj,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
861 ntohs(a->sin6_port),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
862 a->sin6_flowinfo,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
863 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
864 Py_DECREF(addrobj);
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 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
867 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
868 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
869
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
870 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
871 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
872 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
873 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
874 char *ifname = "";
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
875 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
876 /* 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
877 if (a->sll_ifindex) {
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
878 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
879 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0)
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
880 ifname = ifr.ifr_name;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
881 }
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
882 return Py_BuildValue("shbhs#",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
883 ifname,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
884 ntohs(a->sll_protocol),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
885 a->sll_pkttype,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
886 a->sll_hatype,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
887 a->sll_addr,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
888 a->sll_halen);
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
889 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
890 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
891
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
892 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
893
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
894 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
895 /* 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
896 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
897 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
898 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
899 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
900 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
901
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
902 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
904
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
905
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
906 /* 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
907 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
908 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
909 through len_ret. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
910
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
911 static int
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
912 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
913 struct sockaddr **addr_ret, int *len_ret)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
914 {
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
915 switch (s->sock_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
916
27019
9ee4fd05d3cb OS/2 sockets do not support AF_UNIX, even though EMX headers define it
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26597
diff changeset
917 #if defined(AF_UNIX) && !defined(PYOS_OS2)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
918 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
919 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
920 struct sockaddr_un* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
921 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
922 int len;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
923 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
924 if (!PyArg_Parse(args, "t#", &path, &len))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
925 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
926 if (len > sizeof addr->sun_path) {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
927 PyErr_SetString(socket_error,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
928 "AF_UNIX path too long");
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
929 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
930 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
931 addr->sun_family = s->sock_family;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
932 memcpy(addr->sun_path, path, len);
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
933 addr->sun_path[len] = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
934 *addr_ret = (struct sockaddr *) addr;
3666
556ec82f4d93 Calculate length of AF_UNIX addr struct portably in getsockaddrarg().
Guido van Rossum <guido@python.org>
parents: 3665
diff changeset
935 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
936 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
937 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
938 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
939
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
940 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
941 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
942 struct sockaddr_in* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
943 char *host;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
944 int port;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
945 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
946 if (!PyTuple_Check(args)) {
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
947 PyErr_Format(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
948 PyExc_TypeError,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
949 "getsockaddrarg: "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
950 "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
951 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
952 return 0;
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
953 }
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
954 if (!PyArg_ParseTuple(args, "eti:getsockaddrarg",
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
955 "idna", &host, &port))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
956 return 0;
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
957 if (setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
958 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
959 addr->sin_family = AF_INET;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
960 addr->sin_port = htons((short)port);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
961 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
962 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
963 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
964 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
965
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
966 #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
967 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
968 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
969 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
970 char *host;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
971 int port, flowinfo, scope_id;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
972 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
973 flowinfo = scope_id = 0;
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
974 if (!PyArg_ParseTuple(args, "eti|ii",
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
975 "idna", &host, &port, &flowinfo,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
976 &scope_id)) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
977 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
978 }
24411
8e266d0acd10 Pass length of result structure into setipaddr. Fixes bug #565747.
Martin v. Löwis <martin@v.loewis.de>
parents: 24380
diff changeset
979 if (setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET6) < 0)
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
980 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
981 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
982 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
983 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
984 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
985 *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
986 *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
987 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
988 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
989 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
990
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
991 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
992 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
993 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
994 struct sockaddr_ll* addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
995 struct ifreq ifr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
996 char *interfaceName;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
997 int protoNumber;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
998 int hatype = 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
999 int pkttype = 0;
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1000 char *haddr;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1001
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1002 if (!PyArg_ParseTuple(args, "si|iis", &interfaceName,
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1003 &protoNumber, &pkttype, &hatype, &haddr))
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1004 return 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1005 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
1006 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
1007 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
1008 s->errorhandler();
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1009 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
1010 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1011 addr = &(s->sock_addr.ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1012 addr->sll_family = AF_PACKET;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1013 addr->sll_protocol = htons((short)protoNumber);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1014 addr->sll_ifindex = ifr.ifr_ifindex;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1015 addr->sll_pkttype = pkttype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1016 addr->sll_hatype = hatype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1017 *addr_ret = (struct sockaddr *) addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1018 *len_ret = sizeof *addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1019 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1020 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1021 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1022
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1023 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1024
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1025 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1026 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
1027 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1028
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1029 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1030 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1031
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1032
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1033 /* 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
1034 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
1035 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
1036
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1037 static int
13554
906efc1da247 Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13538
diff changeset
1038 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
1039 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1040 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
1041
27019
9ee4fd05d3cb OS/2 sockets do not support AF_UNIX, even though EMX headers define it
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26597
diff changeset
1042 #if defined(AF_UNIX) && !defined(PYOS_OS2)
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1043 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
1044 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1045 *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
1046 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1047 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1048 #endif /* AF_UNIX */
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1049
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1050 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
1051 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1052 *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
1053 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1054 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1055
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
1056 #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
1057 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1058 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1059 *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
1060 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1061 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1062 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1063
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
1064 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1065 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1066 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1067 *len_ret = sizeof (struct sockaddr_ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1068 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1069 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1070 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1071
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1072 /* 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
1073
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1074 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1075 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
1076 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1077
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1078 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1079 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1080
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1081
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1082 /* s.accept() method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1083
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1084 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
1085 sock_accept(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1086 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1087 char addrbuf[256];
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1088 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
1089 socklen_t addrlen;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1090 PyObject *sock = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1091 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1092 PyObject *res = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1093
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
1094 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
1095 return NULL;
17737
0ebfe9a1eb43 Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents: 17537
diff changeset
1096 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
1097
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1098 Py_BEGIN_ALLOW_THREADS
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1099 internal_select(s, 0);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1100 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1101 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
1102
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1103 #ifdef MS_WINDOWS
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1104 if (newfd == INVALID_SOCKET)
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1105 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1106 if (newfd < 0)
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1107 #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
1108 return s->errorhandler();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1109
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1110 /* 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
1111 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
1112 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
1113 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
1114 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
1115 s->sock_proto);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1116
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1117 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
1118 SOCKETCLOSE(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1119 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1120 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1121 addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1122 addrlen);
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1123 if (addr == NULL)
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1124 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1125
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1126 res = Py_BuildValue("OO", sock, addr);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1127
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1128 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1129 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1130 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1131 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1132 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1133
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1134 PyDoc_STRVAR(accept_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1135 "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
1136 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1137 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
1138 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
1139 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
1140
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1141 /* s.setblocking(flag) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1142 False -- non-blocking mode; same as settimeout(0)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1143 True -- blocking mode; same as settimeout(None)
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1144 */
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1145
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1146 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
1147 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
1148 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1149 int block;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1150
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1151 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
1152 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
1153 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1154
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1155 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
1156 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
1157
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1158 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1159 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
1160 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1161
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1162 PyDoc_STRVAR(setblocking_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1163 "setblocking(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1164 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1165 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
1166 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
1167 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
1168
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1169 /* s.settimeout(timeout) method. Argument:
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1170 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
1171 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
1172 > 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
1173 < 0 -- illegal; raises an exception
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1174 */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1175 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
1176 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
1177 {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1178 double timeout;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1179
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1180 if (arg == Py_None)
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1181 timeout = -1.0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1182 else {
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1183 timeout = PyFloat_AsDouble(arg);
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1184 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
1185 if (!PyErr_Occurred())
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1186 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1187 "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
1188 return NULL;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1189 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1190 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1191
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1192 s->sock_timeout = timeout;
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1193 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
1194
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1195 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1196 return Py_None;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1197 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1198
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1199 PyDoc_STRVAR(settimeout_doc,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1200 "settimeout(timeout)\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1201 \n\
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1202 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
1203 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
1204 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
1205 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
1206
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1207 /* s.gettimeout() method.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1208 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
1209 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
1210 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
1211 {
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1212 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
1213 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1214 return Py_None;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1215 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1216 else
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1217 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
1218 }
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1219
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1220 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
1221 "gettimeout() -> timeout\n\
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1222 \n\
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1223 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
1224 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
1225 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
1226
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1227 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1228 /* s.sleeptaskw(1 | 0) method */
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1229
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1230 static PyObject *
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
1231 sock_sleeptaskw(PySocketSockObject *s,PyObject *arg)
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1232 {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1233 int block;
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
1234 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
1235 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
1236 return NULL;
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1237 Py_BEGIN_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1238 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
1239 Py_END_ALLOW_THREADS
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1240
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1241 Py_INCREF(Py_None);
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1242 return Py_None;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1243 }
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1244 PyDoc_STRVAR(sleeptaskw_doc,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1245 "sleeptaskw(flag)\n\
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1246 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1247 Allow sleeps in taskwindows.");
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1248 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1249
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1250
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
1251 /* 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
1252 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
1253 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
1254 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
1255
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1256 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
1257 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
1258 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1259 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1260 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
1261 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
1262 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
1263 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1264 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1265
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1266 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
1267 &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
1268 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
1269 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
1270 }
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
1271 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1272 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
1273 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
1274 &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
1275 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
1276 }
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
1277 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
1278 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
1279 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1280 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1281 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1282 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1283
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1284 PyDoc_STRVAR(setsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1285 "setsockopt(level, option, value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1286 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1287 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
1288 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
1289
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1290
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
1291 /* 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
1292 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
1293 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
1294 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
1295
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1296 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
1297 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
1298 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1299 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1300 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
1301 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1302 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
1303 socklen_t buflen = 0;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1304
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1305 #ifdef __BEOS__
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1306 /* 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
1307 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
1308 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1309 #else
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1310
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1311 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
1312 &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
1313 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1314
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
1315 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
1316 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
1317 socklen_t flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1318 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
1319 (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
1320 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
1321 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1322 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
1323 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1324 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1325 if (buflen > 1024) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1326 #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
1327 if (buflen <= 0 || buflen > 1024) {
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1328 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1329 PyErr_SetString(socket_error,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1330 "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
1331 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
1332 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1333 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
1334 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
1335 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1336 res = getsockopt(s->sock_fd, level, optname,
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1337 (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
1338 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1339 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
1340 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
1341 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1342 _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
1343 return buf;
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1344 #endif /* __BEOS__ */
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1345 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1346
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1347 PyDoc_STRVAR(getsockopt_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1348 "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
1349 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1350 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
1351 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
1352 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
1353
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1354
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1355 /* s.bind(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1356
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1357 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
1358 sock_bind(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1359 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1360 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1361 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1362 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
1363
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1364 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1365 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1366 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1367 res = bind(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1368 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1369 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
1370 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1371 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1372 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1373 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1374
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1375 PyDoc_STRVAR(bind_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1376 "bind(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1377 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1378 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
1379 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
1380 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
1381
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1382
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1383 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1384 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
1385 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1386
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1387 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
1388 sock_close(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1389 {
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
1390 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
1391
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
1392 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
1393 s->sock_fd = -1;
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1394 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
1395 (void) SOCKETCLOSE(fd);
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1396 Py_END_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1397 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1398 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1399 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1400 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1401
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1402 PyDoc_STRVAR(close_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1403 "close()\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1404 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1405 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
1406
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1407 static int
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1408 internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1409 {
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1410 int res;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1411
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1412 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
1413
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1414 #ifdef MS_WINDOWS
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1415
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1416 if (s->sock_timeout > 0.0) {
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1417 if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
27981
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1418 /* 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
1419 fd_set fds;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1420 struct timeval tv;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1421 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
1422 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
1423 FD_ZERO(&fds);
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1424 FD_SET(s->sock_fd, &fds);
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1425 res = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1426 if (res == 0)
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1427 res = WSAEWOULDBLOCK;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1428 else if (res > 0)
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1429 res = 0;
eb2a984d3747 The connect timeout code wasn't working on Windows.
Guido van Rossum <guido@python.org>
parents: 27861
diff changeset
1430 /* 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
1431 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1432 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1433
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1434 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1435 res = WSAGetLastError();
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1436
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1437 #else
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1438
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1439 if (s->sock_timeout > 0.0) {
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1440 if (res < 0 && errno == EINPROGRESS) {
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1441 internal_select(s, 1);
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1442 res = connect(s->sock_fd, addr, addrlen);
24677
479cb5ff2e60 The other half of the patches added to SF patch 555085 by A I
Guido van Rossum <guido@python.org>
parents: 24676
diff changeset
1443 if (res < 0 && errno == EISCONN)
479cb5ff2e60 The other half of the patches added to SF patch 555085 by A I
Guido van Rossum <guido@python.org>
parents: 24676
diff changeset
1444 res = 0;
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1445 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1446 }
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1447
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1448 if (res < 0)
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1449 res = errno;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1450
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1451 #endif
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1452
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1453 return res;
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1454 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1455
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1456 /* s.connect(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1457
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1458 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
1459 sock_connect(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1460 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1461 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1462 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1463 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
1464
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1465 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1466 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1467
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1468 Py_BEGIN_ALLOW_THREADS
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1469 res = internal_connect(s, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1470 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
1471
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1472 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
1473 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1474 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1475 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1476 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1477
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1478 PyDoc_STRVAR(connect_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1479 "connect(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1480 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1481 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
1482 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
1483
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1484
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1485 /* 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
1486
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1487 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
1488 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
1489 {
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1490 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
1491 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
1492 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
1493
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1494 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
1495 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1496
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1497 Py_BEGIN_ALLOW_THREADS
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
1498 res = internal_connect(s, 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
1499 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
1500
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1501 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
1502 }
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1503
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1504 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
1505 "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
1506 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1507 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
1508 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
1509
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1510
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
1511 /* 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
1512
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1513 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
1514 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
1515 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1516 #if SIZEOF_SOCKET_T <= SIZEOF_LONG
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1517 return PyInt_FromLong((long) s->sock_fd);
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1518 #else
28437
871da703e4c0 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents: 27981
diff changeset
1519 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
1520 #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
1521 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
1522
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1523 PyDoc_STRVAR(fileno_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1524 "fileno() -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1525 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1526 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
1527
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
1528
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
1529 #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
1530 /* 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
1531
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
1532 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
1533 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
1534 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1535 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
1536 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
1537
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
1538 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
1539 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
1540 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
1541 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
1542 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
1543 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
1544 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
1545 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
1546 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
1547 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
1548 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1549
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1550 PyDoc_STRVAR(dup_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1551 "dup() -> socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1552 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1553 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
1554
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
1555 #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
1556
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
1557
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1558 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1559
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1560 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
1561 sock_getsockname(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1562 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1563 char addrbuf[256];
12479
a3e1fecb43c6 Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents: 12436
diff changeset
1564 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
1565 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
1566
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1567 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1568 return NULL;
3335
9bd1e41d6b11 clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents: 3091
diff changeset
1569 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1570 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1571 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1572 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1573 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
1574 return s->errorhandler();
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1575 return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1576 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1577
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1578 PyDoc_STRVAR(getsockname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1579 "getsockname() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1580 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1581 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
1582 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
1583
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1584
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1585 #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
1586 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1587
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1588 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
1589 sock_getpeername(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1590 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1591 char addrbuf[256];
12479
a3e1fecb43c6 Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents: 12436
diff changeset
1592 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
1593 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
1594
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1595 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1596 return NULL;
17737
0ebfe9a1eb43 Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents: 17537
diff changeset
1597 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1598 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1599 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1600 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1601 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
1602 return s->errorhandler();
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1603 return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1604 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1605
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1606 PyDoc_STRVAR(getpeername_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1607 "getpeername() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1608 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1609 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
1610 info is a pair (hostaddr, port).");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1611
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1612 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1613
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1614
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1615 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1616
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1617 static PyObject *
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
1618 sock_listen(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1619 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1620 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1621 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
1622
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1623 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
1624 if (backlog == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1625 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1626 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1627 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1628 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1629 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1630 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1631 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
1632 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1633 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1634 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1635 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1636
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1637 PyDoc_STRVAR(listen_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1638 "listen(backlog)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1639 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1640 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
1641 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
1642 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
1643
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1644
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1645 #ifndef NO_DUP
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1646 /* s.makefile(mode) method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1647 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
1648 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
1649 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
1650 of each other.)
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1651 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
1652
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1653 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
1654 sock_makefile(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1655 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13403
diff changeset
1656 extern int fclose(FILE *);
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1657 char *mode = "r";
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1658 int bufsize = -1;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1659 #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
1660 Py_intptr_t fd;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1661 #else
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1662 int fd;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1663 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1664 FILE *fp;
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1665 PyObject *f;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1666 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1667 char *mode_r = "r";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1668 char *mode_w = "w";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1669 #endif
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1670
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1671 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
1672 return NULL;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1673 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1674 if (strcmp(mode,"rb") == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1675 mode = mode_r;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1676 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1677 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1678 if (strcmp(mode,"wb") == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1679 mode = mode_w;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1680 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1681 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1682 #endif
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1683 #ifdef MS_WIN32
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1684 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
1685 ((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
1686 #else
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1687 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
1688 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1689 {
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1690 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
1691 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
1692 return s->errorhandler();
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1693 }
22547
0922c919cedb Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 22115
diff changeset
1694 #ifdef USE_GUSI2
0922c919cedb Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 22115
diff changeset
1695 /* Workaround for bug in Metrowerks MSL vs. GUSI I/O library */
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1696 if (strchr(mode, 'b') != NULL)
22547
0922c919cedb Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 22115
diff changeset
1697 bufsize = 0;
0922c919cedb Due to interaction between the MSL C library and the GUSI I/O library I can get reads from sockets to work consistently either for unbuffered binary files or for buffered binary files, but not for both:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 22115
diff changeset
1698 #endif
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1699 f = PyFile_FromFile(fp, "<socket>", mode, fclose);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1700 if (f != NULL)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1701 PyFile_SetBufSize(f, bufsize);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1702 return f;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1703 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1704
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1705 PyDoc_STRVAR(makefile_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1706 "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
1707 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1708 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
1709 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
1710
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1711 #endif /* NO_DUP */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1712
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1713
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
1714 /* 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
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_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
1718 {
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
1719 int len, n, flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1720 PyObject *buf;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1721 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1722 int read_length;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1723 char *read_buf;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1724 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1725
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1726 if (!PyArg_ParseTuple(args, "i|i:recv", &len, &flags))
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
1727 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1728
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1729 if (len < 0) {
21022
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
1730 PyErr_SetString(PyExc_ValueError,
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1731 "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
1732 return NULL;
9f66aaddf8d4 Test for negative buffer sizes. Fixes #482871.
Martin v. Löwis <martin@v.loewis.de>
parents: 20920
diff changeset
1733 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1734
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1735 buf = PyString_FromStringAndSize((char *) 0, len);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1736 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1737 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1738
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1739 #ifndef __VMS
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1740 Py_BEGIN_ALLOW_THREADS
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1741 internal_select(s, 0);
19401
8607bc890b1f It will always be a string, because it is created just before this call.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19278
diff changeset
1742 n = recv(s->sock_fd, PyString_AS_STRING(buf), len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1743 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
1744
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1745 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1746 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
1747 return s->errorhandler();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1748 }
23295
6fa76b4e59fe Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents: 22974
diff changeset
1749 if (n != len)
6fa76b4e59fe Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents: 22974
diff changeset
1750 _PyString_Resize(&buf, n);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1751 #else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1752 read_buf = PyString_AsString(buf);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1753 read_length = len;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1754 while (read_length != 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1755 unsigned int segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1756
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1757 segment = read_length /SEGMENT_SIZE;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1758 if (segment != 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1759 segment = SEGMENT_SIZE;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1760 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1761 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1762 segment = read_length;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1763 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1764
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1765 Py_BEGIN_ALLOW_THREADS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1766 internal_select(s, 0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1767 n = recv(s->sock_fd, read_buf, segment, flags);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1768 Py_END_ALLOW_THREADS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1769
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1770 if (n < 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1771 Py_DECREF(buf);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1772 return s->errorhandler();
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1773 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1774 if (n != read_length) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1775 read_buf += n;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1776 break;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1777 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1778
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1779 read_length -= segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1780 read_buf += segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1781 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1782 if (_PyString_Resize(&buf, (read_buf - PyString_AsString(buf))) < 0)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1783 {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1784 return NULL;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1785 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1786 #endif /* !__VMS */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1787 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1788 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1789
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1790 PyDoc_STRVAR(recv_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1791 "recv(buffersize[, flags]) -> data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1792 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1793 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
1794 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
1795 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
1796 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
1797
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1798
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
1799 /* s.recvfrom(nbytes [,flags]) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1800
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1801 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
1802 sock_recvfrom(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1803 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1804 char addrbuf[256];
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1805 PyObject *buf = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1806 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1807 PyObject *ret = NULL;
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
1808 int len, n, flags = 0;
a3e1fecb43c6 Jack Jansen: The GUSI 2.0 I/O library used on the Mac uses the
Guido van Rossum <guido@python.org>
parents: 12436
diff changeset
1809 socklen_t addrlen;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1810
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1811 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &len, &flags))
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
1812 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1813
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1814 if (!getsockaddrlen(s, &addrlen))
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1815 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1816 buf = PyString_FromStringAndSize((char *) 0, len);
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1817 if (buf == NULL)
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1818 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1819
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1820 Py_BEGIN_ALLOW_THREADS
17737
0ebfe9a1eb43 Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents: 17537
diff changeset
1821 memset(addrbuf, 0, addrlen);
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1822 internal_select(s, 0);
17737
0ebfe9a1eb43 Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents: 17537
diff changeset
1823 n = recvfrom(s->sock_fd, PyString_AS_STRING(buf), len, flags,
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1824 #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
1825 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1826 (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
1827 #else
13709
4e2aaf1e722a Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents: 13695
diff changeset
1828 (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
1829 #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
1830 #else
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1831 (struct sockaddr *)addrbuf, &addrlen
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1832 #endif
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1833 );
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1834 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
1835
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1836 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1837 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
1838 return s->errorhandler();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1839 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1840
3665
5188374377ae Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents: 3594
diff changeset
1841 if (n != len && _PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1842 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1843
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1844 if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
1845 addrlen)))
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1846 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1847
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1848 ret = Py_BuildValue("OO", buf, addr);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1849
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1850 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1851 Py_XDECREF(addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1852 Py_XDECREF(buf);
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
1853 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1854 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1855
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1856 PyDoc_STRVAR(recvfrom_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1857 "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
1858 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1859 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
1860
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
1861 /* 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
1862
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1863 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
1864 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
1865 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1866 char *buf;
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
1867 int len, n, flags = 0;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1868 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1869 int send_length;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1870 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1871
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1872 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
1873 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1874
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1875 #ifndef __VMS
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1876 Py_BEGIN_ALLOW_THREADS
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1877 internal_select(s, 1);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1878 n = send(s->sock_fd, buf, len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1879 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
1880
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1881 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
1882 return s->errorhandler();
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1883 #else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1884 /* Divide packet into smaller segments for */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1885 /* TCP/IP Services for OpenVMS */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1886 send_length = len;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1887 while (send_length != 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1888 unsigned int segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1889
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1890 segment = send_length / SEGMENT_SIZE;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1891 if (segment != 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1892 segment = SEGMENT_SIZE;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1893 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1894 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1895 segment = send_length;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1896 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1897 Py_BEGIN_ALLOW_THREADS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1898 internal_select(s, 1);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1899 n = send(s->sock_fd, buf, segment, flags);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1900 Py_END_ALLOW_THREADS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1901 if (n < 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1902 return s->errorhandler();
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1903 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1904 send_length -= segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1905 buf += segment;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1906 } /* end while */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25994
diff changeset
1907 #endif /* !__VMS */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1908 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
1909 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1910
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1911 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
1912 "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
1913 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1914 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
1915 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
1916 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
1917
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1918
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1919 /* 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
1920
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1921 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
1922 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
1923 {
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1924 char *buf;
21964
94b90cdd6e0f Remove extraneous variable 'total', as reported by James Rucker.
Martin v. Löwis <martin@v.loewis.de>
parents: 21961
diff changeset
1925 int len, n, flags = 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1926
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1927 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
1928 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1929
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1930 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
1931 do {
27558
8d83578dba81 SF patch #678257 by Geoff Talvola.
Guido van Rossum <guido@python.org>
parents: 27104
diff changeset
1932 internal_select(s, 1);
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1933 n = send(s->sock_fd, buf, len, flags);
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1934 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
1935 break;
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1936 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
1937 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
1938 } 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
1939 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
1940
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1941 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
1942 return s->errorhandler();
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1943
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1944 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
1945 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
1946 }
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1947
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1948 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
1949 "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
1950 \n\
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
1951 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
1952 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
1953 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
1954 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
1955
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1956
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
1957 /* 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
1958
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1959 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
1960 sock_sendto(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1961 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1962 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1963 char *buf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1964 struct sockaddr *addr;
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1965 int addrlen, len, n, flags;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1966
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
1967 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
1968 if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1969 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
1970 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
1971 &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
1972 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1973 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1974
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
1975 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1976 return NULL;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
1977
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1978 Py_BEGIN_ALLOW_THREADS
23815
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23807
diff changeset
1979 internal_select(s, 1);
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
1980 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1981 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
1982
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1983 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
1984 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1985 return PyInt_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1986 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1987
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
1988 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
1989 "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
1990 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1991 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
1992 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
1993
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1994
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1995 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1996
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1997 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
1998 sock_shutdown(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1999 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2000 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2001 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
2002
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
2003 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
2004 if (how == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2005 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2006 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2007 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2008 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2009 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
2010 return s->errorhandler();
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2011 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2012 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2013 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2014
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2015 PyDoc_STRVAR(shutdown_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2016 "shutdown(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2017 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2018 Shut down the reading side of the socket (flag == 0), the writing side\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2019 of the socket (flag == 1), or both ends (flag == 2).");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2020
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2021
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2022 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2023
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2024 static PyMethodDef sock_methods[] = {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2025 {"accept", (PyCFunction)sock_accept, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2026 accept_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2027 {"bind", (PyCFunction)sock_bind, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2028 bind_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2029 {"close", (PyCFunction)sock_close, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2030 close_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2031 {"connect", (PyCFunction)sock_connect, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2032 connect_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2033 {"connect_ex", (PyCFunction)sock_connect_ex, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2034 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
2035 #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
2036 {"dup", (PyCFunction)sock_dup, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2037 dup_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2038 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2039 {"fileno", (PyCFunction)sock_fileno, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2040 fileno_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2041 #ifdef HAVE_GETPEERNAME
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2042 {"getpeername", (PyCFunction)sock_getpeername,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2043 METH_NOARGS, getpeername_doc},
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2044 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2045 {"getsockname", (PyCFunction)sock_getsockname,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2046 METH_NOARGS, getsockname_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2047 {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2048 getsockopt_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2049 {"listen", (PyCFunction)sock_listen, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2050 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
2051 #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
2052 {"makefile", (PyCFunction)sock_makefile, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2053 makefile_doc},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2054 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2055 {"recv", (PyCFunction)sock_recv, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2056 recv_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2057 {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2058 recvfrom_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2059 {"send", (PyCFunction)sock_send, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2060 send_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2061 {"sendall", (PyCFunction)sock_sendall, METH_VARARGS,
20679
e89c25ca6b29 Add sendall() method, which loops until all data is written or an
Guido van Rossum <guido@python.org>
parents: 20661
diff changeset
2062 sendall_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2063 {"sendto", (PyCFunction)sock_sendto, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2064 sendto_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2065 {"setblocking", (PyCFunction)sock_setblocking, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2066 setblocking_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2067 {"settimeout", (PyCFunction)sock_settimeout, METH_O,
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2068 settimeout_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2069 {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS,
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2070 gettimeout_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2071 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2072 setsockopt_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2073 {"shutdown", (PyCFunction)sock_shutdown, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2074 shutdown_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2075 #ifdef RISCOS
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2076 {"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2077 sleeptaskw_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2078 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2079 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2080 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2081
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2082
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2083 /* 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
2084 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2085
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2086 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
2087 sock_dealloc(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2088 {
12319
57f34e162e67 In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents: 12229
diff changeset
2089 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
2090 (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
2091 s->ob_type->tp_free((PyObject *)s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2092 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2093
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2094
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2095 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
2096 sock_repr(PySocketSockObject *s)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2097 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2098 char buf[512];
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2099 #if SIZEOF_SOCKET_T > SIZEOF_LONG
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2100 if (s->sock_fd > LONG_MAX) {
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2101 /* 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
2102 ugly printf formatter for decimal pointer length integer
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2103 printing, only bother if necessary*/
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2104 PyErr_SetString(PyExc_OverflowError,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2105 "no printf formatter to display "
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2106 "the socket descriptor in decimal");
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2107 return NULL;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2108 }
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2109 #endif
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2110 PyOS_snprintf(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2111 buf, sizeof(buf),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2112 "<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
2113 (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
2114 s->sock_type,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2115 s->sock_proto);
3421
90b54312661a remove unused variables
Guido van Rossum <guido@python.org>
parents: 3390
diff changeset
2116 return PyString_FromString(buf);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2117 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2118
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2119
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2120 /* 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
2121
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2122 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
2123 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
2124 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2125 PyObject *new;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2126
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2127 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
2128 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
2129 ((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
2130 ((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
2131 ((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
2132 }
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2133 return new;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2134 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2135
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2136
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2137 /* 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
2138
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2139 /*ARGSUSED*/
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2140 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
2141 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
2142 {
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2143 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
2144 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
2145 int family = AF_INET, type = SOCK_STREAM, proto = 0;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2146 static char *keywords[] = {"family", "type", "proto", 0};
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2147
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2148 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
2149 "|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
2150 &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
2151 return -1;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2152
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2153 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
2154 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
2155 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
2156
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2157 #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
2158 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
2159 #else
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2160 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
2161 #endif
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2162 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2163 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
2164 return -1;
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2165 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2166 init_sockobject(s, fd, family, type, proto);
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2167 /* From now on, ignore SIGPIPE and let the error checking
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2168 do the work. */
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2169 #ifdef SIGPIPE
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2170 (void) signal(SIGPIPE, SIG_IGN);
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2171 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2172
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2173 return 0;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2174
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2175 }
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2176
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2177
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2178 /* 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
2179
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2180 static PyTypeObject sock_type = {
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
2181 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
2182 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
2183 "_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
2184 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
2185 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
2186 (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
2187 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
2188 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
2189 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
2190 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
2191 (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
2192 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
2193 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
2194 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
2195 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
2196 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
2197 0, /* tp_str */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2198 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
2199 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
2200 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
2201 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
2202 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
2203 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
2204 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
2205 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
2206 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
2207 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
2208 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
2209 sock_methods, /* tp_methods */
20727
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2210 0, /* tp_members */
abd71e89840f Made SocketType and socket the same thing: a subclassable type whose
Guido van Rossum <guido@python.org>
parents: 20679
diff changeset
2211 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
2212 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
2213 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
2214 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
2215 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
2216 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
2217 sock_initobj, /* tp_init */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2218 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
2219 sock_new, /* tp_new */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 27019
diff changeset
2220 PyObject_Del, /* tp_free */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2221 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2222
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2223
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2224 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2225
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2226 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2227 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
2228 socket_gethostname(PyObject *self, PyObject *args)
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2229 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2230 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2231 int res;
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2232 if (!PyArg_ParseTuple(args, ":gethostname"))
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2233 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2234 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2235 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2236 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2237 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
2238 return set_error();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2239 buf[sizeof buf - 1] = '\0';
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2240 return PyString_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2241 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2242
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2243 PyDoc_STRVAR(gethostname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2244 "gethostname() -> string\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2245 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2246 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
2247
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2248
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2249 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2250
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2251 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2252 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
2253 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
2254 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2255 char *name;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2256 #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
2257 struct sockaddr_storage addrbuf;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2258 #else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2259 struct sockaddr_in addrbuf;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2260 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2261
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2262 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
2263 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
2264 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
2265 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2266 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
2267 sizeof(struct sockaddr_in));
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2268 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2269
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2270 PyDoc_STRVAR(gethostbyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2271 "gethostbyname(host) -> address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2272 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2273 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
2274
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2275
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2276 /* 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
2277
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2278 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2279 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
2280 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2281 char **pch;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2282 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
2283 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
2284 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
2285 PyObject *tmp;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2286
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2287 if (h == NULL) {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2288 /* 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
2289 #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
2290 set_herror(h_errno);
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
2291 #else
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2292 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
2293 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2294 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2295 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2296
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2297 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
2298 #ifdef HAVE_STRERROR
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2299 /* 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
2300 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2301 (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
2302 #else
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2303 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
2304 socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2305 "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
2306 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2307 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2308 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2309
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2310 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2311
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2312 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2313 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
2314 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2315 break;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2316
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
2317 #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
2318 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2319 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
2320 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2321 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2322 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2323
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2324 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2325
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2326 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
2327 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2328
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2329 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
2330 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2331
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2332 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
2333 int status;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2334 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
2335 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
2336 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2337
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2338 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
2339 Py_DECREF(tmp);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2340
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2341 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2342 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2343 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2344
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2345 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
2346 int status;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2347
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2348 switch (af) {
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2349
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2350 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2351 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2352 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
2353 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
2354 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
2355 #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
2356 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
2357 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2358 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
2359 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
2360
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2361 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
2362 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
2363 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2364 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2365
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
2366 #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
2367 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2368 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2369 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
2370 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
2371 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
2372 #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
2373 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
2374 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2375 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
2376 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
2377 sizeof(sin6));
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2378
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2379 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
2380 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
2381 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2382 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2383 #endif
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2384
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2385 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
2386 PyErr_SetString(socket_error,
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2387 "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
2388 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2389 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2390
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2391 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
2392 goto err;
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2393
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2394 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
2395 Py_DECREF(tmp);
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2396
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2397 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2398 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2399 }
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23714
diff changeset
2400
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2401 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
2402
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2403 err:
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2404 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
2405 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
2406 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
2407 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2408
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2409
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2410 /* 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
2411
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2412 /*ARGSUSED*/
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2413 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
2414 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
2415 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2416 char *name;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2417 struct hostent *h;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2418 #ifdef ENABLE_IPV6
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2419 struct sockaddr_storage addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2420 #else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2421 struct sockaddr_in addr;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28925
diff changeset
2422 #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
2423 struct sockaddr *sa;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
2424 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
2425 #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
2426 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
2427 #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
2428 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
2429 #else
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2430 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
2431 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
2432 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2433 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2434 #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
2435 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2436 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2437 #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
2438
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2439 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
2440 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
2441 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
2442 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2443 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
2444 #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
2445 #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
2446 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
2447 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2448 #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
2449 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
2450 #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
2451 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
2452 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
2453 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
2454 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2455 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2456 #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
2457 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
2458 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2459 h = gethostbyname(name);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
2460 #endif /* HAVE_GETHOSTBYNAME_R */
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
2461 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
2462 /* 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
2463 addr.ss_family.
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2464 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
2465 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
2466 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
2467 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
2468 sa->sa_family);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2469 #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
2470 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
2471 #endif
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
2472 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
2473 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2474
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2475 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
2476 "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
2477 \n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2478 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
2479 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
2480
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
2481
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2482 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2483
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2484 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2485 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
2486 socket_gethostbyaddr(PyObject *self, PyObject *args)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2487 {
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
2488 #ifdef ENABLE_IPV6
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2489 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
2490 #else
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2491 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
2492 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2493 struct sockaddr *sa = (struct sockaddr *)&addr;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2494 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2495 struct hostent *h;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2496 PyObject *ret;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2497 #ifdef HAVE_GETHOSTBYNAME_R
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2498 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
2499 #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
2500 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
2501 #else
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2502 char buf[16384];
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2503 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
2504 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2505 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2506 #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
2507 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
2508 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2509 #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
2510 char *ap;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2511 int al;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2512 int af;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2513
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2514 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
2515 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
2516 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
2517 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
2518 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2519 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
2520 ap = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2521 al = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2522 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2523 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2524 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
2525 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
2526 break;
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
2527 #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
2528 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2529 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
2530 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
2531 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2532 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2533 default:
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2534 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
2535 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2536 }
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2537 Py_BEGIN_ALLOW_THREADS
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2538 #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
2539 #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
2540 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
2541 &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
2542 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2543 #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
2544 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
2545 &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
2546 #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
2547 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
2548 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
2549 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
2550 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2551 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2552 #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
2553 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
2554 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2555 h = gethostbyaddr(ap, al, af);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2556 #endif /* HAVE_GETHOSTBYNAME_R */
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2557 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
2558 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
2559 #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
2560 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
2561 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2562 return ret;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2563 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2564
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2565 PyDoc_STRVAR(gethostbyaddr_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2566 "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
2567 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2568 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
2569 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
2570
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2571
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2572 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2573 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
2574 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
2575
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2576 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2577 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
2578 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
2579 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2580 char *name, *proto;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2581 struct servent *sp;
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2582 if (!PyArg_ParseTuple(args, "ss:getservbyname", &name, &proto))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2583 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2584 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2585 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2586 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2587 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
2588 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
2589 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2590 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2591 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
2592 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2593
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2594 PyDoc_STRVAR(getservbyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2595 "getservbyname(servicename, protocolname) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2596 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2597 Return a port number from a service name and protocol name.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2598 The protocol name should be 'tcp' or 'udp'.");
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2599
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2600
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2601 /* Python interface to getprotobyname(name).
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2602 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
2603 already known or not useful (like the list of aliases). */
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2604
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2605 /*ARGSUSED*/
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2606 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
2607 socket_getprotobyname(PyObject *self, PyObject *args)
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2608 {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2609 char *name;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2610 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
2611 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2612 /* 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
2613 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
2614 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2615 #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
2616 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2617 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2618 Py_BEGIN_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2619 sp = getprotobyname(name);
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2620 Py_END_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2621 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
2622 PyErr_SetString(socket_error, "protocol not found");
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2623 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2624 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2625 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
2626 #endif
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2627 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2628
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2629 PyDoc_STRVAR(getprotobyname_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2630 "getprotobyname(name) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2631 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2632 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
2633
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2634
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2635 #ifndef NO_DUP
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2636 /* 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
2637 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
2638 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
2639
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2640 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2641 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
2642 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
2643 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2644 PySocketSockObject *s;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2645 SOCKET_T fd;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2646 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
2647 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
2648 &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
2649 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
2650 /* 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
2651 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
2652 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
2653 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
2654 s = new_sockobject(fd, family, type, proto);
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2655 /* From now on, ignore SIGPIPE and let the error checking
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2656 do the work. */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2657 #ifdef SIGPIPE
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2658 (void) signal(SIGPIPE, SIG_IGN);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2659 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2660 return (PyObject *) s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2661 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2662
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2663 PyDoc_STRVAR(fromfd_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2664 "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
2665 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2666 Create a socket object from the given file descriptor.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2667 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
2668
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2669 #endif /* NO_DUP */
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2670
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2671
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2672 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
2673 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
2674 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2675 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2676
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2677 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
2678 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2679 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2680 x2 = (int)ntohs((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2681 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2682 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2683
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2684 PyDoc_STRVAR(ntohs_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2685 "ntohs(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2686 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2687 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
2688
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2689
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2690 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2691 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
2692 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2693 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2694
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2695 if (PyInt_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2696 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
2697 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
2698 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2699 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2700 else if (PyLong_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2701 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
2702 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
2703 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2704 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2705 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2706 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2707 /* 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
2708 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2709 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2710 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2711 "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
2712 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
2713 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2714 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2715 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2716 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
2717 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
2718 "expected int/long, %s found",
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2719 arg->ob_type->tp_name);
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2720 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
2721 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2722 return PyInt_FromLong(ntohl(x));
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2723 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2724
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2725 PyDoc_STRVAR(ntohl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2726 "ntohl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2727 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2728 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
2729
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2730
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2731 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
2732 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
2733 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2734 unsigned long x1, x2;
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2735
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2736 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
2737 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2738 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2739 x2 = (int)htons((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2740 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2741 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2742
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2743 PyDoc_STRVAR(htons_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2744 "htons(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2745 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2746 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
2747
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2748
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2749 static PyObject *
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2750 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
2751 {
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2752 unsigned long x;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2753
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2754 if (PyInt_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2755 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
2756 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
2757 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2758 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2759 else if (PyLong_Check(arg)) {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2760 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
2761 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
2762 return NULL;
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2763 #if SIZEOF_LONG > 4
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2764 {
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2765 unsigned long y;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2766 /* 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
2767 y = x & 0xFFFFFFFFUL;
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2768 if (y ^ x)
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2769 return PyErr_Format(PyExc_OverflowError,
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2770 "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
2771 x = y;
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
2772 }
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2773 #endif
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2774 }
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2775 else
24619
b64db550972c internal_connect(): Windows. When sock_timeout > 0 and connect() yields
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
2776 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
2777 "expected int/long, %s found",
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2778 arg->ob_type->tp_name);
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
2779 return PyInt_FromLong(htonl(x));
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2780 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2781
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2782 PyDoc_STRVAR(htonl_doc,
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2783 "htonl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2784 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2785 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
2786
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
2787 /* 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
2788
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2789 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
2790 "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
2791 \n\
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2792 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
2793 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
2794
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2795 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
2796 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
2797 {
11268
3fe8d13328c8 It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents: 11219
diff changeset
2798 #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
2799 #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
2800 #endif
27858
9453d8cdd01e Ummm, try to get it right this time
Neal Norwitz <nnorwitz@gmail.com>
parents: 27857
diff changeset
2801 #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
2802 struct in_addr buf;
27861
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2803 #else
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2804 /* 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
2805 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
2806 #endif
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2807 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
2808
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2809 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
2810 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
2811
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2812
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2813 #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
2814 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
2815 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
2816 sizeof(buf));
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2817
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2818 PyErr_SetString(socket_error,
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2819 "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
2820 return NULL;
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2821
27861
f8440bb8ede5 socket_inet_aton(): ip_addr was left undefined before use in the
Tim Peters <tim.peters@gmail.com>
parents: 27858
diff changeset
2822 #else /* ! HAVE_INET_ATON */
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2823 /* XXX Problem here: inet_aton('255.255.255.255') raises
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2824 an exception while it should be a valid address. */
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2825 packed_addr = inet_addr(ip_addr);
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2826
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2827 if (packed_addr == INADDR_NONE) { /* invalid address */
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
2828 PyErr_SetString(socket_error,
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2829 "illegal IP address string passed to inet_aton");
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2830 return NULL;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2831 }
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2832 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
2833 sizeof(packed_addr));
27854
81afca747caa Addressing SF bug #643005, implement socket.inet_aton() using
Guido van Rossum <guido@python.org>
parents: 27558
diff changeset
2834 #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
2835 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2836
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2837 PyDoc_STRVAR(inet_ntoa_doc,
11937
ef98ee6aeb42 Fixed inet_ntoa() docstring.
Fred Drake <fdrake@acm.org>
parents: 11882
diff changeset
2838 "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
2839 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
2840 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
2841
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2842 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
2843 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
2844 {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2845 char *packed_str;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2846 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
2847 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
2848
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2849 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
2850 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
2851 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2852
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2853 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
2854 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
2855 "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
2856 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
2857 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2858
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2859 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
2860
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2861 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
2862 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2863
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2864 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2865
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2866 PyDoc_STRVAR(inet_pton_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2867 "inet_pton(af, ip) -> packed IP address string\n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2868 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2869 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
2870 for use with low-level network functions.");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2871
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2872 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2873 socket_inet_pton(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2874 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2875 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2876 char* ip;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2877 int retval;
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2878 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2879 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
2880 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2881 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
2882 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2883 if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2884 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2885 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2886
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2887 retval = inet_pton(af, ip, packed);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2888 if (retval < 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2889 PyErr_SetFromErrno(socket_error);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2890 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2891 } else if (retval == 0) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2892 PyErr_SetString(socket_error,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2893 "illegal IP address string passed to inet_pton");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2894 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2895 } else if (af == AF_INET) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2896 return PyString_FromStringAndSize(packed,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2897 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
2898 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2899 } else if (af == AF_INET6) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2900 return PyString_FromStringAndSize(packed,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2901 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
2902 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2903 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2904 PyErr_SetString(socket_error, "unknown address family");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2905 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2906 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2907 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2908
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2909 PyDoc_STRVAR(inet_ntop_doc,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2910 "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
2911 \n\
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2912 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
2913
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2914 static PyObject *
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2915 socket_inet_ntop(PyObject *self, PyObject *args)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2916 {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2917 int af;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2918 char* packed;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2919 int len;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2920 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
2921 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2922 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
2923 #else
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2924 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
2925 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2926
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2927 /* Guarantee NUL-termination for PyString_FromString() below */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2928 memset((void *) &ip[0], '\0', sizeof(ip) + 1);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2929
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2930 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
2931 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2932 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2933
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2934 if (af == AF_INET) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2935 if (len != sizeof(struct in_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2936 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2937 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2938 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2939 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2940 #ifdef ENABLE_IPV6
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2941 } else if (af == AF_INET6) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2942 if (len != sizeof(struct in6_addr)) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2943 PyErr_SetString(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2944 "invalid length of packed IP address string");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2945 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2946 }
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
2947 #endif
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2948 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2949 PyErr_Format(PyExc_ValueError,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2950 "unknown address family %d", af);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2951 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2952 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2953
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2954 retval = inet_ntop(af, packed, ip, sizeof(ip));
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2955 if (!retval) {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2956 PyErr_SetFromErrno(socket_error);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2957 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2958 } else {
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2959 return PyString_FromString(retval);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2960 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2961
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2962 /* NOTREACHED */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2963 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop");
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2964 return NULL;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2965 }
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2966
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2967 #endif /* HAVE_INET_PTON */
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
2968
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2969 /* 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
2970
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2971 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2972 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
2973 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
2974 {
20912
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
2975 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
2976 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
2977 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
2978 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
2979 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
2980 char *hptr, *pptr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2981 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
2982 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2983 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
2984 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
2985 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
2986
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2987 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
2988 family = AF_UNSPEC;
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2989 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
2990 &hobj, &pobj, &family, &socktype,
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2991 &protocol, &flags)) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2992 return NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2993 }
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2994 if (hobj == Py_None) {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2995 hptr = NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2996 } 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
2997 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
2998 if (!idna)
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
2999 return NULL;
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3000 hptr = PyString_AsString(idna);
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3001 } 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
3002 hptr = PyString_AsString(hobj);
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3003 } else {
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3004 PyErr_SetString(PyExc_TypeError,
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3005 "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
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 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3008 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
3009 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
3010 pptr = pbuf;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3011 } 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
3012 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
3013 } 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
3014 pptr = (char *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3015 } else {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3016 PyErr_SetString(socket_error, "Int or String expected");
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3017 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3018 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3019 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
3020 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
3021 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
3022 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
3023 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
3024 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3025 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
3026 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
3027 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3028 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
3029 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
3030 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
3031 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3032 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3033
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3034 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
3035 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3036 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
3037 PyObject *addr =
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3038 makesockaddr(-1, res->ai_addr, res->ai_addrlen);
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3039 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
3040 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3041 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
3042 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
3043 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
3044 addr);
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
3045 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
3046 if (single == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3047 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3048
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3049 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
3050 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3051 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3052 }
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3053 Py_XDECREF(idna);
24687
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3054 if (res0)
8b470281645e SF bug #592645 fix memory leak in socket.getaddrinfo
Neal Norwitz <nnorwitz@gmail.com>
parents: 24677
diff changeset
3055 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3056 return all;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3057 err:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3058 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3059 Py_XDECREF(all);
28671
d41d8de9768f Implement IDNA (Internationalized Domain Names in Applications).
Martin v. Löwis <martin@v.loewis.de>
parents: 28437
diff changeset
3060 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
3061 if (res0)
06d95b6877c4 Fix memory leaks detecting in bug report #478003.
Martin v. Löwis <martin@v.loewis.de>
parents: 20871
diff changeset
3062 freeaddrinfo(res0);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3063 return (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3064 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3065
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3066 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
3067 "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
3068 -> 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
3069 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3070 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
3071
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3072 /* 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
3073
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3074 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3075 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
3076 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
3077 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3078 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
3079 int flags;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3080 char *hostp;
20853
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20756
diff changeset
3081 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
3082 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
3083 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
3084 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3085 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
3086
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3087 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
3088 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
3089 return NULL;
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3090 if (!PyArg_ParseTuple(sa, "si|ii",
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3091 &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
3092 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
3093 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
3094 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
3095 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
3096 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
3097 Py_BEGIN_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3098 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
3099 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
3100 Py_END_ALLOW_THREADS
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
3101 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
3102 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
3103 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
3104 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3105 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3106 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
3107 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
3108 "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
3109 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3110 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3111 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
3112 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3113 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3114 char *t1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3115 int t2;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3116 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
3117 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
3118 "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
3119 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3120 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3121 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3122 }
21128
15ff504632ed Remove INET6 define. Use ENABLE_IPV6 instead.
Martin v. Löwis <martin@v.loewis.de>
parents: 21094
diff changeset
3123 #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
3124 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3125 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3126 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
3127 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
3128 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
3129 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
3130 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3131 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3132 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3133 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3134 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
3135 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
3136 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
3137 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
3138 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3139 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3140 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
3141
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3142 fail:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3143 if (res)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3144 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3145 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3146 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3147
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3148 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
3149 "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
3150 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3151 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
3152
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3153
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3154 /* 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
3155
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3156 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3157 socket_getdefaulttimeout(PyObject *self)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3158 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3159 if (defaulttimeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3160 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3161 return Py_None;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3162 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3163 else
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3164 return PyFloat_FromDouble(defaulttimeout);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3165 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3166
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3167 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
3168 "getdefaulttimeout() -> timeout\n\
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3169 \n\
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3170 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
3171 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
3172 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
3173
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3174 static PyObject *
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3175 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
3176 {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3177 double timeout;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3178
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3179 if (arg == Py_None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3180 timeout = -1.0;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3181 else {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3182 timeout = PyFloat_AsDouble(arg);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3183 if (timeout < 0.0) {
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3184 if (!PyErr_Occurred())
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3185 PyErr_SetString(PyExc_ValueError,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3186 "Timeout value out of range");
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3187 return NULL;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3188 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3189 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3190
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3191 defaulttimeout = timeout;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3192
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3193 Py_INCREF(Py_None);
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3194 return Py_None;
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3195 }
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3196
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3197 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
3198 "setdefaulttimeout(timeout)\n\
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3199 \n\
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3200 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
3201 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
3202 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
3203
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3204
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3205 /* 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
3206
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3207 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
3208 {"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
3209 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
3210 {"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
3211 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
3212 {"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
3213 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
3214 {"gethostname", socket_gethostname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
3215 METH_VARARGS, 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
3216 {"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
3217 METH_VARARGS, getservbyname_doc},
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3218 {"getprotobyname", socket_getprotobyname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
3219 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
3220 #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
3221 {"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
3222 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
3223 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3224 {"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
3225 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
3226 {"ntohl", socket_ntohl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3227 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
3228 {"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
3229 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
3230 {"htonl", socket_htonl,
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24363
diff changeset
3231 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
3232 {"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
3233 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
3234 {"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
3235 METH_VARARGS, inet_ntoa_doc},
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3236 #ifdef HAVE_INET_PTON
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3237 {"inet_pton", socket_inet_pton,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3238 METH_VARARGS, inet_pton_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3239 {"inet_ntop", socket_inet_ntop,
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3240 METH_VARARGS, inet_ntop_doc},
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3241 #endif
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3242 {"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
3243 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
3244 {"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
3245 METH_VARARGS, getnameinfo_doc},
24303
93434bc0899d Silence warning about getdefaulttimeout in PyMethodDef.
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
3246 {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout,
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3247 METH_NOARGS, getdefaulttimeout_doc},
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3248 {"setdefaulttimeout", socket_setdefaulttimeout,
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 24280
diff changeset
3249 METH_O, setdefaulttimeout_doc},
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3250 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3251 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3252
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
3253
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3254 #ifdef RISCOS
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3255 #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
3256
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3257 static int
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3258 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
3259 {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3260 _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
3261
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3262 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
3263 _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
3264 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
3265
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 29037
diff changeset
3266 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
3267 }
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3268
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3269 #endif /* RISCOS */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3270
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3271
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
3272 #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
3273 #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
3274
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3275 /* 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
3276
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
3277 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
3278 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
3279 {
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
3280 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
3281 }
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
3282
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
3283 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
3284 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
3285 {
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
3286 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
3287 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
3288 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
3289 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
3290 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
3291 case 0: /* No error */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3292 atexit(os_cleanup);
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3293 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
3294 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
3295 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
3296 "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
3297 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
3298 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
3299 case WSAEINVAL:
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3300 PyErr_SetString(
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3301 PyExc_ImportError,
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3302 "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
3303 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
3304 default:
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21060
diff changeset
3305 PyOS_snprintf(buf, sizeof(buf),
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21060
diff changeset
3306 "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
3307 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
3308 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
3309 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3310 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
3311 }
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
3312
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
3313 #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
3314
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3315
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3316 #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
3317 #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
3318
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3319 /* Additional initialization for OS/2 */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3320
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3321 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
3322 os_init(void)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3323 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3324 #ifndef PYCC_GCC
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3325 char reason[64];
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3326 int rc = sock_init();
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3327
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3328 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
3329 return 1; /* Success */
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3330 }
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3331
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3332 PyOS_snprintf(reason, sizeof(reason),
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3333 "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
3334 PyErr_SetString(PyExc_ImportError, reason);
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3335
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3336 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
3337 #else
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3338 /* 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
3339 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
3340 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3341 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3342
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3343 #endif /* PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3344
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3345
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3346 #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
3347 static int
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3348 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
3349 {
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3350 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
3351 }
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3352 #endif
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3353
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3354
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
3355 /* 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
3356 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
3357 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
3358 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
3359 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3360 &sock_type,
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
3361 };
3957d155f8c5 Break SSL support out of _socket module and place it into a new
Marc-André Lemburg <mal@egenix.com>
parents: 21757
diff changeset
3362
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3363
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3364 /* 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
3365
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3366 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
3367 "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
3368 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
3369 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
3370 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
3371 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
3372 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
3373 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
3374 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
3375 */
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3376
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23818
diff changeset
3377 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
3378 "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
3379 \n\
980767c6cd97 Clean up some docstrings. Some docstrings didn't show their return
Guido van Rossum <guido@python.org>
parents: 24619
diff changeset
3380 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
3381
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24411
diff changeset
3382 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
3383 init_socket(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3384 {
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3385 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
3386
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3387 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
3388 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3389
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3390 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
3391 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
3392 socket_methods,
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3393 socket_doc);
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3394
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3395 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
3396 if (socket_error == NULL)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3397 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3398 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
3399 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
3400 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
3401 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
3402 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
3403 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3404 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
3405 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
3406 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
3407 NULL);
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3408 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
3409 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3410 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
3411 PyModule_AddObject(m, "gaierror", socket_gaierror);
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3412 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
3413 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
3414 (PyObject *)&sock_type) != 0)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3415 return;
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
3416 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
3417 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
3418 (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
3419 return;
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3420
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3421 #ifdef ENABLE_IPV6
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3422 has_ipv6 = Py_True;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3423 #else
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3424 has_ipv6 = Py_False;
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3425 #endif
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3426 Py_INCREF(has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3427 PyModule_AddObject(m, "has_ipv6", has_ipv6);
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 28671
diff changeset
3428
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
3429 /* 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
3430 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
3431 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
3432 ) != 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
3433 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
3434
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3435 /* 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
3436 #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
3437 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
3438 #endif
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3439 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
3440 #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
3441 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
3442 #endif /* AF_INET6 */
27019
9ee4fd05d3cb OS/2 sockets do not support AF_UNIX, even though EMX headers define it
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26597
diff changeset
3443 #if defined(AF_UNIX) && !defined(PYOS_OS2)
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3444 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
3445 #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
3446 #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
3447 /* 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
3448 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
3449 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3450 #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
3451 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
3452 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3453 #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
3454 /* Appletalk DDP */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3455 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
3456 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3457 #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
3458 /* Amateur radio NetROM */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3459 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
3460 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3461 #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
3462 /* Multiprotocol bridge */
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3463 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
3464 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3465 #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
3466 /* 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
3467 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
3468 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3469 #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
3470 /* 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
3471 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
3472 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3473 #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
3474 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
3475 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3476 #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
3477 /* 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
3478 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
3479 #endif
19151
cd44254360b6 Autotest for netpacket/packet.h, as it is not available on all Linux versions.
Martin v. Löwis <martin@v.loewis.de>
parents: 18997
diff changeset
3480 #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
3481 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
3482 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
3483 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
3484 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
3485 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
3486 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
3487 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
3488 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
3489 PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3490 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3491
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3492 /* Socket types */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3493 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
3494 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
3495 #ifndef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3496 /* 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
3497 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
3498 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
3499 #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
3500 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
3501 #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
3502 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3503
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3504 #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
3505 PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3506 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3507 #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
3508 PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3509 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3510 #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
3511 PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3512 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3513 #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
3514 PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3515 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3516 #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
3517 PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3518 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3519 #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
3520 PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3521 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3522 #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
3523 PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3524 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3525 #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
3526 PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3527 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3528 #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
3529 PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3530 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3531 #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
3532 PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3533 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3534 #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
3535 PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3536 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3537 #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
3538 PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3539 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3540 #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
3541 PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3542 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3543 #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
3544 PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3545 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3546 #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
3547 PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3548 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3549 #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
3550 PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3551 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3552 #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
3553 PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3554 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3555 #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
3556 PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3557 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3558
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3559 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3560 #ifdef SOMAXCONN
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3561 PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3562 #else
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
3563 PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3564 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3565
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3566 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3567 #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
3568 PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3569 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3570 #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
3571 PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3572 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3573 #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
3574 PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3575 #endif
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
3576 #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
3577 PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT);
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
3578 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3579 #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
3580 PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3581 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3582 #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
3583 PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3584 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3585 #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
3586 PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3587 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3588 #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
3589 PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3590 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3591 #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
3592 PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3593 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3594 #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
3595 PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3596 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3597
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3598 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3599 #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
3600 PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3601 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3602 #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
3603 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
3604 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3605 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
3606 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3607 #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
3608 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
3609 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3610 #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
3611 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
3612 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3613 #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
3614 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
3615 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3616 #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
3617 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
3618 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3619 #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
3620 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
3621 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3622 #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
3623 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
3624 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3625 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
3626 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3627 #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
3628 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
3629 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3630 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
3631 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3632 #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
3633 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
3634 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3635 PyModule_AddIntConstant(m, "IPPROTO_IP", 0);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3636 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3637 #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
3638 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
3639 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3640 #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
3641 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
3642 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3643 PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3644 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3645 #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
3646 PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3647 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3648 #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
3649 PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3650 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3651 #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
3652 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
3653 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3654 #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
3655 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
3656 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3657 #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
3658 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
3659 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3660 PyModule_AddIntConstant(m, "IPPROTO_TCP", 6);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3661 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3662 #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
3663 PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3664 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3665 #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
3666 PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3667 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3668 #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
3669 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
3670 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3671 PyModule_AddIntConstant(m, "IPPROTO_UDP", 17);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3672 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3673 #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
3674 PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3675 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3676 #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
3677 PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3678 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3679 #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
3680 PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3681 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3682 #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
3683 PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3684 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3685 #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
3686 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
3687 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3688 #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
3689 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
3690 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3691 #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
3692 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
3693 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3694 #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
3695 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
3696 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3697 #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
3698 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
3699 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3700 #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
3701 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
3702 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3703 #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
3704 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
3705 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3706 #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
3707 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
3708 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3709 #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
3710 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
3711 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3712 #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
3713 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
3714 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3715 #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
3716 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
3717 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3718 #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
3719 PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3720 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3721 #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
3722 PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3723 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3724 #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
3725 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
3726 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3727 #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
3728 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
3729 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3730 #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
3731 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
3732 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3733 #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
3734 PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3735 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3736 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3737 #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
3738 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
3739 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3740 PyModule_AddIntConstant(m, "IPPROTO_RAW", 255);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3741 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3742 #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
3743 PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3744 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3745
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3746 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3747 #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
3748 PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3749 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3750 PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3751 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3752 #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
3753 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3754 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3755 PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3756 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3757
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3758 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3759 #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
3760 PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3761 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3762 PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3763 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3764 #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
3765 PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3766 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3767 PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3768 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3769 #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
3770 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3771 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3772 PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3773 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3774 #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
3775 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3776 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3777 PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3778 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3779 #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
3780 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
3781 INADDR_ALLHOSTS_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3782 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3783 PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3784 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3785 #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
3786 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
3787 INADDR_MAX_LOCAL_GROUP);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3788 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3789 PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3790 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3791 #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
3792 PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3793 #else
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 22568
diff changeset
3794 PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff);
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3795 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3796
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3797 /* IPv4 [gs]etsockopt options */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3798 #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
3799 PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3800 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3801 #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
3802 PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3803 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3804 #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
3805 PyModule_AddIntConstant(m, "IP_TOS", IP_TOS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3806 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3807 #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
3808 PyModule_AddIntConstant(m, "IP_TTL", IP_TTL);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3809 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3810 #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
3811 PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3812 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3813 #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
3814 PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3815 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3816 #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
3817 PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3818 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3819 #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
3820 PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3821 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3822 #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
3823 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
3824 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3825 #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
3826 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
3827 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3828 #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
3829 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
3830 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3831 #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
3832 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
3833 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3834 #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
3835 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
3836 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3837 #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
3838 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
3839 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
3840 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3841 #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
3842 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
3843 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
3844 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3845 #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
3846 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
3847 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3848
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3849 /* 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
3850 #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
3851 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
3852 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3853 #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
3854 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
3855 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3856 #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
3857 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
3858 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3859 #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
3860 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
3861 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3862 #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
3863 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
3864 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3865 #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
3866 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
3867 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3868
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3869 /* TCP options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3870 #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
3871 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
3872 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3873 #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
3874 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
3875 #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
3876 #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
3877 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
3878 #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
3879 #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
3880 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
3881 #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
3882 #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
3883 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
3884 #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
3885 #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
3886 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
3887 #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
3888 #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
3889 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
3890 #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
3891 #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
3892 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
3893 #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
3894 #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
3895 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
3896 #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
3897 #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
3898 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
3899 #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
3900 #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
3901 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
3902 #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
3903 #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
3904 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
3905 #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
3906
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3907
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3908 /* IPX options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3909 #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
3910 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
3911 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3912
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3913 /* 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
3914 #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
3915 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
3916 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3917 #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
3918 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
3919 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3920 #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
3921 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
3922 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3923 #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
3924 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
3925 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3926 #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
3927 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
3928 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3929 #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
3930 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
3931 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3932 #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
3933 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
3934 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3935 #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
3936 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
3937 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3938 #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
3939 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
3940 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3941 #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
3942 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
3943 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3944 #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
3945 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
3946 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3947 #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
3948 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
3949 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3950 #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
3951 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
3952 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3953 #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
3954 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
3955 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3956 #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
3957 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
3958 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3959 #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
3960 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
3961 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3962 #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
3963 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
3964 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3965 #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
3966 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
3967 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3968 #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
3969 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
3970 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3971 #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
3972 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
3973 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3974 #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
3975 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
3976 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3977 #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
3978 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
3979 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3980 #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
3981 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
3982 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3983 #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
3984 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
3985 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3986 #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
3987 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
3988 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3989 #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
3990 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
3991 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3992 #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
3993 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
3994 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3995 #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
3996 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
3997 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3998 #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
3999 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
4000 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4001 #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
4002 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
4003 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
4004
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
4005 /* Initialize gethostbyname lock */
29035
e1d5ca8ab7dc [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
Just van Rossum <just@letterror.com>
parents: 28953
diff changeset
4006 #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
4007 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
4008 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4009 }
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
4010
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4011
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4012 #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
4013
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
4014 /* 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
4015 /* 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
4016
23723
2f6f8708e3e9 Whitespace normalization, folding long lines, uniform comment
Guido van Rossum <guido@python.org>
parents: 23722
diff changeset
4017 int
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4018 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
4019 {
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4020 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
4021 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
4022 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
4023 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
4024 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
4025 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
4026 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
4027 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
4028 /* 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
4029 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
4030 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
4031
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
4032 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
4033 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
4034 {
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
4035 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
4036 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
4037 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
4038 /* 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
4039 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
4040 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
4041 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
4042 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
4043 /* 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
4044 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
4045 }
23725
1235a95fedcd Major cleanup. Renamed static methods to avoid Py prefix. Other misc
Guido van Rossum <guido@python.org>
parents: 23723
diff changeset
4046
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
4047 #endif