annotate Modules/socketmodule.c @ 20661:f7009167dd67 legacy-trunk

After discussion with itojun, it was clarified that Tru64 is in error, and that the work-around should be restricted to that system.
author Martin v. Löwis <martin@v.loewis.de>
date Thu, 25 Oct 2001 09:04:03 +0000
parents edd9d0b3c47e
children e89c25ca6b29
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
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3 /* SSL support based on patches by Brian E Gallew and Laszlo Kovacs */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
4
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 /*
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 This module provides an interface to Berkeley socket IPC.
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 Limitations:
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
10 - 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
11 portable manner, though AF_PACKET is supported under Linux.
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
12 - no read/write operations (use send/recv or makefile instead)
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
13 - additional restrictions apply on Windows
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
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
22 - 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
23 - 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
24 - 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
25 - socket.getprotobyname(protocolname) --> protocol number
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
26 - socket.getservbyname(servicename, protocolname) --> port number
309
382323f92fce Connection sockets now have the proper family/type/proto values.
Guido van Rossum <guido@python.org>
parents: 295
diff changeset
27 - 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
28 - 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
29 - 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
30 - 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
31 - 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
32 - 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
33 --> 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
34 - socket.getnameinfo(sockaddr, flags) --> (host, port)
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
35 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h>
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
36 - 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
37 - socket.inet_ntoa(packed IP) -> IP address string
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
38 - socket.ssl(socket, keyfile, certfile) -> new ssl object
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 - an Internet socket address is a pair (hostname, port)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 where hostname can be anything recognized by gethostbyname()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 (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
42 - 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
43 - 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
44 - 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
45 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
46 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
47 ("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
48 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
49 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
50 getsockname() method.
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
52 Socket methods:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
54 - s.accept() --> new socket object, sockaddr
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
55 - s.bind(sockaddr) --> None
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
56 - s.close() --> None
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
57 - s.connect(sockaddr) --> None
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
58 - s.connect_ex(sockaddr) --> 0 or errno (handy for e.g. async connect)
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
59 - s.fileno() --> file descriptor
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
60 - s.dup() --> same as socket.fromfd(os.dup(s.fileno(), ...)
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
61 - s.getpeername() --> sockaddr
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
62 - s.getsockname() --> sockaddr
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
63 - s.getsockopt(level, optname[, buflen]) --> int or string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
64 - s.listen(backlog) --> None
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
65 - s.makefile([mode[, bufsize]]) --> file object
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
66 - s.recv(buflen [,flags]) --> string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
67 - s.recvfrom(buflen [,flags]) --> string, sockaddr
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
68 - s.send(string [,flags]) --> nbytes
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
69 - s.sendto(string, [flags,] sockaddr) --> nbytes
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
70 - s.setblocking(0 | 1) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
71 - s.setsockopt(level, optname, value) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
72 - s.shutdown(how) --> None
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
73 - repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>"
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
74
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
77 #include "Python.h"
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
78
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
79 /* 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
80 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
81 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
82 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
83
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
84 #ifndef linux
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
85 #undef HAVE_GETHOSTBYNAME_R_3_ARG
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
86 #undef HAVE_GETHOSTBYNAME_R_5_ARG
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
87 #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
88 #endif
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
89
10579
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
90 #ifndef WITH_THREAD
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
91 #undef HAVE_GETHOSTBYNAME_R
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
92 #endif
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
93
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
94 #ifdef 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
95 #if defined(_AIX) || defined(__osf__)
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
96 #define HAVE_GETHOSTBYNAME_R_3_ARG
20412
698bf7c22bfe Test for __sun instead of __sun__, since SUNWspro only defines the latter;
Martin v. Löwis <martin@v.loewis.de>
parents: 20389
diff changeset
97 #elif defined(__sun) || defined(__sgi)
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
98 #define HAVE_GETHOSTBYNAME_R_5_ARG
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
99 #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
100 /* Rely on the configure script */
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
101 #else
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
102 #undef HAVE_GETHOSTBYNAME_R
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
103 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
104 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
105
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
106 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS)
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
107 #define USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
108 #endif
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
109
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
110 #ifdef USE_GETHOSTBYNAME_LOCK
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9095
diff changeset
111 #include "pythread.h"
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
112 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
114 #ifdef HAVE_UNISTD_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
115 #include <unistd.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
116 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
117
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
118 #if defined(PYCC_VACPP)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
119 #include <types.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
120 #include <io.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
121 #include <sys/ioctl.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
122 #include <utils.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
123 #include <ctype.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
124 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
125
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
126 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
127 #define INCL_DOS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
128 #define INCL_DOSERRORS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
129 #define INCL_NOPMAPI
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
130 #include <os2.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
131 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
132
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
133
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
134 #include <sys/types.h>
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
135
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
136 #include <signal.h>
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
137 #ifndef MS_WINDOWS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
138 #include <netdb.h>
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 #include <sys/socket.h>
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 #include <netinet/in.h>
15046
c654b2018403 Norman Vine <nhv@users.sourceforge.net>:
Fred Drake <fdrake@acm.org>
parents: 14008
diff changeset
141 #if !(defined(__BEOS__) || defined(__CYGWIN__))
12194
4dd8b6a3b9c5 Add '#include <netinet/tcp.h>'
Andrew M. Kuchling <amk@amk.ca>
parents: 12050
diff changeset
142 #include <netinet/tcp.h>
12712
be55f5ddc615 Donn Cave <donn@oz.net>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
143 #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
144
11288
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
145 /* Headers needed for inet_ntoa() and inet_addr() */
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
146 #ifdef __BEOS__
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
147 #include <net/netdb.h>
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
148 #else
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
149 #ifndef USE_GUSI1
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
150 #include <arpa/inet.h>
11288
adf87d13a0c1 (1) On Linux, we really need to trust the configure script to select
Guido van Rossum <guido@python.org>
parents: 11268
diff changeset
151 #endif
11438
be25aaca11f4 Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents: 11288
diff changeset
152 #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
153
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
154 #ifndef RISCOS
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
155 #include <fcntl.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
156 #else
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
157 #include <sys/fcntl.h>
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
158 #define NO_DUP
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
159 int h_errno; /* not used */
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
160 #endif
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
161 #else
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
162 #include <winsock.h>
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
163 #include <fcntl.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
164 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
165
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
166
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
167 #ifdef HAVE_SYS_UN_H
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 #include <sys/un.h>
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
169 #else
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
170 #undef AF_UNIX
1271
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
171 #endif
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
172
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
173 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
174 #include <sys/ioctl.h>
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
175 #include <net/if.h>
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
176 #include <netpacket/packet.h>
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
177 #endif
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
178
18263
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
179 #ifdef HAVE_STDDEF_H
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
180 #include <stddef.h>
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
181 #endif
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
182
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
183 #ifndef offsetof
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
184 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
185 #endif
41491d196748 Provide a definition for offsetof.
Martin v. Löwis <martin@v.loewis.de>
parents: 18262
diff changeset
186
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
187 #ifndef O_NDELAY
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
188 #define O_NDELAY O_NONBLOCK /* For QNX only? */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
189 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
190
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
191 #ifdef USE_GUSI1
3390
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
192 /* fdopen() isn't declared in stdio.h (sigh) */
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
193 #include <GUSI.h>
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
194 #endif
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
195
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
196 #include "addrinfo.h"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
197
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
198 #ifdef USE_SSL
15994
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
199 #include "openssl/rsa.h"
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
200 #include "openssl/crypto.h"
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
201 #include "openssl/x509.h"
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
202 #include "openssl/pem.h"
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
203 #include "openssl/ssl.h"
f9a15a583c79 Use openssl/*.h to include the OpenSSL header files
Andrew M. Kuchling <amk@amk.ca>
parents: 15604
diff changeset
204 #include "openssl/err.h"
20505
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
205 #include "openssl/rand.h"
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
206 #endif /* USE_SSL */
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
207
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
208 #ifndef HAVE_INET_PTON
18790
7cd22bf56d7b Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents: 18753
diff changeset
209 int inet_pton (int af, const char *src, void *dst);
7cd22bf56d7b Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents: 18753
diff changeset
210 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
211 #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
212
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
213 #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
214 /* 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
215 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
216 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
217 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
218 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
219 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
220 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
221 appropriate, which is 10/0 on the system with the bug. */
fefcc1e80cee Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents: 18915
diff changeset
222 #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
223 /* avoid clashes with the C library definition of the symbol. */
fefcc1e80cee Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents: 18915
diff changeset
224 #define getaddrinfo fake_getaddrinfo
fefcc1e80cee Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents: 18915
diff changeset
225 #endif
fefcc1e80cee Do not use the system getaddrinfo on Mac OS X. Fixes bug #445928.
Martin v. Löwis <martin@v.loewis.de>
parents: 18915
diff changeset
226
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
227 /* 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
228 #if !defined(HAVE_GETADDRINFO)
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
229 #include "getaddrinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
230 #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
231 #if !defined(HAVE_GETNAMEINFO)
18246
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
232 #include "getnameinfo.c"
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
233 #endif
c4db09b87424 Patch #401196: Configuration machinery for IPv6.
Martin v. Löwis <martin@v.loewis.de>
parents: 17806
diff changeset
234
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
235 #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
236 /* 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
237 /* 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
238 #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
239 #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
240 #endif
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
241
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
242 /* abstract the socket file descriptor type */
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
243 #ifdef MS_WINDOWS
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
244 typedef SOCKET SOCKET_T;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
245 # ifdef MS_WIN64
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
246 # define SIZEOF_SOCKET_T 8
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
247 # else
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
248 # define SIZEOF_SOCKET_T 4
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
249 # endif
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
250 #else
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
251 typedef int SOCKET_T;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
252 # define SIZEOF_SOCKET_T SIZEOF_INT
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
253 #endif
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
254
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
255 #ifdef MS_WIN32
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
256 # define EAFNOSUPPORT WSAEAFNOSUPPORT
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
257 # define snprintf _snprintf
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
258 #endif
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
259
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
260 #if defined(PYOS_OS2)
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
261 #define SOCKETCLOSE soclose
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
262 #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
263 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
264
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
265 #ifndef SOCKETCLOSE
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
266 #define SOCKETCLOSE close
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
267 #endif
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
268
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
269 /* 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
270 by this module (but not argument type or memory errors, etc.). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
271
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
272 static PyObject *PySocket_Error;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
273 static PyObject *PyH_Error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
274 static PyObject *PyGAI_Error;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
275
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
276 #ifdef USE_SSL
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
277 static PyObject *PySSLErrorObject;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
278 #endif /* USE_SSL */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
279
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
280
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
281 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
282 /* 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
283 static int taskwindow;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
284 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
285
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
286
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
287 /* 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
288 and return a NULL pointer from a function. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
290 static PyObject *
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13554
diff changeset
291 PySocket_Err(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
293 #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
294 int err_no = WSAGetLastError();
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
295 if (err_no) {
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
296 static struct { int no; const char *msg; } *msgp, msgs[] = {
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
297 { WSAEINTR, "Interrupted system call" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
298 { WSAEBADF, "Bad file descriptor" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
299 { WSAEACCES, "Permission denied" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
300 { WSAEFAULT, "Bad address" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
301 { WSAEINVAL, "Invalid argument" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
302 { WSAEMFILE, "Too many open files" },
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
303 { WSAEWOULDBLOCK,
13680
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
304 "The socket operation could not complete "
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
305 "without blocking" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
306 { WSAEINPROGRESS, "Operation now in progress" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
307 { WSAEALREADY, "Operation already in progress" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
308 { WSAENOTSOCK, "Socket operation on non-socket" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
309 { WSAEDESTADDRREQ, "Destination address required" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
310 { WSAEMSGSIZE, "Message too long" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
311 { WSAEPROTOTYPE, "Protocol wrong type for socket" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
312 { WSAENOPROTOOPT, "Protocol not available" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
313 { WSAEPROTONOSUPPORT, "Protocol not supported" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
314 { WSAESOCKTNOSUPPORT, "Socket type not supported" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
315 { WSAEOPNOTSUPP, "Operation not supported" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
316 { WSAEPFNOSUPPORT, "Protocol family not supported" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
317 { WSAEAFNOSUPPORT, "Address family not supported" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
318 { WSAEADDRINUSE, "Address already in use" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
319 { WSAEADDRNOTAVAIL,
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
320 "Can't assign requested address" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
321 { WSAENETDOWN, "Network is down" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
322 { WSAENETUNREACH, "Network is unreachable" },
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
323 { WSAENETRESET,
13680
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
324 "Network dropped connection on reset" },
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
325 { WSAECONNABORTED,
13680
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
326 "Software caused connection abort" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
327 { WSAECONNRESET, "Connection reset by peer" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
328 { WSAENOBUFS, "No buffer space available" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
329 { WSAEISCONN, "Socket is already connected" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
330 { WSAENOTCONN, "Socket is not connected" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
331 { WSAESHUTDOWN, "Can't send after socket shutdown" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
332 { WSAETOOMANYREFS,
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
333 "Too many references: can't splice" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
334 { WSAETIMEDOUT, "Operation timed out" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
335 { WSAECONNREFUSED, "Connection refused" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
336 { WSAELOOP, "Too many levels of symbolic links" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
337 { WSAENAMETOOLONG, "File name too long" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
338 { WSAEHOSTDOWN, "Host is down" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
339 { WSAEHOSTUNREACH, "No route to host" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
340 { WSAENOTEMPTY, "Directory not empty" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
341 { WSAEPROCLIM, "Too many processes" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
342 { WSAEUSERS, "Too many users" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
343 { WSAEDQUOT, "Disc quota exceeded" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
344 { WSAESTALE, "Stale NFS file handle" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
345 { WSAEREMOTE, "Too many levels of remote in path" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
346 { WSASYSNOTREADY,
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
347 "Network subsystem is unvailable" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
348 { WSAVERNOTSUPPORTED,
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
349 "WinSock version is not supported" },
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
350 { WSANOTINITIALISED,
13680
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
351 "Successful WSAStartup() not yet performed" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
352 { WSAEDISCON, "Graceful shutdown in progress" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
353 /* Resolver errors */
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
354 { WSAHOST_NOT_FOUND, "No such host is known" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
355 { WSATRY_AGAIN, "Host not found, or server failed" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
356 { WSANO_RECOVERY,
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
357 "Unexpected server error encountered" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
358 { WSANO_DATA, "Valid name without requested data" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
359 { WSANO_ADDRESS, "No address, look for MX record" },
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
360 { 0, NULL }
9f6189e89212 Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Mark Hammond <mhammond@skippinet.com.au>
parents: 13667
diff changeset
361 };
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
362 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
363 const char *msg = "winsock error";
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
364
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
365 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
366 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
367 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
368 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
369 }
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
370 }
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
371
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
372 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
373 if (v != NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
374 PyErr_SetObject(PySocket_Error, v);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
375 Py_DECREF(v);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
376 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
377 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
378 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
379 else
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
380 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
381
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
382 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
383 if (sock_errno() != NO_ERROR) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
384 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
385 ULONG msglen;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
386 char outbuf[100];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
387 int myerrorcode = sock_errno();
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
388
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
389 /* Retrieve Socket-Related Error Message from MPTN.MSG File */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
390 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
391 myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
392 if (rc == NO_ERROR) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
393 PyObject *v;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
394
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
395 outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
396 if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
397 char *lastc = &outbuf[ strlen(outbuf)-1 ];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
398 while (lastc > outbuf && isspace(*lastc))
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
399 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
400 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
401 v = Py_BuildValue("(is)", myerrorcode, outbuf);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
402 if (v != NULL) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
403 PyErr_SetObject(PySocket_Error, v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
404 Py_DECREF(v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
405 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
406 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
407 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
408 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
409 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
410
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
411 return PyErr_SetFromErrno(PySocket_Error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
413
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
414
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
415 static PyObject *
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
416 PyH_Err(int h_error)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
417 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
418 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
419
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
420 #ifdef HAVE_HSTRERROR
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
421 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
422 #else
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
423 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
424 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
425 if (v != NULL) {
18996
9059e7c1d8b0 Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the three
Martin v. Löwis <martin@v.loewis.de>
parents: 18954
diff changeset
426 PyErr_SetObject(PyH_Error, v);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
427 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
428 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
429
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
430 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
431 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
432
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
433
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
434 static PyObject *
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
435 PyGAI_Err(int error)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
436 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
437 PyObject *v;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
438
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
439 if (error == EAI_SYSTEM)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
440 return PySocket_Err();
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
441
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
442 #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
443 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
444 #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
445 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
446 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
447 if (v != NULL) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
448 PyErr_SetObject(PyGAI_Error, v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
449 Py_DECREF(v);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
450 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
451
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
452 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
453 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
454
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
455
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
456 /* The object holding a socket. It holds some extra information,
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
457 like the address family, which is used to decode socket address
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
458 arguments properly. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
459
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 typedef struct {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
461 PyObject_HEAD
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
462 SOCKET_T sock_fd; /* Socket file descriptor */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
463 int sock_family; /* Address family, e.g., AF_INET */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
464 int sock_type; /* Socket type, e.g., SOCK_STREAM */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
465 int sock_proto; /* Protocol type, usually 0 */
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
466 union sock_addr {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
467 struct sockaddr_in in;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
468 #ifdef AF_UNIX
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
469 struct sockaddr_un un;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
470 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
471 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
472 struct sockaddr_in6 in6;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
473 struct sockaddr_storage storage;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
474 #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
475 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
476 struct sockaddr_ll ll;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
477 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
478 } sock_addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
479 } PySocketSockObject;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
481 #ifdef USE_SSL
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
482
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
483 #define X509_NAME_MAXLEN 256
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
484
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
485 typedef struct {
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
486 PyObject_HEAD
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
487 PySocketSockObject *Socket; /* Socket on which we're layered */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
488 SSL_CTX* ctx;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
489 SSL* ssl;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
490 X509* server_cert;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
491 BIO* sbio;
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
492 char server[X509_NAME_MAXLEN];
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
493 char issuer[X509_NAME_MAXLEN];
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
494
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
495 } PySSLObject;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
496
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
497 staticforward PyTypeObject PySSL_Type;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
498 staticforward PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
499 staticforward PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
500
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
501 #define PySSLObject_Check(v) ((v)->ob_type == &PySSL_Type)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
502
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
503 #endif /* USE_SSL */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
504
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
505 /* A forward reference to the Socktype type object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
506 The Socktype variable contains pointers to various functions,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
507 some of which call newsockobject(), which uses Socktype, so
374
70a18a6689d4 Make Socktype global so old and new compilers will like it.
Guido van Rossum <guido@python.org>
parents: 324
diff changeset
508 there has to be a circular reference. */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
509
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
510 staticforward PyTypeObject PySocketSock_Type;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
511
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
512
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
513 /* Create a new socket object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
514 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
515 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
516 in NEWOBJ()). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
517
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
518 static PySocketSockObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
519 PySocketSock_New(SOCKET_T fd, int family, int type, int proto)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
520 {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
521 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
522 int block = 1;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
523 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
524 PySocketSockObject *s;
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
525 PySocketSock_Type.ob_type = &PyType_Type;
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12493
diff changeset
526 s = PyObject_New(PySocketSockObject, &PySocketSock_Type);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
527 if (s != NULL) {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
528 s->sock_fd = fd;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
529 s->sock_family = family;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 s->sock_type = type;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 s->sock_proto = proto;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
532 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
533 if(taskwindow) {
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
534 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
535 }
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
536 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
540
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
541
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
542 /* Lock to allow python interpreter to continue, but only allow one
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
543 thread to be in gethostbyname */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
544 #ifdef USE_GETHOSTBYNAME_LOCK
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
545 PyThread_type_lock gethostbyname_lock;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
546 #endif
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
547
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
548
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
549 /* 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
550 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
551 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
552 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
553 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
554
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 static int
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
556 setipaddr(char* name, struct sockaddr * addr_ret, int af)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
558 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
559 int error;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
560
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
561 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
562 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
563 int siz;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
564 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
565 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
566 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
567 hints.ai_flags = AI_PASSIVE;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
568 error = getaddrinfo(NULL, "0", &hints, &res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
569 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
570 PyGAI_Err(error);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
571 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
572 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
573 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
574 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
575 siz = 4;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
576 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
577 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
578 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
579 siz = 16;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
580 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
581 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
582 default:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
583 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
584 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
585 "unsupported address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
586 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
587 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
588 if (res->ai_next) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
589 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
590 "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
591 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
592 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
593 memcpy(addr_ret, res->ai_addr, res->ai_addrlen);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
594 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
595 return siz;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
597 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
598 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
599 if (af != PF_INET && af != PF_UNSPEC) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
600 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
601 "address family mismatched");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
602 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
603 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
604 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
605 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
606 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
607 #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
608 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
609 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
610 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
611 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
612 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
613 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
614 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
615 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
616 #if defined(__digital__) && defined(__unix__)
20648
fec950d8c25d Fix typo. Thanks to Jack Jansen for spotting it.
Martin v. Löwis <martin@v.loewis.de>
parents: 20646
diff changeset
617 if (error == EAI_NONAME && af == AF_UNSPEC) {
20661
f7009167dd67 After discussion with itojun, it was clarified that Tru64 is in error,
Martin v. Löwis <martin@v.loewis.de>
parents: 20654
diff changeset
618 /* On Tru64 V5.1, numeric-to-addr conversion
20646
cabb568a558b Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents: 20564
diff changeset
619 fails if no address family is given. Assume IPv4 for now.*/
cabb568a558b Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents: 20564
diff changeset
620 hints.ai_family = AF_INET;
cabb568a558b Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents: 20564
diff changeset
621 error = getaddrinfo(name, NULL, &hints, &res);
cabb568a558b Include netdb.h to detect getaddrinfo. Work around problem with getaddrinfo
Martin v. Löwis <martin@v.loewis.de>
parents: 20564
diff changeset
622 }
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
623 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
624 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
625 PyGAI_Err(error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
628 memcpy((char *) addr_ret, res->ai_addr, res->ai_addrlen);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
629 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
630 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
631 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
632 return 4;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
633 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
634 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
635 return 16;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
636 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
637 default:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
638 PyErr_SetString(PySocket_Error, "unknown address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
639 return -1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
640 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
642
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
643
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
644 /* 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
645 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
646 size numbers). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
647
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
648 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
649 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
650 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
651 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
652 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
653
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
654 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
655 NI_NUMERICHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
656 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
657 PyGAI_Err(error);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
658 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
659 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
660 return PyString_FromString(buf);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
661 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
662
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
663
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
664 /* 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
665 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
666 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
667 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
668
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
669 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
670 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
671 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
672 {
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
673 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
674 /* No address -- may be recvfrom() from known socket */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
675 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
676 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
677 }
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
678
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
679 #ifdef __BEOS__
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
680 /* 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
681 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
682 #endif
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
683
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
684 switch (addr->sa_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
685
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
686 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
687 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
688 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
689 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
690 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
691 if (addrobj) {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
692 a = (struct sockaddr_in *)addr;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
693 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
694 Py_DECREF(addrobj);
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
695 }
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
696 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
697 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
698
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
699 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
700 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
701 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 struct sockaddr_un *a = (struct sockaddr_un *) addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
703 return PyString_FromString(a->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
705 #endif /* AF_UNIX */
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
706
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
707 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
708 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
709 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
710 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
711 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
712 PyObject *ret = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
713 if (addrobj) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
714 a = (struct sockaddr_in6 *)addr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
715 ret = Py_BuildValue("Oiii", addrobj, ntohs(a->sin6_port),
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
716 a->sin6_flowinfo, a->sin6_scope_id);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
717 Py_DECREF(addrobj);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
718 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
719 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
720 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
721 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
722
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
723 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
724 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
725 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
726 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
727 char *ifname = "";
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
728 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
729 /* 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
730 if (a->sll_ifindex) {
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
731 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
732 if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0)
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
733 ifname = ifr.ifr_name;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
734 }
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
735 return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol),
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
736 a->sll_pkttype, a->sll_hatype,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
737 a->sll_addr, a->sll_halen);
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
738 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
739 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
740
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
741 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
742
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
743 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
744 /* 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
745 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
746 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
747 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
748 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
749 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
750
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
751 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
752 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
753
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
754
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
755 /* 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
756 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
757 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
758 through len_ret. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
759
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 static int
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
761 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
762 struct sockaddr **addr_ret, int *len_ret)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
763 {
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
764 switch (s->sock_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
765
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
766 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
767 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
768 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
769 struct sockaddr_un* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
770 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
771 int len;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
772 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
773 if (!PyArg_Parse(args, "t#", &path, &len))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
774 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
775 if (len > sizeof addr->sun_path) {
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
776 PyErr_SetString(PySocket_Error,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
777 "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
778 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
779 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
780 addr->sun_family = s->sock_family;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
781 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
782 addr->sun_path[len] = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
783 *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
784 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
786 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
787 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
788
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
789 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
790 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
791 struct sockaddr_in* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
792 char *host;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 int port;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
794 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
795 if (!PyTuple_Check(args)) {
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
796 PyErr_Format(PyExc_TypeError,
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
797 "getsockaddrarg: AF_INET address must be tuple, not %.500s",
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
798 args->ob_type->tp_name);
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
799 return 0;
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
800 }
9731bbb52fb4 Patch by Michael Hudson to clarify the error message from
Guido van Rossum <guido@python.org>
parents: 15046
diff changeset
801 if (!PyArg_ParseTuple(args, "si:getsockaddrarg", &host, &port))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 return 0;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
803 if (setipaddr(host, (struct sockaddr *)addr, AF_INET) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
805 addr->sin_family = AF_INET;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
806 addr->sin_port = htons((short)port);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
807 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
808 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
809 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
810 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
811
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
812 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
813 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
814 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
815 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
816 char *host;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
817 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
818 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
819 flowinfo = scope_id = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
820 if (!PyArg_ParseTuple(args, "si|ii", &host, &port, &flowinfo,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
821 &scope_id)) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
822 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
823 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
824 if (setipaddr(host, (struct sockaddr *)addr, AF_INET6) < 0)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
825 return 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
826 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
827 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
828 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
829 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
830 *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
831 *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
832 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
833 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
834 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
835
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
836 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
837 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
838 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
839 struct sockaddr_ll* addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
840 struct ifreq ifr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
841 char *interfaceName;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
842 int protoNumber;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
843 int hatype = 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
844 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
845 char *haddr;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
846
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
847 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
848 &protoNumber, &pkttype, &hatype, &haddr))
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
849 return 0;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
850 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
851 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
852 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
20378
2f89b344fdb3 Use PySocket_Err() instead of PyErr_SetFromErrno().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20377
diff changeset
853 PySocket_Err();
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
854 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
855 }
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
856 addr = &(s->sock_addr.ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
857 addr->sll_family = AF_PACKET;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
858 addr->sll_protocol = htons((short)protoNumber);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
859 addr->sll_ifindex = ifr.ifr_ifindex;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
860 addr->sll_pkttype = pkttype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
861 addr->sll_hatype = hatype;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
862 *addr_ret = (struct sockaddr *) addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
863 *len_ret = sizeof *addr;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
864 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
865 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
866 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
867
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
868 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
869
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
870 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
871 PyErr_SetString(PySocket_Error, "getsockaddrarg: bad family");
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
872 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
873
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
874 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
875 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
876
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
877
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
878 /* 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
879 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
880 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
881
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
882 static int
13554
906efc1da247 Errare humanum est.
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13538
diff changeset
883 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
884 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
885 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
886
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
887 #ifdef AF_UNIX
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
888 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
889 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
890 *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
891 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
892 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
893 #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
894
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
895 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
896 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
897 *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
898 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
899 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
900
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
901 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
902 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
903 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
904 *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
905 return 1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
906 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
907 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
908
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
909 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
910 case AF_PACKET:
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
911 {
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
912 *len_ret = sizeof (struct sockaddr_ll);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
913 return 1;
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
914 }
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
915 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
916
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
917 /* 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
918
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
919 default:
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
920 PyErr_SetString(PySocket_Error, "getsockaddrlen: bad family");
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
921 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
922
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
923 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
924 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
925
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
926
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
927 /* s.accept() method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
928
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
929 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
930 PySocketSock_accept(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
931 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
932 char addrbuf[256];
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
933 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
934 socklen_t addrlen;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
935 PyObject *sock = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
936 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
937 PyObject *res = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
938
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
939 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
940 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
941 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
942 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
943 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
944 Py_END_ALLOW_THREADS
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
945 #ifdef MS_WINDOWS
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
946 if (newfd == INVALID_SOCKET)
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
947 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
948 if (newfd < 0)
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
949 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
950 return PySocket_Err();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
951
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
952 /* 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
953 to avoid calls to bind() etc. on it. */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
954 sock = (PyObject *) PySocketSock_New(newfd,
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
955 s->sock_family,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
956 s->sock_type,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
957 s->sock_proto);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
958 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
959 SOCKETCLOSE(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
960 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
961 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
962 addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
963 addrlen);
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
964 if (addr == NULL)
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
965 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
966
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
967 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
968
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
969 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
970 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
971 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
972 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
973 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
974
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
975 static char accept_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
976 "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
977 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
978 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
979 connection, and the address of the client. For IP sockets, the address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
980 info is a pair (hostaddr, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
981
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
982
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
983 /* s.setblocking(1 | 0) method */
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
984
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
985 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
986 PySocketSock_setblocking(PySocketSockObject *s, PyObject *arg)
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
987 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
988 int block;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
989 #ifndef RISCOS
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
990 #ifndef MS_WINDOWS
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
991 int delay_flag;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
992 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
993 #endif
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
994 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
995 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
996 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
997 Py_BEGIN_ALLOW_THREADS
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
998 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
999 block = !block;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1000 setsockopt( s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1001 (void *)(&block), sizeof( int ) );
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1002 #else
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1003 #ifndef RISCOS
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1004 #ifndef MS_WINDOWS
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1005 #ifdef PYOS_OS2
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1006 block = !block;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1007 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1008 #else /* !PYOS_OS2 */
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1009 delay_flag = fcntl (s->sock_fd, F_GETFL, 0);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1010 if (block)
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1011 delay_flag &= (~O_NDELAY);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1012 else
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1013 delay_flag |= O_NDELAY;
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1014 fcntl (s->sock_fd, F_SETFL, delay_flag);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1015 #endif /* !PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1016 #else /* MS_WINDOWS */
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1017 block = !block;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1018 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1019 #endif /* MS_WINDOWS */
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1020 #endif /* __BEOS__ */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1021 #endif /* RISCOS */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1022 Py_END_ALLOW_THREADS
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1023
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1024 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1025 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
1026 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1027
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1028 static char setblocking_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1029 "setblocking(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1030 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1031 Set the socket to blocking (flag is true) or non-blocking (false).\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1032 This uses the FIONBIO ioctl with the O_NDELAY flag.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1033
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1034
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1035 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1036 /* s.sleeptaskw(1 | 0) method */
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1037
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1038 static PyObject *
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1039 PySocketSock_sleeptaskw(PySocketSockObject *s,PyObject *args)
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1040 {
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1041 int block;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1042 int delay_flag;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1043 if (!PyArg_GetInt(args, &block))
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1044 return NULL;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1045 Py_BEGIN_ALLOW_THREADS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1046 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1047 Py_END_ALLOW_THREADS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1048
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1049 Py_INCREF(Py_None);
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1050 return Py_None;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1051 }
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1052 static char sleeptaskw_doc[] =
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1053 "sleeptaskw(flag)\n\
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1054 \n\
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1055 Allow sleeps in taskwindows.";
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1056 #endif
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1057
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1058
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
1059 /* 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
1060 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
1061 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
1062 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
1063
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1064 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1065 PySocketSock_setsockopt(PySocketSockObject *s, PyObject *args)
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1066 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1067 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1068 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
1069 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
1070 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
1071 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1072 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1073
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1074 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
1075 &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
1076 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
1077 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
1078 }
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
1079 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1080 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
1081 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
1082 &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
1083 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
1084 }
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
1085 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
1086 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1087 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1088 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1089 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1090 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1091
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1092 static char setsockopt_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1093 "setsockopt(level, option, value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1094 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1095 Set a socket option. See the Unix manual for level and option.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1096 The value argument can either be an integer or a string.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1097
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1098
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
1099 /* 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
1100 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
1101 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
1102 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
1103
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1104 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1105 PySocketSock_getsockopt(PySocketSockObject *s, PyObject *args)
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1106 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1107 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1108 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
1109 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1110 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
1111 socklen_t buflen = 0;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1112
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1113 #ifdef __BEOS__
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1114 /* We have incomplete socket support. */
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1115 PyErr_SetString(PySocket_Error, "getsockopt not supported");
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1116 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1117 #else
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1118
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1119 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
1120 &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
1121 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1122
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
1123 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
1124 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
1125 socklen_t flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1126 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
1127 (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
1128 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1129 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1130 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
1131 }
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
1132 if (buflen <= 0 || buflen > 1024) {
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1133 PyErr_SetString(PySocket_Error,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1134 "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
1135 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
1136 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1137 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
1138 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
1139 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
1140 res = getsockopt(s->sock_fd, level, optname,
17806
3380279612a3 Fix a minor style consistency issue.
Fred Drake <fdrake@acm.org>
parents: 17737
diff changeset
1141 (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
1142 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1143 Py_DECREF(buf);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1144 return PySocket_Err();
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
1145 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1146 _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
1147 return buf;
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1148 #endif /* __BEOS__ */
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1149 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1150
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1151 static char getsockopt_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1152 "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
1153 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1154 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
1155 If a nonzero buffersize argument is given, the return value is a\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1156 string of that length; otherwise it is an integer.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1157
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
1158
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1159 /* s.bind(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1160
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1161 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1162 PySocketSock_bind(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1163 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1164 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1165 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1166 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
1167
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1168 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1169 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1170 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1171 res = bind(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1172 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1173 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1174 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1175 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1176 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1177 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1178
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1179 static char bind_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1180 "bind(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1181 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1182 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
1183 pair (host, port); the host must refer to the local host. For raw packet\n\
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
1184 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
1185
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1186
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1187 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1188 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
1189 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1190
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1191 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1192 PySocketSock_close(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1193 {
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
1194 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
1195
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
1196 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
1197 s->sock_fd = -1;
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1198 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
1199 (void) SOCKETCLOSE(fd);
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1200 Py_END_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1201 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1202 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1203 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1204 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1205
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1206 static char close_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1207 "close()\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1208 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1209 Close the socket. It cannot be used after this call.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1210
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1211
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1212 /* s.connect(sockaddr) method */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1213
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1214 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1215 PySocketSock_connect(PySocketSockObject *s, PyObject *addro)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1216 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1217 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1218 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1219 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
1220
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1221 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1222 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1223 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1224 res = connect(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1225 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1226 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1227 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1228 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1229 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1230 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1231
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1232 static char connect_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1233 "connect(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1234 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1235 Connect the socket to a remote address. For IP sockets, the address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1236 is a pair (host, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1237
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1238
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1239 /* 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
1240
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1241 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1242 PySocketSock_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
1243 {
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1244 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
1245 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
1246 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
1247
13278
3370edad08ce Restore strict checking of socket address values; addresses passed to
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
1248 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
1249 return NULL;
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1250 Py_BEGIN_ALLOW_THREADS
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1251 res = connect(s->sock_fd, addr, addrlen);
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1252 Py_END_ALLOW_THREADS
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1253 if (res != 0)
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1254 res = errno;
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1255 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
1256 }
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1257
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1258 static char connect_ex_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1259 "connect_ex(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1260 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1261 This is like connect(address), but returns an error code (the errno value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1262 instead of raising an exception when an error occurs.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1263
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
1264
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
1265 /* 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
1266
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1267 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1268 PySocketSock_fileno(PySocketSockObject *s)
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
1269 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1270 #if SIZEOF_SOCKET_T <= SIZEOF_LONG
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1271 return PyInt_FromLong((long) s->sock_fd);
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1272 #else
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1273 return PyLong_FromLongLong((LONG_LONG)s->sock_fd);
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1274 #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
1275 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
1276
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1277 static char fileno_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1278 "fileno() -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1279 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1280 Return the integer file descriptor of the socket.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1281
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
1282
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
1283 #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
1284 /* 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
1285
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
1286 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1287 PySocketSock_dup(PySocketSockObject *s)
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
1288 {
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1289 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
1290 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
1291
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
1292 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
1293 if (newfd < 0)
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
1294 return PySocket_Err();
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
1295 sock = (PyObject *) PySocketSock_New(newfd,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1296 s->sock_family,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1297 s->sock_type,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1298 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
1299 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
1300 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
1301 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
1302 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1303
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1304 static char dup_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1305 "dup() -> socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1306 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1307 Return a new socket object connected to the same system resource.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1308
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
1309 #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
1310
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
1311
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1312 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1313
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1314 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1315 PySocketSock_getsockname(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1316 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1317 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
1318 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
1319 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
1320
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1321 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1322 return NULL;
3335
9bd1e41d6b11 clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents: 3091
diff changeset
1323 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1324 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1325 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1326 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1327 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1328 return PySocket_Err();
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1329 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
1330 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1331
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1332 static char getsockname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1333 "getsockname() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1334 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1335 Return the address of the local endpoint. For IP sockets, the address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1336 info is a pair (hostaddr, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1337
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1338
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1339 #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
1340 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1341
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1342 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1343 PySocketSock_getpeername(PySocketSockObject *s)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1344 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1345 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
1346 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
1347 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
1348
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1349 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1350 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
1351 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1352 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1353 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1354 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1355 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1356 return PySocket_Err();
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1357 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
1358 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1359
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1360 static char getpeername_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1361 "getpeername() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1362 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1363 Return the address of the remote endpoint. For IP sockets, the address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1364 info is a pair (hostaddr, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1365
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1366 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1367
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1368
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1369 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1370
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1371 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1372 PySocketSock_listen(PySocketSockObject *s, PyObject *arg)
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 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1375 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
1376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1377 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
1378 if (backlog == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1379 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1380 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1381 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1382 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1383 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1384 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1385 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1386 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1387 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1388 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1389 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1390
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1391 static char listen_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1392 "listen(backlog)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1393 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1394 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
1395 least 1; it specifies the number of unaccepted connection that the system\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1396 will allow before refusing new connections.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1397
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1398
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1399 #ifndef NO_DUP
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1400 /* s.makefile(mode) method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1401 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
1402 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
1403 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
1404 of each other.)
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1405 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
1406
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1407 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1408 PySocketSock_makefile(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1409 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13403
diff changeset
1410 extern int fclose(FILE *);
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1411 char *mode = "r";
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1412 int bufsize = -1;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1413 #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
1414 Py_intptr_t fd;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1415 #else
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1416 int fd;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1417 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1418 FILE *fp;
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1419 PyObject *f;
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1420
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1421 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
1422 return NULL;
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1423 #ifdef MS_WIN32
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1424 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
1425 ((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
1426 #else
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1427 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
1428 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1429 {
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1430 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
1431 SOCKETCLOSE(fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1432 return PySocket_Err();
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1433 }
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1434 f = PyFile_FromFile(fp, "<socket>", mode, fclose);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1435 if (f != NULL)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1436 PyFile_SetBufSize(f, bufsize);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1437 return f;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1438 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1439
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1440 static char makefile_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1441 "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
1442 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1443 Return a regular file object corresponding to the socket.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1444 The mode and buffersize arguments are as for the built-in open() function.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1445
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1446 #endif /* NO_DUP */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1447
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1448
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
1449 /* 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
1450
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1451 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1452 PySocketSock_recv(PySocketSockObject *s, PyObject *args)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1453 {
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
1454 int len, n, flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1455 PyObject *buf;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1456 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
1457 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1458 buf = PyString_FromStringAndSize((char *) 0, len);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1459 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1460 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1461 Py_BEGIN_ALLOW_THREADS
19401
8607bc890b1f It will always be a string, because it is created just before this call.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19278
diff changeset
1462 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
1463 Py_END_ALLOW_THREADS
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1464 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1465 Py_DECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1466 return PySocket_Err();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1467 }
3665
5188374377ae Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents: 3594
diff changeset
1468 if (n != len && _PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1469 return NULL;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1470 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1471 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1472
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1473 static char recv_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1474 "recv(buffersize[, flags]) -> data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1475 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1476 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
1477 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
1478 at least one byte is available or until the remote end is closed. When\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1479 the remote end is closed and all data is read, return the empty string.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1480
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1481
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
1482 /* 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
1483
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1484 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1485 PySocketSock_recvfrom(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1486 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1487 char addrbuf[256];
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1488 PyObject *buf = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1489 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1490 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1491
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
1492 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
1493 socklen_t addrlen;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1494 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
1495 return NULL;
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1496 if (!getsockaddrlen(s, &addrlen))
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1497 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1498 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
1499 if (buf == NULL)
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1500 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1501 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
1502 memset(addrbuf, 0, addrlen);
0ebfe9a1eb43 Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
Fred Drake <fdrake@acm.org>
parents: 17537
diff changeset
1503 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
1504 #ifndef MS_WINDOWS
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1505 #if defined(PYOS_OS2)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1506 (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
1507 #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
1508 (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
1509 #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
1510 #else
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1511 (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
1512 #endif
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1513 );
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1514 Py_END_ALLOW_THREADS
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1515 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1516 Py_DECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1517 return PySocket_Err();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1518 }
3665
5188374377ae Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents: 3594
diff changeset
1519 if (n != len && _PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1520 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1521
16427
c8ef864ba861 fix a couple last-minute bugs in the raw socket support
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16410
diff changeset
1522 if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addrlen)))
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1523 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1524
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1525 ret = Py_BuildValue("OO", buf, addr);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1526 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1527 Py_XDECREF(addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1528 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
1529 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1530 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1531
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1532 static char recvfrom_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1533 "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
1534 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1535 Like recv(buffersize, flags) but also return the sender's address info.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1536
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1537
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
1538 /* 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
1539
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1540 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1541 PySocketSock_send(PySocketSockObject *s, PyObject *args)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1542 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1543 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
1544 int len, n, flags = 0;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
1545 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
1546 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1547 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1548 n = send(s->sock_fd, buf, len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1549 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1550 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1551 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1552 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
1553 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1554
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1555 static char send_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1556 "send(data[, flags])\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1557 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1558 Send a data string to 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
1559 argument, see the Unix manual.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1560
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1561
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
1562 /* 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
1563
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1564 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1565 PySocketSock_sendto(PySocketSockObject *s, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1566 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1567 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1568 char *buf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1569 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
1570 int addrlen, len, n, flags;
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1571 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
1572 if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1573 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
1574 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
1575 &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
1576 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1577 }
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
1578 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1579 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1580 Py_BEGIN_ALLOW_THREADS
1293
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
1581 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1582 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1583 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1584 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1585 return PyInt_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1586 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1587
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1588 static char sendto_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1589 "sendto(data[, flags], address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1590 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1591 Like send(data, flags) but allows specifying the destination address.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1592 For IP sockets, the address is a pair (hostaddr, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1593
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1594
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1595 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1596
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1597 static PyObject *
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1598 PySocketSock_shutdown(PySocketSockObject *s, PyObject *arg)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1599 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1600 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1601 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
1602
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1603 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
1604 if (how == -1 && PyErr_Occurred())
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1605 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1606 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1607 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1608 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1609 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1610 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1611 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1612 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1613 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1614
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1615 static char shutdown_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1616 "shutdown(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1617 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1618 Shut down the reading side of the socket (flag == 0), the writing side\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1619 of the socket (flag == 1), or both ends (flag == 2).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1620
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1621
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1622 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1623
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1624 static PyMethodDef PySocketSock_methods[] = {
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1625 {"accept", (PyCFunction)PySocketSock_accept, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1626 accept_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1627 {"bind", (PyCFunction)PySocketSock_bind, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1628 bind_doc},
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1629 {"close", (PyCFunction)PySocketSock_close, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1630 close_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1631 {"connect", (PyCFunction)PySocketSock_connect, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1632 connect_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1633 {"connect_ex", (PyCFunction)PySocketSock_connect_ex, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1634 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
1635 #ifndef NO_DUP
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1636 {"dup", (PyCFunction)PySocketSock_dup, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1637 dup_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1638 #endif
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1639 {"fileno", (PyCFunction)PySocketSock_fileno, METH_NOARGS,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1640 fileno_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1641 #ifdef HAVE_GETPEERNAME
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1642 {"getpeername", (PyCFunction)PySocketSock_getpeername,
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1643 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
1644 #endif
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
1645 {"getsockname", (PyCFunction)PySocketSock_getsockname,
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1646 METH_NOARGS, getsockname_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1647 {"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1648 getsockopt_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1649 {"listen", (PyCFunction)PySocketSock_listen, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1650 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
1651 #ifndef NO_DUP
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1652 {"makefile", (PyCFunction)PySocketSock_makefile, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1653 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
1654 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1655 {"recv", (PyCFunction)PySocketSock_recv, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1656 recv_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1657 {"recvfrom", (PyCFunction)PySocketSock_recvfrom, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1658 recvfrom_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1659 {"send", (PyCFunction)PySocketSock_send, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1660 send_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1661 {"sendto", (PyCFunction)PySocketSock_sendto, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1662 sendto_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1663 {"setblocking", (PyCFunction)PySocketSock_setblocking, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1664 setblocking_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1665 {"setsockopt", (PyCFunction)PySocketSock_setsockopt, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1666 setsockopt_doc},
20376
061da22f4203 Convert socket methods to use METH_O and METH_NOARGS where possible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20369
diff changeset
1667 {"shutdown", (PyCFunction)PySocketSock_shutdown, METH_O,
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1668 shutdown_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1669 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1670 {"sleeptaskw", (PyCFunction)PySocketSock_sleeptaskw, METH_VARARGS,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1671 sleeptaskw_doc},
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1672 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1673 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1674 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1675
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1676
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1677 /* 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
1678 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1679
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1680 static void
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1681 PySocketSock_dealloc(PySocketSockObject *s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1682 {
12319
57f34e162e67 In dealloc(), only close the socket if fd != -1.
Guido van Rossum <guido@python.org>
parents: 12229
diff changeset
1683 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
1684 (void) SOCKETCLOSE(s->sock_fd);
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12493
diff changeset
1685 PyObject_Del(s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1686 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1687
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1688
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1689 /* Return a socket object's named attribute. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1690
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1691 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1692 PySocketSock_getattr(PySocketSockObject *s, char *name)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1693 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1694 return Py_FindMethod(PySocketSock_methods, (PyObject *) s, name);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1695 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1696
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1697
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1698 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1699 PySocketSock_repr(PySocketSockObject *s)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1700 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1701 char buf[512];
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1702 #if SIZEOF_SOCKET_T > SIZEOF_LONG
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1703 if (s->sock_fd > LONG_MAX) {
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1704 /* 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
1705 ugly printf formatter for decimal pointer length integer
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1706 printing, only bother if necessary*/
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1707 PyErr_SetString(PyExc_OverflowError,
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1708 "no printf formatter to display the socket descriptor in decimal");
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1709 return NULL;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1710 }
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1711 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1712 sprintf(buf,
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1713 "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
1714 (long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto);
3421
90b54312661a remove unused variables
Guido van Rossum <guido@python.org>
parents: 3390
diff changeset
1715 return PyString_FromString(buf);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1716 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1717
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1718
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1719 /* 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
1720
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1721 static PyTypeObject PySocketSock_Type = {
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
1722 PyObject_HEAD_INIT(0) /* Must fill in type value later */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1723 0,
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1724 "socket",
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1725 sizeof(PySocketSockObject),
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1726 0,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1727 (destructor)PySocketSock_dealloc, /*tp_dealloc*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1728 0, /*tp_print*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1729 (getattrfunc)PySocketSock_getattr, /*tp_getattr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1730 0, /*tp_setattr*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1731 0, /*tp_compare*/
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1732 (reprfunc)PySocketSock_repr, /*tp_repr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1733 0, /*tp_as_number*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1734 0, /*tp_as_sequence*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1735 0, /*tp_as_mapping*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1736 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1737
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1738
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1739 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1740
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1741 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1742 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1743 PySocket_gethostname(PyObject *self, PyObject *args)
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1744 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1745 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1746 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
1747 if (!PyArg_ParseTuple(args, ":gethostname"))
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1748 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1749 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1750 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1751 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1752 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1753 return PySocket_Err();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1754 buf[sizeof buf - 1] = '\0';
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1755 return PyString_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1756 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1757
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1758 static char gethostname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1759 "gethostname() -> string\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1760 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1761 Return the current host name.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1762
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1763
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1764 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1765
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1766 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1767 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1768 PySocket_gethostbyname(PyObject *self, PyObject *args)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1769 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1770 char *name;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1771 struct sockaddr_storage addrbuf;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1772
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1773 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
1774 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1775 if (setipaddr(name, (struct sockaddr *)&addrbuf, AF_INET) < 0)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1776 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1777 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
1778 sizeof(struct sockaddr_in));
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1779 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1780
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1781 static char gethostbyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1782 "gethostbyname(host) -> address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1783 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1784 Return the IP address (a string of the form '255.255.255.255') for a host.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1785
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1786
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1787 /* 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
1788
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1789 static PyObject *
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1790 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
1791 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1792 char **pch;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1793 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
1794 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
1795 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
1796 PyObject *tmp;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1797
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1798 if (h == NULL) {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1799 /* 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
1800 #ifndef RISCOS
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1801 PyH_Err(h_errno);
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
1802 #else
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
1803 PyErr_SetString(PySocket_Error, "host not found");
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20648
diff changeset
1804 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1805 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1806 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1807 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
1808 #ifdef HAVE_STRERROR
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1809 /* Let's get real error message to return */
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1810 PyErr_SetString(PySocket_Error, (char *)strerror(EAFNOSUPPORT));
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1811 #else
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1812 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1813 "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
1814 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1815 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1816 }
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1817 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1818 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1819 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
1820 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1821 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1822 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1823 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1824 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
1825 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1826 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1827 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1828 }
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1829 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
1830 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1831 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
1832 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1833 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
1834 int status;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1835 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
1836 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
1837 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1838 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
1839 Py_DECREF(tmp);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1840 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1841 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1842 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1843 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
1844 int status;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1845 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1846 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1847 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1848 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
1849 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
1850 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
1851 #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
1852 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
1853 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1854 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
1855 tmp = makeipaddr((struct sockaddr *)&sin, sizeof(sin));
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1856 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
1857 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
1858 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1859 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1860 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1861 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1862 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1863 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
1864 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
1865 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
1866 #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
1867 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
1868 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1869 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
1870 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
1871 sizeof(sin6));
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1872 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
1873 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
1874 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1875 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1876 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1877 default: /* can't happen */
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1878 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1879 "unsupported address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1880 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1881 }
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1882 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
1883 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1884 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
1885 Py_DECREF(tmp);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1886 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1887 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1888 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1889 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1890 err:
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1891 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
1892 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
1893 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
1894 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1895
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1896
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1897 /* 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
1898
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1899 /*ARGSUSED*/
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1900 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1901 PySocket_gethostbyname_ex(PyObject *self, PyObject *args)
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1902 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1903 char *name;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1904 struct hostent *h;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1905 struct sockaddr_storage addr;
18798
d591a96aed06 Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents: 18794
diff changeset
1906 struct sockaddr *sa;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1907 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
1908 #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
1909 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
1910 #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
1911 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
1912 #else
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1913 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
1914 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
1915 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1916 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1917 #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
1918 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1919 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1920 #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
1921
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1922 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
1923 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1924 if (setipaddr(name, (struct sockaddr *)&addr, PF_INET) < 0)
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1925 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1926 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
1927 #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
1928 #if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
10401
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1929 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1930 #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
1931 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
1932 #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
1933 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
1934 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
1935 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
1936 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1937 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1938 #ifdef USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1939 PyThread_acquire_lock(gethostbyname_lock, 1);
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1940 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1941 h = gethostbyname(name);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1942 #endif /* HAVE_GETHOSTBYNAME_R */
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1943 Py_END_ALLOW_THREADS
18798
d591a96aed06 Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents: 18794
diff changeset
1944 /* Some C libraries would require addr.__ss_family instead of addr.ss_family.
d591a96aed06 Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents: 18794
diff changeset
1945 Therefore, we cast the sockaddr_storage into sockaddr to access sa_family. */
d591a96aed06 Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents: 18794
diff changeset
1946 sa = (struct sockaddr*)&addr;
d591a96aed06 Instead of accessing ss_family, cast sockaddr_storage to sockaddr and access sa_family.
Martin v. Löwis <martin@v.loewis.de>
parents: 18794
diff changeset
1947 ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), sa->sa_family);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1948 #ifdef USE_GETHOSTBYNAME_LOCK
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1949 PyThread_release_lock(gethostbyname_lock);
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1950 #endif
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1951 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
1952 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1953
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1954 static char ghbn_ex_doc[] =
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1955 "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
1956 \n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1957 Return the true host name, a list of aliases, and a list of IP addresses,\n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1958 for a host. The host argument is a string giving a host name or IP number.";
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1959
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1960
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1961 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1962
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1963 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1964 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
1965 PySocket_gethostbyaddr(PyObject *self, PyObject *args)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1966 {
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1967 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1968 struct sockaddr_storage addr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1969 #else
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
1970 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
1971 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1972 struct sockaddr *sa = (struct sockaddr *)&addr;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1973 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1974 struct hostent *h;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1975 PyObject *ret;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1976 #ifdef HAVE_GETHOSTBYNAME_R
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1977 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
1978 #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
1979 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
1980 #else
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1981 char buf[16384];
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1982 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
1983 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1984 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1985 #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
1986 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1987 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1988 #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
1989 char *ap;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1990 int al;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1991 int af;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1992
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
1993 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
1994 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1995 af = PF_UNSPEC;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1996 if (setipaddr(ip_num, sa, af) < 0)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1997 return NULL;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
1998 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
1999 ap = NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2000 al = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2001 switch (af) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2002 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2003 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
2004 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
2005 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2006 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2007 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2008 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
2009 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
2010 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2011 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2012 default:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2013 PyErr_SetString(PySocket_Error, "unsupported address family");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2014 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2015 }
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2016 Py_BEGIN_ALLOW_THREADS
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2017 #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
2018 #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
2019 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
2020 &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
2021 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
2022 #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
2023 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
2024 &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
2025 #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
2026 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
2027 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
2028 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
2029 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2030 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2031 #ifdef USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2032 PyThread_acquire_lock(gethostbyname_lock, 1);
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2033 #endif
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2034 h = gethostbyaddr(ap, al, af);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2035 #endif /* HAVE_GETHOSTBYNAME_R */
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2036 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
2037 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
2038 #ifdef USE_GETHOSTBYNAME_LOCK
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
2039 PyThread_release_lock(gethostbyname_lock);
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2040 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2041 return ret;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2042 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
2043
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2044 static char gethostbyaddr_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2045 "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
2046 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2047 Return the true host name, a list of aliases, and a list of IP addresses,\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2048 for a host. The host argument is a string giving a host name or IP number.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2049
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2050
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2051 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2052 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
2053 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
2054
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2055 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2056 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2057 PySocket_getservbyname(PyObject *self, PyObject *args)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2058 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2059 char *name, *proto;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2060 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
2061 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
2062 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2063 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
2064 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2065 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2066 if (sp == NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2067 PyErr_SetString(PySocket_Error, "service/proto not found");
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2068 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2069 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2070 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
2071 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2072
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2073 static char getservbyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2074 "getservbyname(servicename, protocolname) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2075 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2076 Return a port number from a service name and protocol name.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2077 The protocol name should be 'tcp' or 'udp'.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2078
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2079
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2080 /* Python interface to getprotobyname(name).
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2081 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
2082 already known or not useful (like the list of aliases). */
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2083
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2084 /*ARGSUSED*/
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2085 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2086 PySocket_getprotobyname(PyObject *self, PyObject *args)
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2087 {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2088 char *name;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2089 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
2090 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2091 /* Not available in BeOS yet. - [cjh] */
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2092 PyErr_SetString( PySocket_Error, "getprotobyname not supported" );
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2093 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2094 #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
2095 if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2096 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2097 Py_BEGIN_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2098 sp = getprotobyname(name);
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2099 Py_END_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2100 if (sp == NULL) {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2101 PyErr_SetString(PySocket_Error, "protocol not found");
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2102 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2103 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2104 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
2105 #endif
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2106 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2107
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2108 static char getprotobyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2109 "getprotobyname(name) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2110 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2111 Return the protocol number for the named protocol. (Rarely used.)";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2112
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
2113
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2114 /* Python interface to socket(family, type, proto).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2115 The third (protocol) argument is optional.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2116 Return a new socket object. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2117
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2118 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2119 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2120 PySocket_socket(PyObject *self, PyObject *args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2121 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2122 PySocketSockObject *s;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2123 SOCKET_T fd;
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
2124 int family, type, proto = 0;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11527
diff changeset
2125 if (!PyArg_ParseTuple(args, "ii|i:socket", &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
2126 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2127 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2128 fd = socket(family, type, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2129 Py_END_ALLOW_THREADS
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
2130 #ifdef MS_WINDOWS
3672
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
2131 if (fd == INVALID_SOCKET)
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
2132 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2133 if (fd < 0)
3672
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
2134 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2135 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2136 s = PySocketSock_New(fd, family, type, proto);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2137 /* If the object can't be created, don't forget to close the
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2138 file descriptor again! */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2139 if (s == NULL)
12436
dff7b26116de Use an explicit macro SOCKETCLOSE which expands to closesocket (on
Guido van Rossum <guido@python.org>
parents: 12319
diff changeset
2140 (void) SOCKETCLOSE(fd);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2141 /* From now on, ignore SIGPIPE and let the error checking
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2142 do the work. */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2143 #ifdef SIGPIPE
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
2144 (void) signal(SIGPIPE, SIG_IGN);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2145 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2146 return (PyObject *) s;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2147 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2148
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2149 static char socket_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2150 "socket(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
2151 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2152 Open a socket of the given type. The family argument specifies the\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2153 address family; it is normally AF_INET, sometimes AF_UNIX.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2154 The type argument specifies whether this is a stream (SOCK_STREAM)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2155 or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2156 specifying the default protocol.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2157
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2158
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2159 #ifndef NO_DUP
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2160 /* 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
2161 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
2162 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
2163
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2164 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2165 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2166 PySocket_fromfd(PyObject *self, PyObject *args)
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2167 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2168 PySocketSockObject *s;
13171
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2169 SOCKET_T fd;
c17fd2ca6659 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12712
diff changeset
2170 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
2171 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
2172 &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
2173 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
2174 /* 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
2175 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
2176 if (fd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2177 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2178 s = PySocketSock_New(fd, family, type, proto);
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2179 /* 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
2180 do the work. */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2181 #ifdef SIGPIPE
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2182 (void) signal(SIGPIPE, SIG_IGN);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2183 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2184 return (PyObject *) s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2185 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2186
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2187 static char fromfd_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2188 "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
2189 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2190 Create a socket object from the given file descriptor.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2191 The remaining arguments are the same as for socket().";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2192
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
2193 #endif /* NO_DUP */
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
2194
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2195
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2196 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2197 PySocket_ntohs(PyObject *self, PyObject *args)
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2198 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2199 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2200
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2201 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
2202 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2203 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2204 x2 = (int)ntohs((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2205 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2206 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2207
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2208 static char ntohs_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2209 "ntohs(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2210 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2211 Convert a 16-bit integer from network to host byte order.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2212
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2213
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2214 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2215 PySocket_ntohl(PyObject *self, PyObject *args)
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2216 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2217 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2218
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2219 if (!PyArg_ParseTuple(args, "i:ntohl", &x1)) {
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2220 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2221 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2222 x2 = ntohl(x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2223 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2224 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2225
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2226 static char ntohl_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2227 "ntohl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2228 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2229 Convert a 32-bit integer from network to host byte order.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2230
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2231
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2232 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2233 PySocket_htons(PyObject *self, PyObject *args)
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2234 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2235 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2236
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2237 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
2238 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2239 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2240 x2 = (int)htons((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2241 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2242 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2243
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2244 static char htons_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2245 "htons(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2246 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2247 Convert a 16-bit integer from host to network byte order.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2248
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2249
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2250 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2251 PySocket_htonl(PyObject *self, PyObject *args)
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2252 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2253 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2254
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2255 if (!PyArg_ParseTuple(args, "i:htonl", &x1)) {
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2256 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2257 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2258 x2 = htonl(x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2259 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2260 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
2261
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2262 static char htonl_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2263 "htonl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2264 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2265 Convert a 32-bit integer from host to network byte order.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2266
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2267 /*
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2268 * socket.inet_aton() and socket.inet_ntoa() functions
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2269 *
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2270 * written 20 Aug 1999 by Ben Gertzfield <che@debian.org> <- blame him!
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2271 *
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2272 */
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2273
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2274 static char inet_aton_doc[] =
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2275 "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
2276 \n\
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2277 Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2278 binary format used in low-level network functions.";
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2279
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2280 static PyObject*
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2281 PySocket_inet_aton(PyObject *self, PyObject *args)
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2282 {
11268
3fe8d13328c8 It appears that inet_aton() doesn't really exist except in libresolv;
Guido van Rossum <guido@python.org>
parents: 11219
diff changeset
2283 #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
2284 #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
2285 #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
2286
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2287 /* Have to use inet_addr() instead */
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2288 char *ip_addr;
18753
01692bf02f97 Clean up some warnings from the SGI compiler.
Fred Drake <fdrake@acm.org>
parents: 18743
diff changeset
2289 unsigned long packed_addr;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2290
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2291 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
2292 return NULL;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2293 }
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
2294 #ifdef USE_GUSI1
18753
01692bf02f97 Clean up some warnings from the SGI compiler.
Fred Drake <fdrake@acm.org>
parents: 18743
diff changeset
2295 packed_addr = inet_addr(ip_addr).s_addr;
11438
be25aaca11f4 Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents: 11288
diff changeset
2296 #else
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2297 packed_addr = inet_addr(ip_addr);
11438
be25aaca11f4 Bugfix by Jack Jansen for Macintosh (for the inet_ntoa/aton changes):
Guido van Rossum <guido@python.org>
parents: 11288
diff changeset
2298 #endif
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2299
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2300 if (packed_addr == INADDR_NONE) { /* invalid address */
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2301 PyErr_SetString(PySocket_Error,
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2302 "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
2303 return NULL;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2304 }
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2305
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2306 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
2307 sizeof(packed_addr));
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2308 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2309
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2310 static char inet_ntoa_doc[] =
11937
ef98ee6aeb42 Fixed inet_ntoa() docstring.
Fred Drake <fdrake@acm.org>
parents: 11882
diff changeset
2311 "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
2312 \n\
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2313 Convert an IP address from 32-bit packed binary format to string format";
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2314
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2315 static PyObject*
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2316 PySocket_inet_ntoa(PyObject *self, PyObject *args)
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2317 {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2318 char *packed_str;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
2319 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
2320 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
2321
12050
b90880c0e5eb Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
Guido van Rossum <guido@python.org>
parents: 11937
diff changeset
2322 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
2323 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
2324 }
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2325
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2326 if (addr_len != sizeof(packed_addr)) {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2327 PyErr_SetString(PySocket_Error,
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2328 "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
2329 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
2330 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2331
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2332 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
2333
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2334 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
2335 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2336
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2337 /* 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
2338
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2339 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2340 static PyObject *
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2341 PySocket_getaddrinfo(PyObject *self, PyObject *args)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2342 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2343 struct addrinfo hints, *res0, *res;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2344 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
2345 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
2346 char *hptr, *pptr;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2347 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
2348 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2349 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
2350 PyObject *single = (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2351
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2352 family = socktype = protocol = flags = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2353 family = PF_UNSPEC;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2354 if (!PyArg_ParseTuple(args, "zO|iiii:getaddrinfo",
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2355 &hptr, &pobj, &family, &socktype,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2356 &protocol, &flags)) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2357 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2358 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2359 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
2360 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
2361 pptr = pbuf;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2362 } 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
2363 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
2364 } 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
2365 pptr = (char *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2366 } else {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2367 PyErr_SetString(PySocket_Error, "Int or String expected");
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2368 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2369 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2370 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
2371 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
2372 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
2373 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
2374 hints.ai_flags = flags;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2375 error = getaddrinfo(hptr, pptr, &hints, &res0);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2376 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2377 PyGAI_Err(error);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2378 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2379 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2380
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2381 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
2382 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2383 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
2384 PyObject *addr =
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
2385 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
2386 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
2387 goto err;
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2388 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
2389 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
2390 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
2391 addr);
b47168178d87 PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
Guido van Rossum <guido@python.org>
parents: 20378
diff changeset
2392 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
2393 if (single == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2394 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2395
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2396 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
2397 goto err;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2398 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2399 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2400 return all;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2401 err:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2402 Py_XDECREF(single);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2403 Py_XDECREF(all);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2404 return (PyObject *)NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2405 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2406
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2407 static char getaddrinfo_doc[] =
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2408 "socket.getaddrinfo(host, port [, family, socktype, proto, flags])\n\
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2409 --> List of (family, socktype, proto, canonname, sockaddr)\n\
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2410 \n\
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2411 Resolve host and port into addrinfo struct.";
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2412
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2413 /* 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
2414
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2415 /*ARGSUSED*/
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2416 static PyObject *
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2417 PySocket_getnameinfo(PyObject *self, PyObject *args)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2418 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2419 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
2420 int flags;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2421 char *hostp;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2422 int n, 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
2423 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
2424 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
2425 int error;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2426 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
2427
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2428 flags = flowinfo = scope_id = 0;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2429 if (PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags) == 0)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2430 return NULL;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2431 n = PyArg_ParseTuple(sa, "si|ii", &hostp, &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
2432 if (n == 0)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2433 goto fail;
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
2434 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
2435 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
2436 hints.ai_family = PF_UNSPEC;
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
2437 hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2438 error = getaddrinfo(hostp, pbuf, &hints, &res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2439 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2440 PyGAI_Err(error);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2441 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2442 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2443 if (res->ai_next) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2444 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2445 "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
2446 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2447 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2448 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
2449 case AF_INET:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2450 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2451 char *t1;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2452 int t2;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2453 if (PyArg_ParseTuple(sa, "si", &t1, &t2) == 0) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2454 PyErr_SetString(PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2455 "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
2456 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2457 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2458 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2459 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2460 #ifdef INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2461 case AF_INET6:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2462 {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2463 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
2464 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
2465 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
2466 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
2467 break;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2468 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2469 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2470 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2471 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
2472 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
2473 if (error) {
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2474 PyGAI_Err(error);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2475 goto fail;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2476 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2477 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
2478
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2479 fail:
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2480 if (res)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2481 freeaddrinfo(res);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2482 Py_XDECREF(sa);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2483 return ret;
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2484 }
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2485
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2486 static char getnameinfo_doc[] =
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2487 "socket.getnameinfo(sockaddr, flags) --> (host, port)\n\
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2488 \n\
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2489 Get host and port for a sockaddr.";
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2490
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2491 /* XXX It might be helpful to augment the error message generated
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2492 below with the name of the SSL function that generated the error.
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2493 I expect it's obvious most of the time.
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2494 */
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2495
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2496 #ifdef USE_SSL
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2497 static PyObject *
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2498 PySSL_SetError(SSL *ssl, int ret)
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2499 {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2500 PyObject *v, *n, *s;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2501 char *errstr;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2502 int err;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2503
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2504 assert(ret <= 0);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2505
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2506 err = SSL_get_error(ssl, ret);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2507 n = PyInt_FromLong(err);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2508 if (n == NULL)
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2509 return NULL;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2510 v = PyTuple_New(2);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2511 if (v == NULL) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2512 Py_DECREF(n);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2513 return NULL;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2514 }
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2515
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2516 switch (SSL_get_error(ssl, ret)) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2517 case SSL_ERROR_ZERO_RETURN:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2518 errstr = "TLS/SSL connection has been closed";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2519 break;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2520 case SSL_ERROR_WANT_READ:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2521 errstr = "The operation did not complete (read)";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2522 break;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2523 case SSL_ERROR_WANT_WRITE:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2524 errstr = "The operation did not complete (write)";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2525 break;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2526 case SSL_ERROR_WANT_X509_LOOKUP:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2527 errstr = "The operation did not complete (X509 lookup)";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2528 break;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2529 case SSL_ERROR_SYSCALL:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2530 case SSL_ERROR_SSL:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2531 {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2532 unsigned long e = ERR_get_error();
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2533 if (e == 0) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2534 /* an EOF was observed that violates the protocol */
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2535 errstr = "EOF occurred in violation of protocol";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2536 } else if (e == -1) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2537 /* the underlying BIO reported an I/O error */
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2538 Py_DECREF(v);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2539 Py_DECREF(n);
20378
2f89b344fdb3 Use PySocket_Err() instead of PyErr_SetFromErrno().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20377
diff changeset
2540 return PySocket_Err();
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2541 } else {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2542 /* XXX Protected by global interpreter lock */
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2543 errstr = ERR_error_string(e, NULL);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2544 }
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2545 break;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2546 }
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2547 default:
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2548 errstr = "Invalid error code";
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2549 }
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2550 s = PyString_FromString(errstr);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2551 if (s == NULL) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2552 Py_DECREF(v);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2553 Py_DECREF(n);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2554 }
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2555 PyTuple_SET_ITEM(v, 0, n);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2556 PyTuple_SET_ITEM(v, 1, s);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2557 PyErr_SetObject(PySSLErrorObject, v);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2558 return NULL;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2559 }
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2560
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2561 /* This is a C function to be called for new object initialization */
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2562 static PySSLObject *
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2563 newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2564 {
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2565 PySSLObject *self;
20366
7bcaca653388 USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20360
diff changeset
2566 char *errstr = NULL;
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2567 int ret;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2568
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2569 self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2570 if (self == NULL){
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2571 errstr = "newPySSLObject error";
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2572 goto fail;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2573 }
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2574 memset(self->server, '\0', sizeof(char) * X509_NAME_MAXLEN);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2575 memset(self->issuer, '\0', sizeof(char) * X509_NAME_MAXLEN);
20360
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2576 self->server_cert = NULL;
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2577 self->ssl = NULL;
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2578 self->ctx = NULL;
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2579 self->Socket = NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2580
20367
300b1d8bfa4d Do simple error checking before doing any SSL calls.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20366
diff changeset
2581 if ((key_file && !cert_file) || (!key_file && cert_file)) {
300b1d8bfa4d Do simple error checking before doing any SSL calls.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20366
diff changeset
2582 errstr = "Both the key & certificate files must be specified";
300b1d8bfa4d Do simple error checking before doing any SSL calls.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20366
diff changeset
2583 goto fail;
300b1d8bfa4d Do simple error checking before doing any SSL calls.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20366
diff changeset
2584 }
300b1d8bfa4d Do simple error checking before doing any SSL calls.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20366
diff changeset
2585
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2586 self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2587 if (self->ctx == NULL) {
20366
7bcaca653388 USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20360
diff changeset
2588 errstr = "SSL_CTX_new error";
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2589 goto fail;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2590 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2591
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2592 if (key_file) {
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2593 if (SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2594 SSL_FILETYPE_PEM) < 1) {
20366
7bcaca653388 USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20360
diff changeset
2595 errstr = "SSL_CTX_use_PrivateKey_file error";
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2596 goto fail;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2597 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2598
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2599 if (SSL_CTX_use_certificate_chain_file(self->ctx,
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2600 cert_file) < 1) {
20366
7bcaca653388 USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20360
diff changeset
2601 errstr = "SSL_CTX_use_certificate_chain_file error";
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2602 goto fail;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2603 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2604 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2605
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2606 SSL_CTX_set_verify(self->ctx,
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2607 SSL_VERIFY_NONE, NULL); /* set verify lvl */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2608 self->ssl = SSL_new(self->ctx); /* New ssl struct */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2609 SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2610 SSL_set_connect_state(self->ssl);
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2611
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2612 /* Actually negotiate SSL connection */
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2613 /* XXX If SSL_connect() returns 0, it's also a failure. */
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2614 ret = SSL_connect(self->ssl);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2615 if (ret <= 0) {
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2616 PySSL_SetError(self->ssl, ret);
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2617 goto fail;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2618 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2619 self->ssl->debug = 1;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2620
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2621 if ((self->server_cert = SSL_get_peer_certificate(self->ssl))) {
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2622 X509_NAME_oneline(X509_get_subject_name(self->server_cert),
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2623 self->server, X509_NAME_MAXLEN);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2624 X509_NAME_oneline(X509_get_issuer_name(self->server_cert),
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2625 self->issuer, X509_NAME_MAXLEN);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2626 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2627 self->Socket = Sock;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2628 Py_INCREF(self->Socket);
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2629 return self;
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2630 fail:
20366
7bcaca653388 USe PyObject_SetString() instead of PyObject_SetObject() in newSSLObject().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20360
diff changeset
2631 if (errstr)
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2632 PyErr_SetString(PySSLErrorObject, errstr);
20358
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2633 Py_DECREF(self);
98f597a17c90 Fix two memory leaks in socket.ssl().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19568
diff changeset
2634 return NULL;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2635 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2636
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2637 /* This is the Python function called for new object initialization */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2638 static PyObject *
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2639 PySocket_ssl(PyObject *self, PyObject *args)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2640 {
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2641 PySSLObject *rv;
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2642 PySocketSockObject *Sock;
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2643 char *key_file = NULL;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2644 char *cert_file = NULL;
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2645
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2646 if (!PyArg_ParseTuple(args, "O!|zz:ssl",
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2647 &PySocketSock_Type, (PyObject*)&Sock,
20359
e191ceee672f A bit of reformatting to match the standard style
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20358
diff changeset
2648 &key_file, &cert_file))
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2649 return NULL;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2650
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2651 rv = newPySSLObject(Sock, key_file, cert_file);
20359
e191ceee672f A bit of reformatting to match the standard style
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20358
diff changeset
2652 if (rv == NULL)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2653 return NULL;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2654 return (PyObject *)rv;
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2655 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2656
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2657 static char ssl_doc[] =
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2658 "ssl(socket, [keyfile, certfile]) -> sslobject";
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2659
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2660 /* SSL object methods */
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2661
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2662 static PyObject *
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2663 PySSL_server(PySSLObject *self)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2664 {
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2665 return PyString_FromString(self->server);
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2666 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2667
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2668 static PyObject *
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2669 PySSL_issuer(PySSLObject *self)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2670 {
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2671 return PyString_FromString(self->issuer);
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2672 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2673
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2674
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2675 static void PySSL_dealloc(PySSLObject *self)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2676 {
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2677 if (self->server_cert) /* Possible not to have one? */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2678 X509_free (self->server_cert);
20360
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2679 if (self->ssl)
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2680 SSL_free(self->ssl);
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2681 if (self->ctx)
8a09c855f957 In newSSLObject(), initialize the various members of an SSLObject to NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20359
diff changeset
2682 SSL_CTX_free(self->ctx);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2683 Py_XDECREF(self->Socket);
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12493
diff changeset
2684 PyObject_Del(self);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2685 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2686
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2687 static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2688 {
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2689 char *data;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2690 int len;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2691
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2692 if (!PyArg_ParseTuple(args, "s#:write", &data, &len))
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2693 return NULL;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2694
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2695 len = SSL_write(self->ssl, data, len);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2696 if (len > 0)
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2697 return PyInt_FromLong(len);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2698 else
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2699 return PySSL_SetError(self->ssl, len);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2700 }
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2701
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2702 static char PySSL_SSLwrite_doc[] =
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2703 "write(s) -> len\n\
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2704 \n\
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2705 Writes the string s into the SSL object. Returns the number\n\
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2706 of bytes written.";
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2707
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2708 static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2709 {
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2710 PyObject *buf;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2711 int count = 0;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2712 int len = 1024;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2713
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2714 if (!PyArg_ParseTuple(args, "|i:read", &len))
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2715 return NULL;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2716
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2717 if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2718 return NULL;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2719
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2720 count = SSL_read(self->ssl, PyString_AsString(buf), len);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2721 if (count <= 0) {
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2722 Py_DECREF(buf);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2723 return PySSL_SetError(self->ssl, count);
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2724 }
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2725 if (count != len && _PyString_Resize(&buf, count) < 0)
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2726 return NULL;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2727 return buf;
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2728 }
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2729
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2730 static char PySSL_SSLread_doc[] =
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2731 "read([len]) -> string\n\
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2732 \n\
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2733 Read up to len bytes from the SSL socket.";
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2734
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2735 static PyMethodDef PySSLMethods[] = {
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2736 {"write", (PyCFunction)PySSL_SSLwrite, 1,
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2737 PySSL_SSLwrite_doc},
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2738 {"read", (PyCFunction)PySSL_SSLread, 1,
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2739 PySSL_SSLread_doc},
20440
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
2740 {"server", (PyCFunction)PySSL_server, METH_NOARGS},
9be2cc6b9959 Fix a bunch of warnings reported by Skip.
Guido van Rossum <guido@python.org>
parents: 20412
diff changeset
2741 {"issuer", (PyCFunction)PySSL_issuer, METH_NOARGS},
20377
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2742 {NULL, NULL}
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2743 };
9c2d444674d0 Commit parts of SF patch #462759
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20376
diff changeset
2744
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2745 static PyObject *PySSL_getattr(PySSLObject *self, char *name)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2746 {
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2747 return Py_FindMethod(PySSLMethods, (PyObject *)self, name);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2748 }
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2749
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2750 staticforward PyTypeObject PySSL_Type = {
16106
28c414dcb3e1 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 15994
diff changeset
2751 PyObject_HEAD_INIT(NULL)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2752 0, /*ob_size*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2753 "SSL", /*tp_name*/
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2754 sizeof(PySSLObject), /*tp_basicsize*/
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2755 0, /*tp_itemsize*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2756 /* methods */
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2757 (destructor)PySSL_dealloc, /*tp_dealloc*/
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2758 0, /*tp_print*/
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
2759 (getattrfunc)PySSL_getattr, /*tp_getattr*/
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2760 0, /*tp_setattr*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2761 0, /*tp_compare*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2762 0, /*tp_repr*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2763 0, /*tp_as_number*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2764 0, /*tp_as_sequence*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2765 0, /*tp_as_mapping*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2766 0, /*tp_hash*/
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2767 };
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2768
20505
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2769 /* helper routines for seeding the SSL PRNG */
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2770 static PyObject *
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2771 PySSL_RAND_add(PyObject *self, PyObject *args)
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2772 {
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2773 char *buf;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2774 int len;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2775 double entropy;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2776
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2777 if (!PyArg_ParseTuple(args, "s#d:RAND_add", &buf, &len, &entropy))
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2778 return NULL;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2779 RAND_add(buf, len, entropy);
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2780 Py_INCREF(Py_None);
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2781 return Py_None;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2782 }
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2783
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2784 static char PySSL_RAND_add_doc[] =
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2785 "RAND_add(string, entropy)\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2786 \n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2787 Mix string into the OpenSSL PRNG state. entropy (a float) is a lower\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2788 bound on the entropy contained in string.";
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2789
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2790 static PyObject *
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2791 PySSL_RAND_status(PyObject *self)
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2792 {
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2793 return PyInt_FromLong(RAND_status());
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2794 }
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2795
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2796 static char PySSL_RAND_status_doc[] =
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2797 "RAND_status() -> 0 or 1\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2798 \n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2799 Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2800 It is necessary to seed the PRNG with RAND_add() on some platforms before\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2801 using the ssl() function.";
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2802
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2803 static PyObject *
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2804 PySSL_RAND_egd(PyObject *self, PyObject *arg)
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2805 {
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2806 int bytes;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2807
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2808 if (!PyString_Check(arg))
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2809 return PyErr_Format(PyExc_TypeError,
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2810 "RAND_egd() expected string, found %s",
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2811 arg->ob_type->tp_name);
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2812 bytes = RAND_egd(PyString_AS_STRING(arg));
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2813 if (bytes == -1) {
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2814 PyErr_SetString(PySSLErrorObject,
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2815 "EGD connection failed or EGD did not return "
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2816 "enough data to seed the PRNG");
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2817 return NULL;
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2818 }
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2819 return PyInt_FromLong(bytes);
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2820 }
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2821
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2822 static char PySSL_RAND_egd_doc[] =
20564
8dddfffb9f2b (Hopefully) fix SF bug #472675: CVS socketmodule now doesn't compile
Guido van Rossum <guido@python.org>
parents: 20505
diff changeset
2823 "RAND_egd(path) -> bytes\n\
20505
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2824 \n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2825 Queries the entropy gather daemon (EGD) on socket path. Returns number\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2826 of bytes read. Raises socket.sslerror if connection to EGD fails or\n\
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2827 if it does provide enough data to seed PRNG.";
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2828
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2829 #endif /* USE_SSL */
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2830
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2831
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2832 /* 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
2833
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2834 static PyMethodDef PySocket_methods[] = {
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2835 {"gethostbyname", PySocket_gethostbyname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2836 METH_VARARGS, gethostbyname_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2837 {"gethostbyname_ex", PySocket_gethostbyname_ex,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2838 METH_VARARGS, ghbn_ex_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2839 {"gethostbyaddr", PySocket_gethostbyaddr,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2840 METH_VARARGS, gethostbyaddr_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2841 {"gethostname", PySocket_gethostname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2842 METH_VARARGS, gethostname_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2843 {"getservbyname", PySocket_getservbyname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2844 METH_VARARGS, getservbyname_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2845 {"getprotobyname", PySocket_getprotobyname,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2846 METH_VARARGS,getprotobyname_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2847 {"socket", PySocket_socket,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2848 METH_VARARGS, socket_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
2849 #ifndef NO_DUP
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2850 {"fromfd", PySocket_fromfd,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2851 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
2852 #endif
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2853 {"ntohs", PySocket_ntohs,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2854 METH_VARARGS, ntohs_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2855 {"ntohl", PySocket_ntohl,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2856 METH_VARARGS, ntohl_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2857 {"htons", PySocket_htons,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2858 METH_VARARGS, htons_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2859 {"htonl", PySocket_htonl,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2860 METH_VARARGS, htonl_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2861 {"inet_aton", PySocket_inet_aton,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2862 METH_VARARGS, inet_aton_doc},
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2863 {"inet_ntoa", PySocket_inet_ntoa,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2864 METH_VARARGS, inet_ntoa_doc},
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2865 {"getaddrinfo", PySocket_getaddrinfo,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2866 METH_VARARGS, getaddrinfo_doc},
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2867 {"getnameinfo", PySocket_getnameinfo,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
2868 METH_VARARGS, getnameinfo_doc},
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2869 #ifdef USE_SSL
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
2870 {"ssl", PySocket_ssl,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13761
diff changeset
2871 METH_VARARGS, ssl_doc},
20505
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2872 {"RAND_add", PySSL_RAND_add, METH_VARARGS,
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2873 PySSL_RAND_add_doc},
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2874 {"RAND_egd", PySSL_RAND_egd, METH_O,
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2875 PySSL_RAND_egd_doc},
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2876 {"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS,
93841c5f475b Expose three OpenSSL API calls for dealing with the PRNG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20440
diff changeset
2877 PySSL_RAND_status_doc},
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
2878 #endif /* USE_SSL */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2879 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2880 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2881
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2882
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2883 /* Convenience routine to export an integer value.
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2884 *
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2885 * Errors are silently ignored, for better or for worse...
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2886 */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2887 static void
13470
75b0e8cb0783 - ANSI-ification
Fredrik Lundh <fredrik@pythonware.com>
parents: 13447
diff changeset
2888 insint(PyObject *d, char *name, int value)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2889 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2890 PyObject *v = PyInt_FromLong((long) value);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2891 if (!v || PyDict_SetItemString(d, name, v))
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2892 PyErr_Clear();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
2893
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2894 Py_XDECREF(v);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2895 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2896
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2897
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2898 #ifdef MS_WINDOWS
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2899
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
2900 /* Additional initialization and cleanup for NT/Windows */
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2901
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
2902 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13554
diff changeset
2903 NTcleanup(void)
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2904 {
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
2905 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
2906 }
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
2907
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
2908 static int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13554
diff changeset
2909 NTinit(void)
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2910 {
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
2911 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
2912 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
2913 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
2914 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
2915 switch (ret) {
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2916 case 0: /* no error */
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2917 atexit(NTcleanup);
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2918 return 1;
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2919 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
2920 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
2921 "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
2922 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
2923 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
2924 case WSAEINVAL:
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2925 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
2926 "WSAStartup failed: requested version not supported");
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2927 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
2928 default:
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
2929 sprintf(buf, "WSAStartup failed: error code %d", 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
2930 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
2931 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
2932 }
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
2933 return 0;
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
2934 }
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
2935
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2936 #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
2937
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2938 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2939
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2940 /* Additional initialization and cleanup for OS/2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2941
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2942 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13554
diff changeset
2943 OS2cleanup(void)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2944 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2945 /* No cleanup is necessary for OS/2 Sockets */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2946 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2947
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2948 static int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13554
diff changeset
2949 OS2init(void)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2950 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2951 char reason[64];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2952 int rc = sock_init();
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2953
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2954 if (rc == 0) {
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2955 atexit(OS2cleanup);
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2956 return 1; /* Indicate Success */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2957 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2958
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2959 sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno());
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2960 PyErr_SetString(PyExc_ImportError, reason);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2961
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2962 return 0; /* Indicate Failure */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2963 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2964
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2965 #endif /* PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2966
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2967 /* Initialize this module.
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2968 * This is called when the first 'import socket' is done,
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2969 * via a table in config.c, if config.c is compiled with USE_SOCKET
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2970 * defined.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2971 *
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2972 * For MS_WINDOWS (which means any Windows variant), this module
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2973 * is actually called "_socket", and there's a wrapper "socket.py"
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2974 * which implements some missing functionality (such as makefile(),
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2975 * dup() and fromfd()). The import of "_socket" may fail with an
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2976 * ImportError exception if initialization of WINSOCK fails. When
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2977 * WINSOCK is initialized succesfully, a call to WSACleanup() is
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2978 * scheduled to be made at exit time.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2979 *
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2980 * For OS/2, this module is also called "_socket" and uses a wrapper
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2981 * "socket.py" which implements that functionality that is missing
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2982 * when PC operating systems don't put socket descriptors in the
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2983 * operating system's filesystem layer.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2984 */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2985
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2986 static char module_doc[] =
14008
6c91ad9c0e06 Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents: 13830
diff changeset
2987 "Implementation module for socket operations. See the socket module\n\
6c91ad9c0e06 Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents: 13830
diff changeset
2988 for documentation.";
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2989
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2990 static char sockettype_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2991 "A socket represents one endpoint of a network connection.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2992 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2993 Methods:\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2994 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2995 accept() -- accept a connection, returning new socket and client address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2996 bind() -- bind the socket to a local address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2997 close() -- close the socket\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2998 connect() -- connect the socket to a remote address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2999 connect_ex() -- connect, return an error code instead of an exception \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3000 dup() -- return a new socket object identical to the current one (*)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3001 fileno() -- return underlying file descriptor\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3002 getpeername() -- return remote address (*)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3003 getsockname() -- return local address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3004 getsockopt() -- get socket options\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3005 listen() -- start listening for incoming connections\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3006 makefile() -- return a file object corresponding tot the socket (*)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3007 recv() -- receive data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3008 recvfrom() -- receive data and sender's address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3009 send() -- send data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3010 sendto() -- send data to a given address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3011 setblocking() -- set or clear the blocking I/O flag\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3012 setsockopt() -- set socket options\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3013 shutdown() -- shut down traffic in one or both directions\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3014 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3015 (*) not available on all platforms!)";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3016
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 9307
diff changeset
3017 DL_EXPORT(void)
13694
b54f11ada91e Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents: 13680
diff changeset
3018 init_socket(void)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3019 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3020 PyObject *m, *d;
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3021 #ifdef RISCOS
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3022 _kernel_swi_regs r;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3023 r.r[0]=0;
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3024 _kernel_swi(0x43380, &r, &r);
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3025 taskwindow = r.r[0];
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3026 #else
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
3027 #ifdef MS_WINDOWS
3700
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
3028 if (!NTinit())
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
3029 return;
931086cb8529 More rational support for Windows (tested on Roj's NT 3.5 machine only).
Guido van Rossum <guido@python.org>
parents: 3673
diff changeset
3030 #else
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3031 #if defined(__TOS_OS2__)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3032 if (!OS2init())
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
3033 return;
14008
6c91ad9c0e06 Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents: 13830
diff changeset
3034 #endif /* __TOS_OS2__ */
6c91ad9c0e06 Remove a lot of the confusing conditional compilation from the beginning
Fred Drake <fdrake@acm.org>
parents: 13830
diff changeset
3035 #endif /* MS_WINDOWS */
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3036 #endif /* RISCOS */
16106
28c414dcb3e1 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 15994
diff changeset
3037 #ifdef USE_SSL
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
3038 PySSL_Type.ob_type = &PyType_Type;
16106
28c414dcb3e1 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 15994
diff changeset
3039 #endif
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3040 m = Py_InitModule3("_socket", PySocket_methods, module_doc);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
3041 d = PyModule_GetDict(m);
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3042 PySocket_Error = PyErr_NewException("socket.error", NULL, NULL);
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3043 if (PySocket_Error == NULL)
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3044 return;
18996
9059e7c1d8b0 Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the three
Martin v. Löwis <martin@v.loewis.de>
parents: 18954
diff changeset
3045 PyDict_SetItemString(d, "error", PySocket_Error);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3046 PyH_Error = PyErr_NewException("socket.herror", PySocket_Error, NULL);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3047 if (PyH_Error == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3048 return;
18996
9059e7c1d8b0 Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the three
Martin v. Löwis <martin@v.loewis.de>
parents: 18954
diff changeset
3049 PyDict_SetItemString(d, "herror", PyH_Error);
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3050 PyGAI_Error = PyErr_NewException("socket.gaierror", PySocket_Error,
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3051 NULL);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3052 if (PyGAI_Error == NULL)
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3053 return;
18996
9059e7c1d8b0 Auto-detect hstrerror. Raise socket.herror in PyH_Error. Register the three
Martin v. Löwis <martin@v.loewis.de>
parents: 18954
diff changeset
3054 PyDict_SetItemString(d, "gaierror", PyGAI_Error);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3055 #ifdef USE_SSL
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3056 SSL_load_error_strings();
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3057 SSLeay_add_ssl_algorithms();
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
3058 PySSLErrorObject = PyErr_NewException("socket.sslerror", NULL, NULL);
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
3059 if (PySSLErrorObject == NULL)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3060 return;
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
3061 PyDict_SetItemString(d, "sslerror", PySSLErrorObject);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3062 if (PyDict_SetItemString(d, "SSLType",
20368
9e72bceb540b Lots of code reorganization with a few small API changes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20367
diff changeset
3063 (PyObject *)&PySSL_Type) != 0)
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3064 return;
20369
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3065 PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3066 SSL_ERROR_ZERO_RETURN);
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3067 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_READ",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3068 SSL_ERROR_WANT_READ);
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3069 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_WRITE",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3070 SSL_ERROR_WANT_WRITE);
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3071 PyModule_AddIntConstant(m, "SSL_ERROR_WANT_X509_LOOKUP",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3072 SSL_ERROR_WANT_X509_LOOKUP);
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3073 PyModule_AddIntConstant(m, "SSL_ERROR_SYSCALL",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3074 SSL_ERROR_SYSCALL);
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3075 PyModule_AddIntConstant(m, "SSL_ERROR_SSL",
8830be3209a2 Add a bunch of SSL error constants
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20368
diff changeset
3076 SSL_ERROR_SSL);
11527
28b8585354de OpenSSL support. This is based on patches for a version of SSLeay by
Guido van Rossum <guido@python.org>
parents: 11438
diff changeset
3077 #endif /* USE_SSL */
5572
b231855a9474 Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents: 5534
diff changeset
3078 PySocketSock_Type.ob_type = &PyType_Type;
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
3079 PySocketSock_Type.tp_doc = sockettype_doc;
5697
88b0b2a3aab5 socket_type -> SocketType
Guido van Rossum <guido@python.org>
parents: 5572
diff changeset
3080 if (PyDict_SetItemString(d, "SocketType",
5572
b231855a9474 Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents: 5534
diff changeset
3081 (PyObject *)&PySocketSock_Type) != 0)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
3082 return;
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3083
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3084 /* 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
3085 #ifdef AF_UNSPEC
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3086 insint(d, "AF_UNSPEC", AF_UNSPEC);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3087 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3088 insint(d, "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
3089 #ifdef AF_INET6
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3090 insint(d, "AF_INET6", AF_INET6);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3091 #endif /* AF_INET6 */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
3092 #ifdef AF_UNIX
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3093 insint(d, "AF_UNIX", AF_UNIX);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
3094 #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
3095 #ifdef AF_AX25
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3096 insint(d, "AF_AX25", AF_AX25); /* Amateur Radio AX.25 */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3097 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3098 #ifdef AF_IPX
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3099 insint(d, "AF_IPX", AF_IPX); /* Novell IPX */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3100 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3101 #ifdef AF_APPLETALK
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3102 insint(d, "AF_APPLETALK", AF_APPLETALK); /* Appletalk DDP */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3103 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3104 #ifdef AF_NETROM
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3105 insint(d, "AF_NETROM", AF_NETROM); /* Amateur radio NetROM */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3106 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3107 #ifdef AF_BRIDGE
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3108 insint(d, "AF_BRIDGE", AF_BRIDGE); /* Multiprotocol bridge */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3109 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3110 #ifdef AF_AAL5
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3111 insint(d, "AF_AAL5", AF_AAL5); /* Reserved for Werner's ATM */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3112 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3113 #ifdef AF_X25
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3114 insint(d, "AF_X25", AF_X25); /* Reserved for X.25 project */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3115 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3116 #ifdef AF_INET6
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3117 insint(d, "AF_INET6", AF_INET6); /* IP version 6 */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3118 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3119 #ifdef AF_ROSE
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3120 insint(d, "AF_ROSE", AF_ROSE); /* Amateur Radio X.25 PLP */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3121 #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
3122 #ifdef HAVE_NETPACKET_PACKET_H
16410
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3123 insint(d, "AF_PACKET", AF_PACKET);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3124 insint(d, "PF_PACKET", PF_PACKET);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3125 insint(d, "PACKET_HOST", PACKET_HOST);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3126 insint(d, "PACKET_BROADCAST", PACKET_BROADCAST);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3127 insint(d, "PACKET_MULTICAST", PACKET_MULTICAST);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3128 insint(d, "PACKET_OTHERHOST", PACKET_OTHERHOST);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3129 insint(d, "PACKET_OUTGOING", PACKET_OUTGOING);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3130 insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK);
3d4a7cd0bf17 SF patch 101137 from Grant Edwards
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16400
diff changeset
3131 insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE);
16947
b25131bc6ec7 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16472
diff changeset
3132 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3133
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3134 /* Socket types */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3135 insint(d, "SOCK_STREAM", SOCK_STREAM);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3136 insint(d, "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
3137 #ifndef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
3138 /* We have incomplete socket support. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3139 insint(d, "SOCK_RAW", SOCK_RAW);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3140 insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3141 insint(d, "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
3142 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3143
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3144 #ifdef SO_DEBUG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3145 insint(d, "SO_DEBUG", SO_DEBUG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3146 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3147 #ifdef SO_ACCEPTCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3148 insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3149 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3150 #ifdef SO_REUSEADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3151 insint(d, "SO_REUSEADDR", SO_REUSEADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3152 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3153 #ifdef SO_KEEPALIVE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3154 insint(d, "SO_KEEPALIVE", SO_KEEPALIVE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3155 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3156 #ifdef SO_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3157 insint(d, "SO_DONTROUTE", SO_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3158 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3159 #ifdef SO_BROADCAST
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3160 insint(d, "SO_BROADCAST", SO_BROADCAST);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3161 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3162 #ifdef SO_USELOOPBACK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3163 insint(d, "SO_USELOOPBACK", SO_USELOOPBACK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3164 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3165 #ifdef SO_LINGER
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3166 insint(d, "SO_LINGER", SO_LINGER);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3167 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3168 #ifdef SO_OOBINLINE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3169 insint(d, "SO_OOBINLINE", SO_OOBINLINE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3170 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3171 #ifdef SO_REUSEPORT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3172 insint(d, "SO_REUSEPORT", SO_REUSEPORT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3173 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3174 #ifdef SO_SNDBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3175 insint(d, "SO_SNDBUF", SO_SNDBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3176 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3177 #ifdef SO_RCVBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3178 insint(d, "SO_RCVBUF", SO_RCVBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3179 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3180 #ifdef SO_SNDLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3181 insint(d, "SO_SNDLOWAT", SO_SNDLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3182 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3183 #ifdef SO_RCVLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3184 insint(d, "SO_RCVLOWAT", SO_RCVLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3185 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3186 #ifdef SO_SNDTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3187 insint(d, "SO_SNDTIMEO", SO_SNDTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3188 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3189 #ifdef SO_RCVTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3190 insint(d, "SO_RCVTIMEO", SO_RCVTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3191 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3192 #ifdef SO_ERROR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3193 insint(d, "SO_ERROR", SO_ERROR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3194 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3195 #ifdef SO_TYPE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3196 insint(d, "SO_TYPE", SO_TYPE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3197 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3198
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3199 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3200 #ifdef SOMAXCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3201 insint(d, "SOMAXCONN", SOMAXCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3202 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3203 insint(d, "SOMAXCONN", 5); /* Common value */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3204 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3205
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3206 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3207 #ifdef MSG_OOB
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3208 insint(d, "MSG_OOB", MSG_OOB);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3209 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3210 #ifdef MSG_PEEK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3211 insint(d, "MSG_PEEK", MSG_PEEK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3212 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3213 #ifdef MSG_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3214 insint(d, "MSG_DONTROUTE", MSG_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3215 #endif
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
3216 #ifdef MSG_DONTWAIT
12493
04cfa1341a50 Fix typo in last patch -- the symbol's name is MSG_DONWAIT, not
Guido van Rossum <guido@python.org>
parents: 12492
diff changeset
3217 insint(d, "MSG_DONTWAIT", MSG_DONTWAIT);
12492
1725e802e3eb Patch by Charles G Waldman:
Guido van Rossum <guido@python.org>
parents: 12479
diff changeset
3218 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3219 #ifdef MSG_EOR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3220 insint(d, "MSG_EOR", MSG_EOR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3221 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3222 #ifdef MSG_TRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3223 insint(d, "MSG_TRUNC", MSG_TRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3224 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3225 #ifdef MSG_CTRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3226 insint(d, "MSG_CTRUNC", MSG_CTRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3227 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3228 #ifdef MSG_WAITALL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3229 insint(d, "MSG_WAITALL", MSG_WAITALL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3230 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3231 #ifdef MSG_BTAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3232 insint(d, "MSG_BTAG", MSG_BTAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3233 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3234 #ifdef MSG_ETAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3235 insint(d, "MSG_ETAG", MSG_ETAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3236 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3237
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3238 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3239 #ifdef SOL_SOCKET
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3240 insint(d, "SOL_SOCKET", SOL_SOCKET);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3241 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3242 #ifdef SOL_IP
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3243 insint(d, "SOL_IP", SOL_IP);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3244 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3245 insint(d, "SOL_IP", 0);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3246 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3247 #ifdef SOL_IPX
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3248 insint(d, "SOL_IPX", SOL_IPX);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3249 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3250 #ifdef SOL_AX25
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3251 insint(d, "SOL_AX25", SOL_AX25);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3252 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3253 #ifdef SOL_ATALK
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3254 insint(d, "SOL_ATALK", SOL_ATALK);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3255 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3256 #ifdef SOL_NETROM
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3257 insint(d, "SOL_NETROM", SOL_NETROM);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3258 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3259 #ifdef SOL_ROSE
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3260 insint(d, "SOL_ROSE", SOL_ROSE);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3261 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3262 #ifdef SOL_TCP
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3263 insint(d, "SOL_TCP", SOL_TCP);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3264 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3265 insint(d, "SOL_TCP", 6);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3266 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3267 #ifdef SOL_UDP
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3268 insint(d, "SOL_UDP", SOL_UDP);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3269 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3270 insint(d, "SOL_UDP", 17);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3271 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3272 #ifdef IPPROTO_IP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3273 insint(d, "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
3274 #else
534602746079 Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents: 7942
diff changeset
3275 insint(d, "IPPROTO_IP", 0);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3276 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3277 #ifdef IPPROTO_HOPOPTS
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3278 insint(d, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3279 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3280 #ifdef IPPROTO_ICMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3281 insint(d, "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
3282 #else
534602746079 Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents: 7942
diff changeset
3283 insint(d, "IPPROTO_ICMP", 1);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3284 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3285 #ifdef IPPROTO_IGMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3286 insint(d, "IPPROTO_IGMP", IPPROTO_IGMP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3287 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3288 #ifdef IPPROTO_GGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3289 insint(d, "IPPROTO_GGP", IPPROTO_GGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3290 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3291 #ifdef IPPROTO_IPV4
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3292 insint(d, "IPPROTO_IPV4", IPPROTO_IPV4);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3293 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3294 #ifdef IPPROTO_IPIP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3295 insint(d, "IPPROTO_IPIP", IPPROTO_IPIP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3296 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3297 #ifdef IPPROTO_TCP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3298 insint(d, "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
3299 #else
534602746079 Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents: 7942
diff changeset
3300 insint(d, "IPPROTO_TCP", 6);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3301 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3302 #ifdef IPPROTO_EGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3303 insint(d, "IPPROTO_EGP", IPPROTO_EGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3304 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3305 #ifdef IPPROTO_PUP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3306 insint(d, "IPPROTO_PUP", IPPROTO_PUP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3307 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3308 #ifdef IPPROTO_UDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3309 insint(d, "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
3310 #else
534602746079 Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents: 7942
diff changeset
3311 insint(d, "IPPROTO_UDP", 17);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3312 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3313 #ifdef IPPROTO_IDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3314 insint(d, "IPPROTO_IDP", IPPROTO_IDP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3315 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3316 #ifdef IPPROTO_HELLO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3317 insint(d, "IPPROTO_HELLO", IPPROTO_HELLO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3318 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3319 #ifdef IPPROTO_ND
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3320 insint(d, "IPPROTO_ND", IPPROTO_ND);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3321 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3322 #ifdef IPPROTO_TP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3323 insint(d, "IPPROTO_TP", IPPROTO_TP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3324 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3325 #ifdef IPPROTO_IPV6
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3326 insint(d, "IPPROTO_IPV6", IPPROTO_IPV6);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3327 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3328 #ifdef IPPROTO_ROUTING
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3329 insint(d, "IPPROTO_ROUTING", IPPROTO_ROUTING);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3330 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3331 #ifdef IPPROTO_FRAGMENT
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3332 insint(d, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3333 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3334 #ifdef IPPROTO_RSVP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3335 insint(d, "IPPROTO_RSVP", IPPROTO_RSVP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3336 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3337 #ifdef IPPROTO_GRE
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3338 insint(d, "IPPROTO_GRE", IPPROTO_GRE);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3339 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3340 #ifdef IPPROTO_ESP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3341 insint(d, "IPPROTO_ESP", IPPROTO_ESP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3342 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3343 #ifdef IPPROTO_AH
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3344 insint(d, "IPPROTO_AH", IPPROTO_AH);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3345 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3346 #ifdef IPPROTO_MOBILE
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3347 insint(d, "IPPROTO_MOBILE", IPPROTO_MOBILE);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3348 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3349 #ifdef IPPROTO_ICMPV6
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3350 insint(d, "IPPROTO_ICMPV6", IPPROTO_ICMPV6);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3351 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3352 #ifdef IPPROTO_NONE
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3353 insint(d, "IPPROTO_NONE", IPPROTO_NONE);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3354 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3355 #ifdef IPPROTO_DSTOPTS
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3356 insint(d, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3357 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3358 #ifdef IPPROTO_XTP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3359 insint(d, "IPPROTO_XTP", IPPROTO_XTP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3360 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3361 #ifdef IPPROTO_EON
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3362 insint(d, "IPPROTO_EON", IPPROTO_EON);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3363 #endif
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3364 #ifdef IPPROTO_PIM
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3365 insint(d, "IPPROTO_PIM", IPPROTO_PIM);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3366 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3367 #ifdef IPPROTO_IPCOMP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3368 insint(d, "IPPROTO_IPCOMP", IPPROTO_IPCOMP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3369 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3370 #ifdef IPPROTO_VRRP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3371 insint(d, "IPPROTO_VRRP", IPPROTO_VRRP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3372 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3373 #ifdef IPPROTO_BIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3374 insint(d, "IPPROTO_BIP", IPPROTO_BIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3375 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3376 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3377 #ifdef IPPROTO_RAW
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3378 insint(d, "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
3379 #else
534602746079 Some systems (e.g. Linux) use enums for some symbols (like IPPROTO_IP)
Guido van Rossum <guido@python.org>
parents: 7942
diff changeset
3380 insint(d, "IPPROTO_RAW", 255);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3381 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3382 #ifdef IPPROTO_MAX
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3383 insint(d, "IPPROTO_MAX", IPPROTO_MAX);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3384 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3385
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3386 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3387 #ifdef IPPORT_RESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3388 insint(d, "IPPORT_RESERVED", IPPORT_RESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3389 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3390 insint(d, "IPPORT_RESERVED", 1024);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3391 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3392 #ifdef IPPORT_USERRESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3393 insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3394 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3395 insint(d, "IPPORT_USERRESERVED", 5000);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3396 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3397
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3398 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3399 #ifdef INADDR_ANY
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3400 insint(d, "INADDR_ANY", INADDR_ANY);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3401 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3402 insint(d, "INADDR_ANY", 0x00000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3403 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3404 #ifdef INADDR_BROADCAST
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3405 insint(d, "INADDR_BROADCAST", INADDR_BROADCAST);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3406 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3407 insint(d, "INADDR_BROADCAST", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3408 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3409 #ifdef INADDR_LOOPBACK
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3410 insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3411 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3412 insint(d, "INADDR_LOOPBACK", 0x7F000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3413 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3414 #ifdef INADDR_UNSPEC_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3415 insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3416 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3417 insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3418 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3419 #ifdef INADDR_ALLHOSTS_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3420 insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3421 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3422 insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3423 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3424 #ifdef INADDR_MAX_LOCAL_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3425 insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3426 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3427 insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3428 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3429 #ifdef INADDR_NONE
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3430 insint(d, "INADDR_NONE", INADDR_NONE);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3431 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3432 insint(d, "INADDR_NONE", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3433 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
3434
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3435 /* IPv4 [gs]etsockopt options */
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3436 #ifdef IP_OPTIONS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3437 insint(d, "IP_OPTIONS", IP_OPTIONS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3438 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3439 #ifdef IP_HDRINCL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3440 insint(d, "IP_HDRINCL", IP_HDRINCL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3441 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3442 #ifdef IP_TOS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3443 insint(d, "IP_TOS", IP_TOS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3444 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3445 #ifdef IP_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3446 insint(d, "IP_TTL", IP_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3447 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3448 #ifdef IP_RECVOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3449 insint(d, "IP_RECVOPTS", IP_RECVOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3450 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3451 #ifdef IP_RECVRETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3452 insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3453 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3454 #ifdef IP_RECVDSTADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3455 insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3456 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3457 #ifdef IP_RETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3458 insint(d, "IP_RETOPTS", IP_RETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3459 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3460 #ifdef IP_MULTICAST_IF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3461 insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3462 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3463 #ifdef IP_MULTICAST_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3464 insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3465 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3466 #ifdef IP_MULTICAST_LOOP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3467 insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3468 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3469 #ifdef IP_ADD_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3470 insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3471 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3472 #ifdef IP_DROP_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3473 insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
3474 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3475 #ifdef IP_DEFAULT_MULTICAST_TTL
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3476 insint(d, "IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3477 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3478 #ifdef IP_DEFAULT_MULTICAST_LOOP
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3479 insint(d, "IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3480 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3481 #ifdef IP_MAX_MEMBERSHIPS
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3482 insint(d, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3483 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3484
18997
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3485 /* 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
3486 #ifdef IPV6_JOIN_GROUP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3487 insint(d, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3488 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3489 #ifdef IPV6_LEAVE_GROUP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3490 insint(d, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3491 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3492 #ifdef IPV6_MULTICAST_HOPS
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3493 insint(d, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3494 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3495 #ifdef IPV6_MULTICAST_IF
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3496 insint(d, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3497 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3498 #ifdef IPV6_MULTICAST_LOOP
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3499 insint(d, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3500 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3501 #ifdef IPV6_UNICAST_HOPS
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3502 insint(d, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS);
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3503 #endif
9fc4a5abb369 Add more constants. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents: 18996
diff changeset
3504
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3505 /* TCP options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3506 #ifdef TCP_NODELAY
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3507 insint(d, "TCP_NODELAY", TCP_NODELAY);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3508 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3509 #ifdef TCP_MAXSEG
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3510 insint(d, "TCP_MAXSEG", TCP_MAXSEG);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3511 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3512
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3513 /* IPX options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3514 #ifdef IPX_TYPE
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3515 insint(d, "IPX_TYPE", IPX_TYPE);
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
3516 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3517
18794
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3518 /* 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
3519 #ifdef EAI_ADDRFAMILY
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3520 insint(d, "EAI_ADDRFAMILY", EAI_ADDRFAMILY);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3521 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3522 #ifdef EAI_AGAIN
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3523 insint(d, "EAI_AGAIN", EAI_AGAIN);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3524 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3525 #ifdef EAI_BADFLAGS
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3526 insint(d, "EAI_BADFLAGS", EAI_BADFLAGS);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3527 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3528 #ifdef EAI_FAIL
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3529 insint(d, "EAI_FAIL", EAI_FAIL);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3530 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3531 #ifdef EAI_FAMILY
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3532 insint(d, "EAI_FAMILY", EAI_FAMILY);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3533 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3534 #ifdef EAI_MEMORY
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3535 insint(d, "EAI_MEMORY", EAI_MEMORY);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3536 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3537 #ifdef EAI_NODATA
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3538 insint(d, "EAI_NODATA", EAI_NODATA);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3539 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3540 #ifdef EAI_NONAME
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3541 insint(d, "EAI_NONAME", EAI_NONAME);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3542 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3543 #ifdef EAI_SERVICE
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3544 insint(d, "EAI_SERVICE", EAI_SERVICE);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3545 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3546 #ifdef EAI_SOCKTYPE
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3547 insint(d, "EAI_SOCKTYPE", EAI_SOCKTYPE);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3548 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3549 #ifdef EAI_SYSTEM
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3550 insint(d, "EAI_SYSTEM", EAI_SYSTEM);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3551 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3552 #ifdef EAI_BADHINTS
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3553 insint(d, "EAI_BADHINTS", EAI_BADHINTS);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3554 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3555 #ifdef EAI_PROTOCOL
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3556 insint(d, "EAI_PROTOCOL", EAI_PROTOCOL);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3557 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3558 #ifdef EAI_MAX
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3559 insint(d, "EAI_MAX", EAI_MAX);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3560 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3561 #ifdef AI_PASSIVE
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3562 insint(d, "AI_PASSIVE", AI_PASSIVE);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3563 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3564 #ifdef AI_CANONNAME
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3565 insint(d, "AI_CANONNAME", AI_CANONNAME);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3566 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3567 #ifdef AI_NUMERICHOST
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3568 insint(d, "AI_NUMERICHOST", AI_NUMERICHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3569 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3570 #ifdef AI_MASK
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3571 insint(d, "AI_MASK", AI_MASK);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3572 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3573 #ifdef AI_ALL
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3574 insint(d, "AI_ALL", AI_ALL);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3575 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3576 #ifdef AI_V4MAPPED_CFG
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3577 insint(d, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3578 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3579 #ifdef AI_ADDRCONFIG
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3580 insint(d, "AI_ADDRCONFIG", AI_ADDRCONFIG);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3581 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3582 #ifdef AI_V4MAPPED
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3583 insint(d, "AI_V4MAPPED", AI_V4MAPPED);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3584 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3585 #ifdef AI_DEFAULT
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3586 insint(d, "AI_DEFAULT", AI_DEFAULT);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3587 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3588 #ifdef NI_MAXHOST
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3589 insint(d, "NI_MAXHOST", NI_MAXHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3590 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3591 #ifdef NI_MAXSERV
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3592 insint(d, "NI_MAXSERV", NI_MAXSERV);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3593 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3594 #ifdef NI_NOFQDN
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3595 insint(d, "NI_NOFQDN", NI_NOFQDN);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3596 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3597 #ifdef NI_NUMERICHOST
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3598 insint(d, "NI_NUMERICHOST", NI_NUMERICHOST);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3599 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3600 #ifdef NI_NAMEREQD
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3601 insint(d, "NI_NAMEREQD", NI_NAMEREQD);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3602 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3603 #ifdef NI_NUMERICSERV
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3604 insint(d, "NI_NUMERICSERV", NI_NUMERICSERV);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3605 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3606 #ifdef NI_DGRAM
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3607 insint(d, "NI_DGRAM", NI_DGRAM);
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3608 #endif
4d0ea4c2386d Patch #401196: IPv6 extensions to the socket module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18790
diff changeset
3609
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3610 /* Initialize gethostbyname lock */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
3611 #ifdef USE_GETHOSTBYNAME_LOCK
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
3612 gethostbyname_lock = PyThread_allocate_lock();
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
3613 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3614 }
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
3615
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3616 /* Simplistic emulation code for inet_pton that only works for IPv4 */
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3617 #ifndef HAVE_INET_PTON
18264
3d9164d95e78 Fix typos in inet_pton/inet_ntop.
Martin v. Löwis <martin@v.loewis.de>
parents: 18263
diff changeset
3618 int
18790
7cd22bf56d7b Silence warnings in MSVC++: hide unused variables, add constness back to
Martin v. Löwis <martin@v.loewis.de>
parents: 18753
diff changeset
3619 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
3620 {
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3621 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
3622 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
3623 #ifdef USE_GUSI1
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3624 packed_addr = (long)inet_addr(src).s_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
3625 #else
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3626 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
3627 #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
3628 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
3629 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
3630 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
3631 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
3632 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3633 /* 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
3634 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
3635 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3636
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
3637 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
3638 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
3639 {
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3640 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
3641 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
3642 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
3643 /* 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
3644 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
3645 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
3646 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
3647 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3648 /* 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
3649 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
3650 }
6b0a8157be3b Emulate inet_{pton,ntop} on systems that don't provide it.
Martin v. Löwis <martin@v.loewis.de>
parents: 18253
diff changeset
3651 #endif