annotate Modules/socketmodule.c @ 11219:2d7331f4dfe3 legacy-trunk

Port inet_ntoa and inet_aton to Windows: - fix unescaped newline in string literal - removed unused err variable - Windows doesn't have inet_aton; use inet_addr instead
author Guido van Rossum <guido@python.org>
date Fri, 20 Aug 1999 19:11:27 +0000
parents f406e78ec10b
children 3fe8d13328c8
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 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
3 The Netherlands.
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
8 documentation for any purpose and without fee is hereby granted,
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
10 both that copyright notice and this permission notice appear in
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
15 permission.
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4407
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Socket module */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 /*
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 This module provides an interface to Berkeley socket IPC.
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 Limitations:
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
39 - only AF_INET and AF_UNIX address families are supported
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
40 - 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
41 - additional restrictions apply on Windows
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
43 Module interface:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
45 - socket.error: exception raised for socket specific errors
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
46 - 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
47 - 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
48 - 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
49 - socket.getprotobyname(protocolname) --> protocol number
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
50 - 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
51 - 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
52 - 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
53 - 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
54 - 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
55 - socket.htonl(32 bit value) --> new int object
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
56 - 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
57 - 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
58 - socket.inet_ntoa(packed IP) -> IP address string
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 - an Internet socket address is a pair (hostname, port)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 where hostname can be anything recognized by gethostbyname()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 (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
62 - 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
63 - a UNIX domain socket address is a string specifying the pathname
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
65 Socket methods:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
67 - s.accept() --> new socket object, sockaddr
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
68 - s.bind(sockaddr) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
69 - s.close() --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
70 - s.connect(sockaddr) --> None
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
71 - 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
72 - 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
73 - 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
74 - s.getpeername() --> sockaddr
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
75 - s.getsockname() --> sockaddr
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
76 - s.getsockopt(level, optname[, buflen]) --> int or string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
77 - s.listen(backlog) --> None
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
78 - s.makefile([mode[, bufsize]]) --> file object
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
79 - s.recv(buflen [,flags]) --> string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
80 - 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
81 - s.send(string [,flags]) --> nbytes
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
82 - s.sendto(string, [flags,] sockaddr) --> nbytes
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
83 - s.setblocking(0 | 1) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
84 - s.setsockopt(level, optname, value) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
85 - s.shutdown(how) --> None
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
86 - 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
87
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
90 #include "Python.h"
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
91
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
92 #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
93 #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
94 #undef HAVE_GETHOSTBYNAME_R_6_ARG
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
95
10579
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
96 #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
97 #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
98 #endif
1ed1eb5bc6ec Put back __osf__ support for gethostbyname_r(); the real bug was that
Guido van Rossum <guido@python.org>
parents: 10561
diff changeset
99
10454
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
100 #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
101 #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
102 #define 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
103 #elif defined(__sun__) || defined(__sgi)
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
104 #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
105 #elif defined(linux)
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
106 #define HAVE_GETHOSTBYNAME_R_6_ARG
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
107 #else
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
108 #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
109 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
110 #endif
dad14ffe1c22 Implement two suggestions by Jonathan Giddy: (1) in AIX, clear the
Guido van Rossum <guido@python.org>
parents: 10453
diff changeset
111
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
112 #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
113 #define USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
114 #endif
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
115
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
116 #ifdef USE_GETHOSTBYNAME_LOCK
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9095
diff changeset
117 #include "pythread.h"
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
118 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
120 #ifdef HAVE_UNISTD_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
121 #include <unistd.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
122 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
123
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
124 #if !defined(MS_WINDOWS) && !defined(PYOS_OS2) && !defined(__BEOS__)
4651
6effd10e7233 Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
125 extern int gethostname(); /* For Solaris, at least */
6effd10e7233 Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
126 #endif
6effd10e7233 Added extern decl for gethostname() to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
127
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
128 #if defined(PYCC_VACPP)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
129 #include <types.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
130 #include <io.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
131 #include <sys/ioctl.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
132 #include <utils.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
133 #include <ctype.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
134 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
135
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
136 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
137 #define INCL_DOS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
138 #define INCL_DOSERRORS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
139 #define INCL_NOPMAPI
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
140 #include <os2.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
141 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
142
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
143 #if defined(__BEOS__)
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
144 /* It's in the libs, but not the headers... - [cjh] */
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
145 int shutdown( int, int );
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
146 #endif
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
147
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
148 #include <sys/types.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
149 #include "mytime.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
150
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
151 #include <signal.h>
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
152 #ifndef MS_WINDOWS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
153 #include <netdb.h>
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 #include <sys/socket.h>
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 #include <netinet/in.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
156
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
157 /* added 20 Aug 1999 to remove warnings from inet_ntoa call <che@debian.org> */
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
158 #include <arpa/inet.h>
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
159
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
160 #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
161 #else
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
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
165 #ifdef HAVE_SYS_UN_H
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 #include <sys/un.h>
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
167 #else
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
168 #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
169 #endif
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
170
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
171 #ifndef O_NDELAY
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
172 #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
173 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
174
3390
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
175 #ifdef USE_GUSI
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
176 /* 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
177 #include <GUSI.h>
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
178 #endif
832f26d0e069 Include GUSI.h if using gusi-sockets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3335
diff changeset
179
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
180
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
181 /* Here we have some hacks to choose between K&R or ANSI style function
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
182 definitions. For NT to build this as an extension module (ie, DLL)
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
183 it must be compiled by the C++ compiler, as it takes the address of
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
184 a static data item exported from the main Python DLL.
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
185 */
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
186 #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
187 /* 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
188 /* seem to be a few differences in the API */
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
189 #define close 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
190 #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
191 #define FORCE_ANSI_FUNC_DEFS
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
192 #endif
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
193
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
194 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
195 #define close soclose
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
196 #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
197 #define FORCE_ANSI_FUNC_DEFS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
198 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
199
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
200 #ifdef FORCE_ANSI_FUNC_DEFS
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
201 #define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
202 fnname( arg1type arg1name )
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
203
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
204 #define BUILD_FUNC_DEF_2( fnname, arg1type, arg1name, arg2type, arg2name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
205 fnname( arg1type arg1name, arg2type arg2name )
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
206
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
207 #define BUILD_FUNC_DEF_3( fnname, arg1type, arg1name, arg2type, arg2name , arg3type, arg3name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
208 fnname( arg1type arg1name, arg2type arg2name, arg3type arg3name )
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
209
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
210 #define BUILD_FUNC_DEF_4( fnname, arg1type, arg1name, arg2type, arg2name , arg3type, arg3name, arg4type, arg4name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
211 fnname( arg1type arg1name, arg2type arg2name, arg3type arg3name, arg4type arg4name )
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
212
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
213 #else /* !FORCE_ANSI_FN_DEFS */
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
214 #define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
215 fnname( arg1name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
216 arg1type arg1name;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
217
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
218 #define BUILD_FUNC_DEF_2( fnname, arg1type, arg1name, arg2type, arg2name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
219 fnname( arg1name, arg2name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
220 arg1type arg1name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
221 arg2type arg2name;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
222
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
223 #define BUILD_FUNC_DEF_3( fnname, arg1type, arg1name, arg2type, arg2name, arg3type, arg3name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
224 fnname( arg1name, arg2name, arg3name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
225 arg1type arg1name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
226 arg2type arg2name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
227 arg3type arg3name;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
228
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
229 #define BUILD_FUNC_DEF_4( fnname, arg1type, arg1name, arg2type, arg2name, arg3type, arg3name, arg4type, arg4name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
230 fnname( arg1name, arg2name, arg3name, arg4name ) \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
231 arg1type arg1name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
232 arg2type arg2name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
233 arg3type arg3name; \
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
234 arg4type arg4name;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
235
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
236 #endif /* !FORCE_ANSI_FN_DEFS */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
237
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
238 /* 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
239 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
240
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
241 static PyObject *PySocket_Error;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
242
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
243
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
244 /* 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
245 and return a NULL pointer from a function. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
247 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
248 PySocket_Err()
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
250 #ifdef MS_WINDOWS
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
251 if (WSAGetLastError()) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
252 PyObject *v;
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
253 v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error");
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
254 if (v != NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
255 PyErr_SetObject(PySocket_Error, v);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
256 Py_DECREF(v);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
257 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
258 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
259 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
260 else
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
261 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
262
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
263 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
264 if (sock_errno() != NO_ERROR) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
265 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
266 ULONG msglen;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
267 char outbuf[100];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
268 int myerrorcode = sock_errno();
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
269
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
270 /* 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
271 rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
272 myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
273 if (rc == NO_ERROR) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
274 PyObject *v;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
275
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
276 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
277 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
278 char *lastc = &outbuf[ strlen(outbuf)-1 ];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
279 while (lastc > outbuf && isspace(*lastc))
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
280 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
281 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
282 v = Py_BuildValue("(is)", myerrorcode, outbuf);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
283 if (v != NULL) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
284 PyErr_SetObject(PySocket_Error, v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
285 Py_DECREF(v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
286 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
287 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
288 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
289 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
290 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
291
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
292 return PyErr_SetFromErrno(PySocket_Error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
296 /* 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
297 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
298 arguments properly. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
299
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 typedef struct {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
301 PyObject_HEAD
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
302 int sock_fd; /* Socket file descriptor */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
303 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
304 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
305 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
306 union sock_addr {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
307 struct sockaddr_in in;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
308 #ifdef AF_UNIX
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
309 struct sockaddr_un un;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
310 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
311 } sock_addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
312 } PySocketSockObject;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
314
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
315 /* 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
316 The Socktype variable contains pointers to various functions,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
317 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
318 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
319
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
320 staticforward PyTypeObject PySocketSock_Type;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
322
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
323 /* Create a new socket object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
324 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
325 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
326 in NEWOBJ()). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
327
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
328 static PySocketSockObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
329 BUILD_FUNC_DEF_4(PySocketSock_New,int,fd, int,family, int,type, int,proto)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
331 PySocketSockObject *s;
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
332 PySocketSock_Type.ob_type = &PyType_Type;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
333 s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 if (s != NULL) {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 s->sock_fd = fd;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 s->sock_family = family;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 s->sock_type = type;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 s->sock_proto = proto;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
343
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
344 /* Lock to allow python interpreter to continue, but only allow one
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
345 thread to be in gethostbyname */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
346 #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
347 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
348 #endif
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
349
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
350
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
351 /* 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
352 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
353 to do the work; the names "" and "<broadcast>" are special.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
354 Return the length (should always be 4 bytes), or negative if
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
355 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
356
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 static int
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
358 BUILD_FUNC_DEF_2(setipaddr, char*,name, struct sockaddr_in *,addr_ret)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 struct hostent *hp;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
361 int d1, d2, d3, d4;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
362 int h_length;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
363 char ch;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
364 #ifdef HAVE_GETHOSTBYNAME_R
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
365 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
366 #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
367 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
368 #else
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
369 char buf[1001];
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
370 int buf_len = (sizeof buf) - 1;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
371 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
372 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
373 #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
374 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
375 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
376 #endif /* HAVE_GETHOSTBYNAME_R */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
378 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
379 if (name[0] == '\0') {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 addr_ret->sin_addr.s_addr = INADDR_ANY;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 return 4;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
383 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 addr_ret->sin_addr.s_addr = INADDR_BROADCAST;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 return 4;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
387 if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
388 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
389 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
390 addr_ret->sin_addr.s_addr = htonl(
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
391 ((long) d1 << 24) | ((long) d2 << 16) |
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
392 ((long) d3 << 8) | ((long) d4 << 0));
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
393 return 4;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
394 }
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
395 Py_BEGIN_ALLOW_THREADS
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
396 #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
397 #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
398 result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &hp, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
399 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
400 hp = 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
401 #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
402 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
403 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
404 hp = (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
405 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
406 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
407 #ifdef USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
408 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
409 #endif
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
410 hp = gethostbyname(name);
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
411 #endif /* HAVE_GETHOSTBYNAME_R */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
412 Py_END_ALLOW_THREADS
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
413
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 if (hp == NULL) {
2115
7ea369d05c2e better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
415 #ifdef HAVE_HSTRERROR
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
416 /* Let's get real error message to return */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
417 extern int h_errno;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
418 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
419 #else
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
420 PyErr_SetString(PySocket_Error, "host not found");
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
421 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
422 #ifdef USE_GETHOSTBYNAME_LOCK
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
423 PyThread_release_lock(gethostbyname_lock);
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
424 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
428 h_length = hp->h_length;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
429 #ifdef USE_GETHOSTBYNAME_LOCK
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
430 PyThread_release_lock(gethostbyname_lock);
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
431 #endif
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
432 return h_length;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
435
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
436 /* 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
437 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
438 size numbers). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
439
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
440 static PyObject *
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
441 BUILD_FUNC_DEF_1(makeipaddr, struct sockaddr_in *,addr)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
442 {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
443 long x = ntohl(addr->sin_addr.s_addr);
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
444 char buf[100];
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
445 sprintf(buf, "%d.%d.%d.%d",
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
446 (int) (x>>24) & 0xff, (int) (x>>16) & 0xff,
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
447 (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
448 return PyString_FromString(buf);
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
449 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
450
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
451
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
452 /* 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
453 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
454 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
455 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
456
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
457 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
458 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
459 BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *,addr, int,addrlen)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 {
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
461 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
462 /* No address -- may be recvfrom() from known socket */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
463 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
464 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
465 }
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
466
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
467 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
468 /* XXX: BeOS version of accept() doesn't set family coreectly */
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
469 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
470 #endif
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
471
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
472 switch (addr->sa_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
473
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
474 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
475 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 struct sockaddr_in *a = (struct sockaddr_in *) addr;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
477 PyObject *addrobj = makeipaddr(a);
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
478 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
479 if (addrobj) {
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
480 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
481 Py_DECREF(addrobj);
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
482 }
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
483 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
484 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
485
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
486 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
487 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
488 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 struct sockaddr_un *a = (struct sockaddr_un *) addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
490 return PyString_FromString(a->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
492 #endif /* AF_UNIX */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
493
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
494 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
495
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
496 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
497 /* 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
498 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
499 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
500 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
501 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
502 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
503
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
504 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
505 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
506
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
507
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
508 /* 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
509 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
510 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
511 through len_ret. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
512
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
513 static int
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
514 BUILD_FUNC_DEF_4(
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
515 getsockaddrarg,PySocketSockObject *,s, PyObject *,args, struct sockaddr **,addr_ret, int *,len_ret)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 {
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
517 switch (s->sock_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
518
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
519 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
520 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
521 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
522 struct sockaddr_un* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
523 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 int len;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
525 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
526 if (!PyArg_Parse(args, "t#", &path, &len))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
527 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
528 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
529 PyErr_SetString(PySocket_Error,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
530 "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
531 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
532 }
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
533 addr->sun_family = AF_UNIX;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
534 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
535 addr->sun_path[len] = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
536 *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
537 *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
540 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
541
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
542 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
543 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
544 struct sockaddr_in* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
545 char *host;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
546 int port;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
547 addr=(struct sockaddr_in*)&(s->sock_addr).in;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
548 if (!PyArg_Parse(args, "(si)", &host, &port))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
550 if (setipaddr(host, addr) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
552 addr->sin_family = AF_INET;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
553 addr->sin_port = htons((short)port);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
554 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
555 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
558
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
559 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
560
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
561 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
562 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
563 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
564
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
565 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
566 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
567
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
568
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
569 /* Get the address length according to the socket object's address family.
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
570 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
571 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
572
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
573 static int
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
574 BUILD_FUNC_DEF_2(getsockaddrlen,PySocketSockObject *,s, int *,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
575 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
576 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
577
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
578 #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
579 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
580 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
581 *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
582 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
583 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
584 #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
585
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
586 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
587 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
588 *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
589 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
590 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
591
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
592 /* 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
593
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
594 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
595 PyErr_SetString(PySocket_Error, "getsockaddrarg: 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
596 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
597
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
598 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
599 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
600
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
601
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
602 /* s.accept() method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
603
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
604 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
605 BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 char addrbuf[256];
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608 int addrlen, newfd;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
609 PyObject *sock = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
610 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
611 PyObject *res = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
612
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
613 if (!PyArg_NoArgs(args))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 return NULL;
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
615 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
616 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
617 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
619 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 if (newfd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
621 return PySocket_Err();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
622
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
623 /* 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
624 to avoid calls to bind() etc. on it. */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
625 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
626 s->sock_family,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
627 s->sock_type,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
628 s->sock_proto);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
629 if (sock == NULL) {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 close(newfd);
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
631 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
632 }
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
633 if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen)))
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
634 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
635
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
636 if (!(res = Py_BuildValue("OO", sock, addr)))
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
637 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
638
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
639 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
640 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
641 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
644
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
645 static char accept_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
646 "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
647 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
648 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
649 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
650 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
651
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
652
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
653 /* 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
654
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
655 static PyObject *
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
656 BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
657 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
658 int block;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
659 #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
660 int delay_flag;
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 4871
diff changeset
661 #endif
5534
84d3cca814fb Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents: 5436
diff changeset
662 if (!PyArg_Parse(args, "i", &block))
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
663 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
664 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
665 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
666 block = !block;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
667 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
668 (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
669 #else
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
670 #ifndef MS_WINDOWS
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
671 #ifdef PYOS_OS2
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
672 block = !block;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
673 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
674 #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
675 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
676 if (block)
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
677 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
678 else
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
679 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
680 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
681 #endif /* !PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
682 #else /* MS_WINDOWS */
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
683 block = !block;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
684 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
685 #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
686 #endif /* __BEOS__ */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
687 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
688
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
689 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
690 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
691 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
692
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
693 static char setblocking_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
694 "setblocking(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
695 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
696 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
697 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
698
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
699
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
700 /* 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
701 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
702 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
703 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
704
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
705 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
706 BUILD_FUNC_DEF_2(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
707 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
708 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
709 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
710 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
711 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
712 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
713 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
714
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
715 if (PyArg_Parse(args, "(iii)", &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
716 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
717 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
718 }
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
719 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
720 PyErr_Clear();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
721 if (!PyArg_Parse(args, "(iis#)", &level, &optname,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
722 &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
723 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
724 }
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
725 res = setsockopt(s->sock_fd, level, optname, (ANY *)buf, buflen);
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
726 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
727 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
728 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
729 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
730 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
731
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
732 static char setsockopt_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
733 "setsockopt(level, option, value)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
734 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
735 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
736 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
737
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
738
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
739 /* 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
740 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
741 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
742 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
743
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
744 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
745 BUILD_FUNC_DEF_2(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
746 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
747 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
748 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
749 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
750 PyObject *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
751 int buflen = 0;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
752
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
753 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
754 /* We have incomplete socket support. */
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
755 PyErr_SetString( PySocket_Error, "getsockopt not supported" );
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
756 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
757 #else
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
758
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
759 if (!PyArg_ParseTuple(args, "ii|i", &level, &optname, &buflen))
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
760 return NULL;
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
761
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
762 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
763 int flag = 0;
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
764 int flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
765 res = getsockopt(s->sock_fd, level, optname,
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
766 (ANY *)&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
767 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
768 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
769 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
770 }
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
771 if (buflen <= 0 || buflen > 1024) {
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
772 PyErr_SetString(PySocket_Error,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
773 "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
774 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
775 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
776 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
777 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
778 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
779 res = getsockopt(s->sock_fd, level, optname,
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2115
diff changeset
780 (ANY *)PyString_AsString(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
781 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
782 Py_DECREF(buf);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
783 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
784 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
785 _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
786 return buf;
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
787 #endif /* __BEOS__ */
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
788 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
789
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
790 static char getsockopt_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
791 "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
792 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
793 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
794 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
795 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
796
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
797
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
798 /* s.bind(sockaddr) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
799
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
800 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
801 BUILD_FUNC_DEF_2(PySocketSock_bind,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
805 int res;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 if (!getsockaddrarg(s, args, &addr, &addrlen))
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
808 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
809 res = bind(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
810 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
811 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
812 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
813 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
814 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
815 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
816
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
817 static char bind_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
818 "bind(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
819 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
820 Bind the socket to a local address. For IP sockets, the address is a\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
821 pair (host, port); the host must refer to the local host.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
822
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
823
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
824 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
825 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
826 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
827
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
828 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
829 BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
831 if (!PyArg_NoArgs(args))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
832 return NULL;
4407
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
833 if (s->sock_fd != -1) {
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
834 Py_BEGIN_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
835 (void) close(s->sock_fd);
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
836 Py_END_ALLOW_THREADS
7ddd8b3f6802 Don't close an already closed socket.
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
837 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
838 s->sock_fd = -1;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
839 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
840 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
841 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
842
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
843 static char close_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
844 "close()\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
845 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
846 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
847
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
848
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
849 /* s.connect(sockaddr) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
850
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
851 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
852 BUILD_FUNC_DEF_2(PySocketSock_connect,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
853 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
854 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
855 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
856 int res;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
857 if (!getsockaddrarg(s, args, &addr, &addrlen))
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
858 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
859 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
860 res = connect(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
861 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
862 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
863 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
864 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
865 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
866 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
867
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
868 static char connect_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
869 "connect(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
870 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
871 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
872 is a pair (host, port).";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
873
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
874
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
875 /* s.connect_ex(sockaddr) method */
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
876
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
877 static PyObject *
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
878 BUILD_FUNC_DEF_2(PySocketSock_connect_ex,PySocketSockObject *,s, PyObject *,args)
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
879 {
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
880 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
881 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
882 int res;
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
883 if (!getsockaddrarg(s, args, &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
884 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
885 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
886 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
887 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
888 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
889 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
890 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
891 }
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
892
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
893 static char connect_ex_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
894 "connect_ex(address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
895 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
896 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
897 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
898
6604
f67a6339ede7 Add s.connect_ex() which returns errno instead of raising an exception.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
899
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
900 /* 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
901
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
902 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
903 BUILD_FUNC_DEF_2(PySocketSock_fileno,PySocketSockObject *,s, PyObject *,args)
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
904 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
905 if (!PyArg_NoArgs(args))
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
906 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
907 return PyInt_FromLong((long) s->sock_fd);
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
908 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
909
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
910 static char fileno_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
911 "fileno() -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
912 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
913 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
914
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
915
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
916 #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
917 /* 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
918
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
919 static PyObject *
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
920 BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args)
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
921 {
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
922 int newfd;
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
923 PyObject *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
924 if (!PyArg_NoArgs(args))
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
925 return NULL;
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
926 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
927 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
928 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
929 sock = (PyObject *) PySocketSock_New(newfd,
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
930 s->sock_family,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
931 s->sock_type,
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
932 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
933 if (sock == NULL)
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
934 close(newfd);
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
935 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
936 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
937
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
938 static char dup_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
939 "dup() -> socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
940 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
941 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
942
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
943 #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
944
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
945
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
946 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
947
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
948 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
949 BUILD_FUNC_DEF_2(PySocketSock_getsockname,PySocketSockObject *,s, PyObject *,args)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
950 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
951 char addrbuf[256];
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
952 int addrlen, res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
953 if (!PyArg_NoArgs(args))
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
954 return NULL;
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
955 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
956 return NULL;
3335
9bd1e41d6b11 clear addr buffer before calling getsockname
Guido van Rossum <guido@python.org>
parents: 3091
diff changeset
957 memset(addrbuf, 0, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
958 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
959 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
960 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
961 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
962 return PySocket_Err();
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
963 return makesockaddr((struct sockaddr *) addrbuf, addrlen);
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
964 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
965
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
966 static char getsockname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
967 "getsockname() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
968 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
969 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
970 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
971
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
972
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
973 #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
974 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
975
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
976 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
977 BUILD_FUNC_DEF_2(PySocketSock_getpeername,PySocketSockObject *,s, PyObject *,args)
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
978 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
979 char addrbuf[256];
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
980 int addrlen, res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
981 if (!PyArg_NoArgs(args))
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
982 return NULL;
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
983 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
984 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
985 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
986 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
987 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
988 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
989 return PySocket_Err();
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
990 return makesockaddr((struct sockaddr *) addrbuf, addrlen);
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
991 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
992
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
993 static char getpeername_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
994 "getpeername() -> address info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
995 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
996 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
997 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
998
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
999 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1000
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
1001
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1002 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1003
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1004 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1005 BUILD_FUNC_DEF_2(PySocketSock_listen,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1006 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1007 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1008 int res;
5534
84d3cca814fb Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents: 5436
diff changeset
1009 if (!PyArg_Parse(args, "i", &backlog))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1010 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1011 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1012 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1013 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1014 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1015 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1016 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1017 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1018 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1019 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1020 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1021
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1022 static char listen_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1023 "listen(backlog)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1024 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1025 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
1026 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
1027 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
1028
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1029
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1030 #ifndef NO_DUP
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1031 /* s.makefile(mode) method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1032 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
1033 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
1034 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
1035 of each other.)
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1036 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
1037
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1038 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1039 BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1040 {
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2115
diff changeset
1041 extern int fclose Py_PROTO((FILE *));
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1042 char *mode = "r";
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1043 int bufsize = -1;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1044 int fd;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1045 FILE *fp;
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1046 PyObject *f;
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1047
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1048 if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1049 return NULL;
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1050 #ifdef MS_WIN32
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1051 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
1052 ((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
1053 #else
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1054 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
1055 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1056 {
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1057 if (fd >= 0)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1058 close(fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1059 return PySocket_Err();
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1060 }
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1061 f = PyFile_FromFile(fp, "<socket>", mode, fclose);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1062 if (f != NULL)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1063 PyFile_SetBufSize(f, bufsize);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
1064 return f;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1065 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1066
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1067 static char makefile_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1068 "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
1069 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1070 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
1071 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
1072
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1073 #endif /* NO_DUP */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1074
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1075
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
1076 /* 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
1077
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1078 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1079 BUILD_FUNC_DEF_2(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
1080 {
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
1081 int len, n, flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1082 PyObject *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
1083 if (!PyArg_ParseTuple(args, "i|i", &len, &flags))
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
1084 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1085 buf = PyString_FromStringAndSize((char *) 0, len);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1086 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1087 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1088 Py_BEGIN_ALLOW_THREADS
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2115
diff changeset
1089 n = recv(s->sock_fd, PyString_AsString(buf), len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1090 Py_END_ALLOW_THREADS
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1091 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1092 Py_DECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1093 return PySocket_Err();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1094 }
3665
5188374377ae Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents: 3594
diff changeset
1095 if (n != len && _PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1096 return NULL;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1097 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1098 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1099
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1100 static char recv_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1101 "recv(buffersize[, flags]) -> data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1102 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1103 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
1104 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
1105 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
1106 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
1107
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1108
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
1109 /* 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
1110
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1111 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1112 BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1113 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1114 char addrbuf[256];
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1115 PyObject *buf = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1116 PyObject *addr = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1117 PyObject *ret = NULL;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1118
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
1119 int addrlen, len, n, flags = 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
1120 if (!PyArg_ParseTuple(args, "i|i", &len, &flags))
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;
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1122 if (!getsockaddrlen(s, &addrlen))
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1123 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1124 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
1125 if (buf == NULL)
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
1126 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1127 Py_BEGIN_ALLOW_THREADS
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1128 n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1129 #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
1130 #if defined(PYOS_OS2)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1131 (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
1132 #else
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1133 (ANY *)addrbuf, &addrlen
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1134 #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
1135 #else
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1136 (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
1137 #endif
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1138 );
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1139 Py_END_ALLOW_THREADS
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1140 if (n < 0) {
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1141 Py_DECREF(buf);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1142 return PySocket_Err();
3091
7ddfb629ac3f plug some leaks
Guido van Rossum <guido@python.org>
parents: 2736
diff changeset
1143 }
3665
5188374377ae Get rid of obsolete allowbroadcast().
Guido van Rossum <guido@python.org>
parents: 3594
diff changeset
1144 if (n != len && _PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1145 return NULL;
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1146
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1147 if (!(addr = makesockaddr((struct sockaddr *)addrbuf, addrlen)))
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1148 goto finally;
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1149
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1150 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
1151 finally:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1152 Py_XDECREF(addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1153 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
1154 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1155 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1156
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1157 static char recvfrom_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1158 "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
1159 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1160 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
1161
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1162
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
1163 /* 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
1164
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1165 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1166 BUILD_FUNC_DEF_2(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
1167 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1168 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
1169 int len, n, flags = 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
1170 if (!PyArg_ParseTuple(args, "s#|i", &buf, &len, &flags))
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
1171 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1172 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1173 n = send(s->sock_fd, buf, len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1174 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1175 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1176 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1177 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
1178 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1179
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1180 static char send_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1181 "send(data[, flags])\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1182 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1183 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
1184 argument, see the Unix manual.";
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
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
1187 /* 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
1188
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1189 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1190 BUILD_FUNC_DEF_2(PySocketSock_sendto,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1191 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1192 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1193 char *buf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1194 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
1195 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
1196 flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1197 if (!PyArg_Parse(args, "(s#O)", &buf, &len, &addro)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1198 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1199 if (!PyArg_Parse(args, "(s#iO)", &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
1200 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1201 }
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
1202 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1203 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1204 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
1205 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1206 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1207 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1208 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1209 return PyInt_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1210 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1211
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1212 static char sendto_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1213 "sendto(data[, flags], address)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1214 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1215 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
1216 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
1217
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1218
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1219 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1220
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1221 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1222 BUILD_FUNC_DEF_2(PySocketSock_shutdown,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1223 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1224 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1225 int res;
5534
84d3cca814fb Remove the last three uses of PyArg_GetInt() from the source.
Guido van Rossum <guido@python.org>
parents: 5436
diff changeset
1226 if (!PyArg_Parse(args, "i", &how))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1227 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1228 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1229 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1230 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1231 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1232 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1233 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1234 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1235 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1236
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1237 static char shutdown_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1238 "shutdown(flag)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1239 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1240 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
1241 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
1242
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1243
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1244 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1245
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1246 static PyMethodDef PySocketSock_methods[] = {
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1247 {"accept", (PyCFunction)PySocketSock_accept, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1248 accept_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1249 {"bind", (PyCFunction)PySocketSock_bind, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1250 bind_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1251 {"close", (PyCFunction)PySocketSock_close, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1252 close_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1253 {"connect", (PyCFunction)PySocketSock_connect, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1254 connect_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1255 {"connect_ex", (PyCFunction)PySocketSock_connect_ex, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1256 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
1257 #ifndef NO_DUP
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1258 {"dup", (PyCFunction)PySocketSock_dup, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1259 dup_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1260 #endif
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1261 {"fileno", (PyCFunction)PySocketSock_fileno, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1262 fileno_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1263 #ifdef HAVE_GETPEERNAME
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1264 {"getpeername", (PyCFunction)PySocketSock_getpeername, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1265 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
1266 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1267 {"getsockname", (PyCFunction)PySocketSock_getsockname, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1268 getsockname_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1269 {"getsockopt", (PyCFunction)PySocketSock_getsockopt, 1,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1270 getsockopt_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1271 {"listen", (PyCFunction)PySocketSock_listen, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1272 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
1273 #ifndef NO_DUP
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1274 {"makefile", (PyCFunction)PySocketSock_makefile, 1,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1275 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
1276 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1277 {"recv", (PyCFunction)PySocketSock_recv, 1,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1278 recv_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1279 {"recvfrom", (PyCFunction)PySocketSock_recvfrom, 1,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1280 recvfrom_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1281 {"send", (PyCFunction)PySocketSock_send, 1,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1282 send_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1283 {"sendto", (PyCFunction)PySocketSock_sendto, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1284 sendto_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1285 {"setblocking", (PyCFunction)PySocketSock_setblocking, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1286 setblocking_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1287 {"setsockopt", (PyCFunction)PySocketSock_setsockopt, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1288 setsockopt_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1289 {"shutdown", (PyCFunction)PySocketSock_shutdown, 0,
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1290 shutdown_doc},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1291 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1292 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1293
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1294
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1295 /* 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
1296 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1297
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1298 static void
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1299 BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1300 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1301 (void) close(s->sock_fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1302 PyMem_DEL(s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1303 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1304
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1305
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1306 /* 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
1307
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1308 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1309 BUILD_FUNC_DEF_2(PySocketSock_getattr,PySocketSockObject *,s, char *,name)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1310 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1311 return Py_FindMethod(PySocketSock_methods, (PyObject *) s, name);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1312 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1313
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1314
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1315 static PyObject *
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1316 BUILD_FUNC_DEF_1(PySocketSock_repr,PySocketSockObject *,s)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1317 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1318 char buf[512];
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1319 sprintf(buf,
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1320 "<socket object, fd=%d, family=%d, type=%d, protocol=%d>",
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1321 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
1322 return PyString_FromString(buf);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1323 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1324
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1325
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
1326 /* 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
1327
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1328 static PyTypeObject PySocketSock_Type = {
3594
564912267290 Windows/PC changes
Guido van Rossum <guido@python.org>
parents: 3421
diff changeset
1329 PyObject_HEAD_INIT(0) /* Must fill in type value later */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1330 0,
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1331 "socket",
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1332 sizeof(PySocketSockObject),
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1333 0,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1334 (destructor)PySocketSock_dealloc, /*tp_dealloc*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1335 0, /*tp_print*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1336 (getattrfunc)PySocketSock_getattr, /*tp_getattr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1337 0, /*tp_setattr*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1338 0, /*tp_compare*/
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1339 (reprfunc)PySocketSock_repr, /*tp_repr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1340 0, /*tp_as_number*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1341 0, /*tp_as_sequence*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1342 0, /*tp_as_mapping*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1343 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1344
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1345
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1346 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1347
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1348 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1349 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1350 BUILD_FUNC_DEF_2(PySocket_gethostname,PyObject *,self, PyObject *,args)
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1351 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1352 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1353 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1354 if (!PyArg_NoArgs(args))
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1355 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1356 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1357 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1358 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1359 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1360 return PySocket_Err();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1361 buf[sizeof buf - 1] = '\0';
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1362 return PyString_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1363 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1364
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1365 static char gethostname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1366 "gethostname() -> string\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1367 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1368 Return the current host name.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1369
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1370
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1371 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1372
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1373 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1374 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1375 BUILD_FUNC_DEF_2(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
1376 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1377 char *name;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1378 struct sockaddr_in addrbuf;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1379 if (!PyArg_Parse(args, "s", &name))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1380 return NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1381 if (setipaddr(name, &addrbuf) < 0)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1382 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1383 return makeipaddr(&addrbuf);
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1384 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1385
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1386 static char gethostbyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1387 "gethostbyname(host) -> address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1388 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1389 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
1390
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1391
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1392 /* 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
1393
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1394 static PyObject *
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1395 gethost_common(h, addr)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1396 struct hostent *h;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1397 struct sockaddr_in *addr;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1398 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1399 char **pch;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1400 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
1401 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
1402 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
1403 PyObject *tmp;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1404 if (h == NULL) {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1405 #ifdef HAVE_HSTRERROR
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1406 /* Let's get real error message to return */
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1407 extern int h_errno;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1408 PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1409 #else
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1410 PyErr_SetString(PySocket_Error, "host not found");
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1411 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1412 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1413 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1414 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
1415 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1416 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
1417 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1418 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
1419 int status;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1420 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
1421 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
1422 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1423 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
1424 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
1425 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1426 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1427 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1428 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
1429 int status;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1430 memcpy((char *) &addr->sin_addr, *pch, h->h_length);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1431 tmp = makeipaddr(addr);
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1432 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
1433 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1434 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
1435 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
1436 if (status)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1437 goto err;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1438 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1439 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
1440 err:
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1441 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
1442 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
1443 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
1444 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1445
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1446
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1447 /* 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
1448
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1449 /*ARGSUSED*/
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1450 static PyObject *
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1451 BUILD_FUNC_DEF_2(PySocket_gethostbyname_ex,PyObject *,self, PyObject *,args)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1452 {
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1453 char *name;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1454 struct hostent *h;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1455 struct sockaddr_in addr;
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1456 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
1457 #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
1458 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
1459 #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
1460 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
1461 #else
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1462 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
1463 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
1464 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1465 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1466 #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
1467 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1468 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1469 #endif /* 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
1470 if (!PyArg_Parse(args, "s", &name))
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1471 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1472 if (setipaddr(name, &addr) < 0)
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1473 return NULL;
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1474 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
1475 #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
1476 #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
1477 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
1478 #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
1479 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
1480 #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
1481 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
1482 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
1483 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
1484 #endif
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1485 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1486 #ifdef USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1487 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
1488 #endif
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1489 h = gethostbyname(name);
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1490 #endif /* HAVE_GETHOSTBYNAME_R */
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1491 Py_END_ALLOW_THREADS
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1492 ret = gethost_common(h, &addr);
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1493 #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
1494 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
1495 #endif
10441
9ba5dffccb1b Jonathan Giddy writes:
Guido van Rossum <guido@python.org>
parents: 10401
diff changeset
1496 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
1497 }
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1498
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1499 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
1500 "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
1501 \n\
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1502 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
1503 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
1504
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1505
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1506 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1507
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1508 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1509 static PyObject *
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1510 BUILD_FUNC_DEF_2(PySocket_gethostbyaddr,PyObject *,self, PyObject *, args)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1511 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1512 struct sockaddr_in addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1513 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1514 struct hostent *h;
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1515 PyObject *ret;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1516 #ifdef HAVE_GETHOSTBYNAME_R
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1517 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
1518 #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
1519 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
1520 #else
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1521 char buf[16384];
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1522 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
1523 int errnop;
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1524 #endif
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1525 #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
1526 int result;
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1527 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1528 #endif /* HAVE_GETHOSTBYNAME_R */
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1529
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1530 if (!PyArg_Parse(args, "s", &ip_num))
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1531 return NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1532 if (setipaddr(ip_num, &addr) < 0)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1533 return NULL;
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1534 Py_BEGIN_ALLOW_THREADS
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1535 #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
1536 #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
1537 result = gethostbyaddr_r((char *)&addr.sin_addr,
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1538 sizeof(addr.sin_addr),
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1539 AF_INET, &hp_allocated, buf, buf_len,
f81db738abd9 Patch by Rob Riggs for Linux -- glibc2 has a different argument
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
1540 &h, &errnop);
10453
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1541 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1542 h = gethostbyaddr_r((char *)&addr.sin_addr,
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1543 sizeof(addr.sin_addr),
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1544 AF_INET,
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1545 &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
1546 #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
1547 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
1548 result = gethostbyaddr_r((char *)&addr.sin_addr,
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1549 sizeof(addr.sin_addr),
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1550 AF_INET, &hp_allocated, &data);
5b54fa775e55 Vladimir Marangozov implements the AIX 3-arg gethostbyname_r code.
Guido van Rossum <guido@python.org>
parents: 10442
diff changeset
1551 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
1552 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
1553 #else /* not HAVE_GETHOSTBYNAME_R */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1554 #ifdef USE_GETHOSTBYNAME_LOCK
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1555 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
1556 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1557 h = gethostbyaddr((char *)&addr.sin_addr,
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1558 sizeof(addr.sin_addr),
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1559 AF_INET);
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1560 #endif /* HAVE_GETHOSTBYNAME_R */
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1561 Py_END_ALLOW_THREADS
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1562 ret = gethost_common(h, &addr);
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1563 #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
1564 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
1565 #endif
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
1566 return ret;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1567 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1568
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1569 static char gethostbyaddr_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1570 "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
1571 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1572 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
1573 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
1574
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1575
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1576 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1577 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
1578 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
1579
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1580 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1581 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1582 BUILD_FUNC_DEF_2(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
1583 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1584 char *name, *proto;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1585 struct servent *sp;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1586 if (!PyArg_Parse(args, "(ss)", &name, &proto))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1587 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1588 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1589 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1590 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1591 if (sp == NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1592 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
1593 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1594 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1595 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
1596 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1597
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1598 static char getservbyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1599 "getservbyname(servicename, protocolname) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1600 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1601 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
1602 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
1603
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1604
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1605 /* Python interface to getprotobyname(name).
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1606 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
1607 already known or not useful (like the list of aliases). */
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1608
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1609 /*ARGSUSED*/
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1610 static PyObject *
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1611 BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args)
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1612 {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1613 char *name;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1614 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
1615 #ifdef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1616 /* 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
1617 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
1618 return NULL;
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
1619 #else
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1620 if (!PyArg_Parse(args, "s", &name))
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1621 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1622 Py_BEGIN_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1623 sp = getprotobyname(name);
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1624 Py_END_ALLOW_THREADS
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1625 if (sp == NULL) {
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1626 PyErr_SetString(PySocket_Error, "protocol not found");
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1627 return NULL;
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1628 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1629 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
1630 #endif
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1631 }
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1632
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1633 static char getprotobyname_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1634 "getprotobyname(name) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1635 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1636 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
1637
4782
2426a220664b Added getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents: 4651
diff changeset
1638
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1639 /* 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
1640 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
1641 Return a new socket object. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1642
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1643 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1644 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1645 BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1646 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1647 PySocketSockObject *s;
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1648 #ifdef MS_WINDOWS
3672
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1649 SOCKET fd;
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1650 #else
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1651 int fd;
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1652 #endif
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
1653 int family, type, proto = 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
1654 if (!PyArg_ParseTuple(args, "ii|i", &family, &type, &proto))
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
1655 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1656 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1657 fd = socket(family, type, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1658 Py_END_ALLOW_THREADS
3738
ce74bba8a6a6 Slightly different Windows ifdefs
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1659 #ifdef MS_WINDOWS
3672
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1660 if (fd == INVALID_SOCKET)
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1661 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1662 if (fd < 0)
3672
cec27c93b5cb more changes for Windows, sigh
Guido van Rossum <guido@python.org>
parents: 3666
diff changeset
1663 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1664 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1665 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
1666 /* 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
1667 file descriptor again! */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1668 if (s == NULL)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1669 (void) close(fd);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1670 /* 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
1671 do the work. */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1672 #ifdef SIGPIPE
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1673 (void) signal(SIGPIPE, SIG_IGN);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1674 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1675 return (PyObject *) s;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1676 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1677
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1678 static char socket_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1679 "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
1680 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1681 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
1682 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
1683 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
1684 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
1685 specifying the default protocol.";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1686
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1687
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1688 #ifndef NO_DUP
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1689 /* 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
1690 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
1691 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
1692
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1693 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1694 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1695 BUILD_FUNC_DEF_2(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
1696 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1697 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
1698 int fd, family, type, proto = 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
1699 if (!PyArg_ParseTuple(args, "iii|i", &fd, &family, &type, &proto))
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
1700 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
1701 /* 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
1702 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
1703 if (fd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1704 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1705 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
1706 /* 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
1707 do the work. */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1708 #ifdef SIGPIPE
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1709 (void) signal(SIGPIPE, SIG_IGN);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1710 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1711 return (PyObject *) s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1712 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1713
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1714 static char fromfd_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1715 "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
1716 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1717 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
1718 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
1719
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1720 #endif /* NO_DUP */
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1721
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1722
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1723 static PyObject *
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1724 BUILD_FUNC_DEF_2(PySocket_ntohs, PyObject *, self, PyObject *, args)
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1725 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1726 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1727
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1728 if (!PyArg_Parse(args, "i", &x1)) {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1729 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1730 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1731 x2 = (int)ntohs((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1732 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1733 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1734
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1735 static char ntohs_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1736 "ntohs(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1737 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1738 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
1739
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1740
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1741 static PyObject *
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1742 BUILD_FUNC_DEF_2(PySocket_ntohl, PyObject *, self, PyObject *, args)
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1743 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1744 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1745
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1746 if (!PyArg_Parse(args, "i", &x1)) {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1747 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1748 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1749 x2 = ntohl(x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1750 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1751 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1752
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1753 static char ntohl_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1754 "ntohl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1755 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1756 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
1757
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1758
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1759 static PyObject *
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1760 BUILD_FUNC_DEF_2(PySocket_htons, PyObject *, self, PyObject *, args)
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1761 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1762 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1763
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1764 if (!PyArg_Parse(args, "i", &x1)) {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1765 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1766 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1767 x2 = (int)htons((short)x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1768 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1769 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1770
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1771 static char htons_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1772 "htons(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1773 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1774 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
1775
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1776
3673
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1777 static PyObject *
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1778 BUILD_FUNC_DEF_2(PySocket_htonl, PyObject *, self, PyObject *, args)
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1779 {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1780 int x1, x2;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1781
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1782 if (!PyArg_Parse(args, "i", &x1)) {
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1783 return NULL;
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1784 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1785 x2 = htonl(x1);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1786 return PyInt_FromLong(x2);
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1787 }
f6ace61c3dfe ntohs, ntohl, htons, htonl -- thanks to Lance
Guido van Rossum <guido@python.org>
parents: 3672
diff changeset
1788
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1789 static char htonl_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1790 "htonl(integer) -> integer\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1791 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1792 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
1793
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1794 /*
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1795 * 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
1796 *
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1797 * 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
1798 *
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1799 */
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1800
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1801 static char inet_aton_doc[] =
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1802 "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
1803 \n\
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1804 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
1805 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
1806
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1807 static PyObject*
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1808 BUILD_FUNC_DEF_2(PySocket_inet_aton, PyObject *, self, PyObject *, args)
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1809 {
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1810 #ifndef MS_WINDOWS
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1811 char *ip_addr;
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1812 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
1813 int err;
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1814
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1815 if (!PyArg_Parse(args, "s", &ip_addr)) {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1816 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
1817 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1818
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1819 err = inet_aton(ip_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
1820
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1821 if (err == 0) { /* invalid address */
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1822 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
1823 "illegal IP address string passed to inet_aton");
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1824 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
1825 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1826
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1827 return PyString_FromStringAndSize((char *) &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
1828 sizeof(packed_addr));
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1829 #else /* MS_WINDOWS */
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1830 /* 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
1831 char *ip_addr;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1832 long packed_addr;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1833
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1834 if (!PyArg_Parse(args, "s", &ip_addr)) {
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1835 return NULL;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1836 }
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1837
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1838 packed_addr = inet_addr(ip_addr);
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1839
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1840 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
1841 PyErr_SetString(PySocket_Error,
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1842 "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
1843 return NULL;
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1844 }
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1845
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1846 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
1847 sizeof(packed_addr));
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1848 #endif /* MS_WINDOWS */
11217
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1849 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1850
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1851 static char inet_ntoa_doc[] =
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1852 "inet_aton(packed_ip) -> ip_address_string\n\
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1853 \n\
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1854 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
1855
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1856 static PyObject*
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1857 BUILD_FUNC_DEF_2(PySocket_inet_ntoa, PyObject *, self, PyObject *, args)
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1858 {
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1859 char *packed_str;
11219
2d7331f4dfe3 Port inet_ntoa and inet_aton to Windows:
Guido van Rossum <guido@python.org>
parents: 11217
diff changeset
1860 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
1861 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
1862
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1863 if (!PyArg_Parse(args, "s#", &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
1864 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
1865 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1866
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1867 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
1868 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
1869 "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
1870 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
1871 }
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1872
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1873 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
1874
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1875 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
1876 }
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1877
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1878 /* 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
1879
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1880 static PyMethodDef PySocket_methods[] = {
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1881 {"gethostbyname", PySocket_gethostbyname, 0, gethostbyname_doc},
8821
a1c16a3fa7db Added gethostbyname_ex(), which returns the same kind of data as
Guido van Rossum <guido@python.org>
parents: 8631
diff changeset
1882 {"gethostbyname_ex", PySocket_gethostbyname_ex, 0, ghbn_ex_doc},
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1883 {"gethostbyaddr", PySocket_gethostbyaddr, 0, gethostbyaddr_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1884 {"gethostname", PySocket_gethostname, 0, gethostname_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1885 {"getservbyname", PySocket_getservbyname, 0, getservbyname_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1886 {"getprotobyname", PySocket_getprotobyname, 0,getprotobyname_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1887 {"socket", PySocket_socket, 1, 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
1888 #ifndef NO_DUP
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1889 {"fromfd", PySocket_fromfd, 1, 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
1890 #endif
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1891 {"ntohs", PySocket_ntohs, 0, ntohs_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1892 {"ntohl", PySocket_ntohl, 0, ntohl_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1893 {"htons", PySocket_htons, 0, htons_doc},
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
1894 {"htonl", PySocket_htonl, 0, htonl_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
1895 {"inet_aton", PySocket_inet_aton, 0, inet_aton_doc},
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
1896 {"inet_ntoa", PySocket_inet_ntoa, 0, inet_ntoa_doc},
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1897 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1898 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1899
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1900
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1901 /* 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
1902 *
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
1903 * 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
1904 */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1905 static void
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1906 BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1907 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1908 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
1909 if (!v || PyDict_SetItemString(d, name, v))
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
1910 PyErr_Clear();
4871
a7159ba0e45d Check of return values and proper error handling.
Barry Warsaw <barry@python.org>
parents: 4783
diff changeset
1911
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
1912 Py_XDECREF(v);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1913 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1914
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1915
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1916 #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
1917
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
1918 /* 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
1919
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
1920 static void
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
1921 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
1922 {
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
1923 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
1924 }
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
1925
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
1926 static int
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
1927 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
1928 {
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
1929 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
1930 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
1931 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
1932 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
1933 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
1934 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
1935 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
1936 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
1937 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
1938 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
1939 "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
1940 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
1941 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
1942 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
1943 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
1944 "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
1945 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
1946 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
1947 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
1948 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
1949 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
1950 }
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
1951 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
1952 }
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
1953
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
1954 #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
1955
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1956 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1957
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1958 /* Additional initialization and cleanup for OS/2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1959
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1960 static void
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1961 OS2cleanup()
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1962 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1963 /* No cleanup is necessary for OS/2 Sockets */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1964 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1965
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1966 static int
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1967 OS2init()
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1968 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1969 char reason[64];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1970 int rc = sock_init();
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1971
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1972 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
1973 atexit(OS2cleanup);
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1974 return 1; /* Indicate Success */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1975 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1976
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1977 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
1978 PyErr_SetString(PyExc_ImportError, reason);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1979
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1980 return 0; /* Indicate Failure */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1981 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1982
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1983 #endif /* PYOS_OS2 */
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1984
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
1985
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1986 /* Initialize this module.
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1987 * 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
1988 * 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
1989 * defined.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1990 *
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1991 * 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
1992 * 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
1993 * which implements some missing functionality (such as makefile(),
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1994 * 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
1995 * ImportError exception if initialization of WINSOCK fails. When
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1996 * 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
1997 * scheduled to be made at exit time.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1998 *
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
1999 * 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
2000 * "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
2001 * 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
2002 * operating system's filesystem layer.
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2003 */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
2004
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2005 static char module_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2006 "This module provides socket operations and some related functions.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2007 On Unix, it supports IP (Internet Protocol) and Unix domain sockets.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2008 On other systems, it only supports IP.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2009 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2010 Functions:\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2011 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2012 socket() -- create a new socket object\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2013 fromfd() -- create a socket object from an open file descriptor (*)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2014 gethostname() -- return the current hostname\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2015 gethostbyname() -- map a hostname to its IP number\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2016 gethostbyaddr() -- map an IP number or hostname to DNS info\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2017 getservbyname() -- map a service name and a protocol name to a port number\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2018 getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2019 ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2020 htons(), htonl() -- convert 16, 32 bit int from host to network byte order\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
2021 inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format\n\
f406e78ec10b Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
Guido van Rossum <guido@python.org>
parents: 11182
diff changeset
2022 inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)\n\
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2023 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2024 (*) not available on all platforms!)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2025 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2026 Special objects:\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2027 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2028 SocketType -- type object for socket objects\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2029 error -- exception raised for I/O errors\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2030 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2031 Integer constants:\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2032 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2033 AF_INET, AF_UNIX -- socket domains (first argument to socket() call)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2034 SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2035 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2036 Many other constants may be defined; these may be used in calls to\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2037 the setsockopt() and getsockopt() methods.\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2038 ";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2039
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2040 static char sockettype_doc[] =
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2041 "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
2042 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2043 Methods:\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2044 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2045 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
2046 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
2047 close() -- close the socket\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2048 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
2049 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
2050 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
2051 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
2052 getpeername() -- return remote address (*)\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2053 getsockname() -- return local address\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2054 getsockopt() -- get socket options\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2055 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
2056 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
2057 recv() -- receive data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2058 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
2059 send() -- send data\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2060 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
2061 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
2062 setsockopt() -- set socket options\n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2063 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
2064 \n\
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2065 (*) not available on all platforms!)";
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2066
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 9307
diff changeset
2067 DL_EXPORT(void)
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2068 #if defined(MS_WINDOWS) || defined(PYOS_OS2) || defined(__BEOS__)
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
2069 init_socket()
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
2070 #else
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2071 initsocket()
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
2072 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2073 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2074 PyObject *m, *d;
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3700
diff changeset
2075 #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
2076 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
2077 return;
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2078 m = Py_InitModule3("_socket", PySocket_methods, module_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
2079 #else
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2080 #if defined(__TOS_OS2__)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2081 if (!OS2init())
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6618
diff changeset
2082 return;
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2083 m = Py_InitModule3("_socket", PySocket_methods, module_doc);
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2084 #else
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2085 #if defined(__BEOS__)
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2086 m = Py_InitModule3("_socket", PySocket_methods, module_doc);
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2087 #else
8631
d86733676815 Added copious docstrings, plus two minor layout tweaks.
Guido van Rossum <guido@python.org>
parents: 8439
diff changeset
2088 m = Py_InitModule3("socket", PySocket_methods, module_doc);
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2089 #endif /* __BEOS__ */
6718
32f2eda2946c Left-aligned preprocessor directives and changed C++ comments to C
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
2090 #endif
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
2091 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2092 d = PyModule_GetDict(m);
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2093 PySocket_Error = PyErr_NewException("socket.error", NULL, NULL);
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2094 if (PySocket_Error == NULL)
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2095 return;
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2096 PyDict_SetItemString(d, "error", PySocket_Error);
5572
b231855a9474 Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents: 5534
diff changeset
2097 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
2098 PySocketSock_Type.tp_doc = sockettype_doc;
5572
b231855a9474 Add socket.socket_type, as discussed on c.l.p.
Guido van Rossum <guido@python.org>
parents: 5534
diff changeset
2099 Py_INCREF(&PySocketSock_Type);
5697
88b0b2a3aab5 socket_type -> SocketType
Guido van Rossum <guido@python.org>
parents: 5572
diff changeset
2100 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
2101 (PyObject *)&PySocketSock_Type) != 0)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5697
diff changeset
2102 return;
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2103
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2104 /* 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
2105 #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
2106 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
2107 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2108 insint(d, "AF_INET", AF_INET);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
2109 #ifdef AF_UNIX
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2110 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
2111 #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
2112 #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
2113 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
2114 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2115 #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
2116 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
2117 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2118 #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
2119 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
2120 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2121 #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
2122 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
2123 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2124 #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
2125 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
2126 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2127 #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
2128 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
2129 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2130 #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
2131 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
2132 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2133 #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
2134 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
2135 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2136 #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
2137 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
2138 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2139
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2140 /* Socket types */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2141 insint(d, "SOCK_STREAM", SOCK_STREAM);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2142 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
2143 #ifndef __BEOS__
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8821
diff changeset
2144 /* We have incomplete socket support. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2145 insint(d, "SOCK_RAW", SOCK_RAW);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2146 insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2147 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
2148 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2149
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2150 #ifdef SO_DEBUG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2151 insint(d, "SO_DEBUG", SO_DEBUG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2152 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2153 #ifdef SO_ACCEPTCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2154 insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2155 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2156 #ifdef SO_REUSEADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2157 insint(d, "SO_REUSEADDR", SO_REUSEADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2158 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2159 #ifdef SO_KEEPALIVE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2160 insint(d, "SO_KEEPALIVE", SO_KEEPALIVE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2161 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2162 #ifdef SO_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2163 insint(d, "SO_DONTROUTE", SO_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2164 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2165 #ifdef SO_BROADCAST
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2166 insint(d, "SO_BROADCAST", SO_BROADCAST);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2167 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2168 #ifdef SO_USELOOPBACK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2169 insint(d, "SO_USELOOPBACK", SO_USELOOPBACK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2170 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2171 #ifdef SO_LINGER
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2172 insint(d, "SO_LINGER", SO_LINGER);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2173 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2174 #ifdef SO_OOBINLINE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2175 insint(d, "SO_OOBINLINE", SO_OOBINLINE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2176 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2177 #ifdef SO_REUSEPORT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2178 insint(d, "SO_REUSEPORT", SO_REUSEPORT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2179 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2180 #ifdef SO_SNDBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2181 insint(d, "SO_SNDBUF", SO_SNDBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2182 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2183 #ifdef SO_RCVBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2184 insint(d, "SO_RCVBUF", SO_RCVBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2185 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2186 #ifdef SO_SNDLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2187 insint(d, "SO_SNDLOWAT", SO_SNDLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2188 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2189 #ifdef SO_RCVLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2190 insint(d, "SO_RCVLOWAT", SO_RCVLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2191 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2192 #ifdef SO_SNDTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2193 insint(d, "SO_SNDTIMEO", SO_SNDTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2194 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2195 #ifdef SO_RCVTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2196 insint(d, "SO_RCVTIMEO", SO_RCVTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2197 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2198 #ifdef SO_ERROR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2199 insint(d, "SO_ERROR", SO_ERROR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2200 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2201 #ifdef SO_TYPE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2202 insint(d, "SO_TYPE", SO_TYPE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2203 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2204
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2205 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2206 #ifdef SOMAXCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2207 insint(d, "SOMAXCONN", SOMAXCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2208 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2209 insint(d, "SOMAXCONN", 5); /* Common value */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2210 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2211
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2212 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2213 #ifdef MSG_OOB
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2214 insint(d, "MSG_OOB", MSG_OOB);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2215 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2216 #ifdef MSG_PEEK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2217 insint(d, "MSG_PEEK", MSG_PEEK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2218 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2219 #ifdef MSG_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2220 insint(d, "MSG_DONTROUTE", MSG_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2221 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2222 #ifdef MSG_EOR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2223 insint(d, "MSG_EOR", MSG_EOR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2224 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2225 #ifdef MSG_TRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2226 insint(d, "MSG_TRUNC", MSG_TRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2227 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2228 #ifdef MSG_CTRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2229 insint(d, "MSG_CTRUNC", MSG_CTRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2230 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2231 #ifdef MSG_WAITALL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2232 insint(d, "MSG_WAITALL", MSG_WAITALL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2233 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2234 #ifdef MSG_BTAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2235 insint(d, "MSG_BTAG", MSG_BTAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2236 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2237 #ifdef MSG_ETAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2238 insint(d, "MSG_ETAG", MSG_ETAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2239 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2240
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2241 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2242 #ifdef SOL_SOCKET
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2243 insint(d, "SOL_SOCKET", SOL_SOCKET);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2244 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2245 #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
2246 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
2247 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2248 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
2249 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2250 #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
2251 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
2252 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2253 #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
2254 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
2255 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2256 #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
2257 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
2258 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2259 #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
2260 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
2261 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2262 #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
2263 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
2264 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2265 #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
2266 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
2267 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2268 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
2269 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2270 #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
2271 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
2272 #else
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2273 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
2274 #endif
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2275 #ifdef IPPROTO_IP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2276 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
2277 #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
2278 insint(d, "IPPROTO_IP", 0);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2279 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2280 #ifdef IPPROTO_ICMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2281 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
2282 #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
2283 insint(d, "IPPROTO_ICMP", 1);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2284 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2285 #ifdef IPPROTO_IGMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2286 insint(d, "IPPROTO_IGMP", IPPROTO_IGMP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2287 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2288 #ifdef IPPROTO_GGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2289 insint(d, "IPPROTO_GGP", IPPROTO_GGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2290 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2291 #ifdef IPPROTO_TCP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2292 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
2293 #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
2294 insint(d, "IPPROTO_TCP", 6);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2295 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2296 #ifdef IPPROTO_EGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2297 insint(d, "IPPROTO_EGP", IPPROTO_EGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2298 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2299 #ifdef IPPROTO_PUP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2300 insint(d, "IPPROTO_PUP", IPPROTO_PUP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2301 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2302 #ifdef IPPROTO_UDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2303 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
2304 #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
2305 insint(d, "IPPROTO_UDP", 17);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2306 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2307 #ifdef IPPROTO_IDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2308 insint(d, "IPPROTO_IDP", IPPROTO_IDP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2309 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2310 #ifdef IPPROTO_HELLO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2311 insint(d, "IPPROTO_HELLO", IPPROTO_HELLO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2312 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2313 #ifdef IPPROTO_ND
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2314 insint(d, "IPPROTO_ND", IPPROTO_ND);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2315 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2316 #ifdef IPPROTO_TP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2317 insint(d, "IPPROTO_TP", IPPROTO_TP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2318 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2319 #ifdef IPPROTO_XTP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2320 insint(d, "IPPROTO_XTP", IPPROTO_XTP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2321 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2322 #ifdef IPPROTO_EON
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2323 insint(d, "IPPROTO_EON", IPPROTO_EON);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2324 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2325 #ifdef IPPROTO_BIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2326 insint(d, "IPPROTO_BIP", IPPROTO_BIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2327 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2328 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2329 #ifdef IPPROTO_RAW
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2330 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
2331 #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
2332 insint(d, "IPPROTO_RAW", 255);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2333 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2334 #ifdef IPPROTO_MAX
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2335 insint(d, "IPPROTO_MAX", IPPROTO_MAX);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2336 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2337
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2338 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2339 #ifdef IPPORT_RESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2340 insint(d, "IPPORT_RESERVED", IPPORT_RESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2341 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2342 insint(d, "IPPORT_RESERVED", 1024);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2343 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2344 #ifdef IPPORT_USERRESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2345 insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2346 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2347 insint(d, "IPPORT_USERRESERVED", 5000);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2348 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2349
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2350 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2351 #ifdef INADDR_ANY
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2352 insint(d, "INADDR_ANY", INADDR_ANY);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2353 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2354 insint(d, "INADDR_ANY", 0x00000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2355 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2356 #ifdef INADDR_BROADCAST
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2357 insint(d, "INADDR_BROADCAST", INADDR_BROADCAST);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2358 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2359 insint(d, "INADDR_BROADCAST", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2360 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2361 #ifdef INADDR_LOOPBACK
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2362 insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2363 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2364 insint(d, "INADDR_LOOPBACK", 0x7F000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2365 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2366 #ifdef INADDR_UNSPEC_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2367 insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2368 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2369 insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2370 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2371 #ifdef INADDR_ALLHOSTS_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2372 insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2373 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2374 insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2375 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2376 #ifdef INADDR_MAX_LOCAL_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2377 insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2378 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2379 insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2380 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2381 #ifdef INADDR_NONE
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2382 insint(d, "INADDR_NONE", INADDR_NONE);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2383 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2384 insint(d, "INADDR_NONE", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2385 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
2386
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2387 /* IP [gs]etsockopt options */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2388 #ifdef IP_OPTIONS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2389 insint(d, "IP_OPTIONS", IP_OPTIONS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2390 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2391 #ifdef IP_HDRINCL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2392 insint(d, "IP_HDRINCL", IP_HDRINCL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2393 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2394 #ifdef IP_TOS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2395 insint(d, "IP_TOS", IP_TOS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2396 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2397 #ifdef IP_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2398 insint(d, "IP_TTL", IP_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2399 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2400 #ifdef IP_RECVOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2401 insint(d, "IP_RECVOPTS", IP_RECVOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2402 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2403 #ifdef IP_RECVRETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2404 insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2405 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2406 #ifdef IP_RECVDSTADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2407 insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2408 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2409 #ifdef IP_RETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2410 insint(d, "IP_RETOPTS", IP_RETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2411 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2412 #ifdef IP_MULTICAST_IF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2413 insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2414 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2415 #ifdef IP_MULTICAST_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2416 insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2417 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2418 #ifdef IP_MULTICAST_LOOP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2419 insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2420 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2421 #ifdef IP_ADD_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2422 insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2423 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2424 #ifdef IP_DROP_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2425 insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
2426 #endif
11182
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2427 #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
2428 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
2429 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2430 #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
2431 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
2432 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2433 #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
2434 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
2435 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2436
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2437 /* TCP options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2438 #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
2439 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
2440 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2441 #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
2442 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
2443 #endif
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2444
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2445 /* IPX options */
35e0d03f2b02 Patch by Marc-Andre Lemburg to add a bunch more symbols.
Guido van Rossum <guido@python.org>
parents: 10579
diff changeset
2446 #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
2447 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
2448 #endif
7942
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2449
ee2aaa2f722a Threading speedup patches by Christopher Lindblad <cjl@infoseek.com>.
Guido van Rossum <guido@python.org>
parents: 6718
diff changeset
2450 /* Initialize gethostbyname lock */
10442
9184c9e108f9 Clean up pass for the previous patches.
Guido van Rossum <guido@python.org>
parents: 10441
diff changeset
2451 #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
2452 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
2453 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2454 }