annotate Modules/socketmodule.c @ 3044:7e7bb00a0a2e legacy-trunk

Added functionality: locate CW projects, copy them, empty them and binhex them.
author Jack Jansen <jack.jansen@cwi.nl>
date Thu, 31 Aug 1995 13:47:14 +0000
parents 37c48fde61b8
children 7ddfb629ac3f
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
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
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Socket module */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 /*
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 This module provides an interface to Berkeley socket IPC.
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 Limitations:
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
32 - 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
33 - no read/write operations (use send/recv or makefile instead)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
35 Module interface:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
37 - 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
38 - 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
39 - 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
40 - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com')
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
41 - 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
42 - socket.socket(family, type [, proto]) --> new socket object
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
43 - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h>
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 - an Internet socket address is a pair (hostname, port)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 where hostname can be anything recognized by gethostbyname()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 (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
47 - 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
48 - a UNIX domain socket address is a string specifying the pathname
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
50 Socket methods:
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
52 - s.accept() --> new socket object, sockaddr
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
53 - s.bind(sockaddr) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
54 - s.close() --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
55 - s.connect(sockaddr) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
56 - s.fileno() --> file descriptor
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
57 - s.getpeername() --> sockaddr
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
58 - s.getsockname() --> sockaddr
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
59 - s.getsockopt(level, optname[, buflen]) --> int or string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
60 - s.listen(backlog) --> None
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
61 - s.makefile([mode[, bufsize]]) --> file object
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
62 - s.recv(buflen [,flags]) --> string
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
63 - 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
64 - s.send(string [,flags]) --> nbytes
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
65 - s.sendto(string, [flags,] sockaddr) --> nbytes
2565
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
66 - s.setblocking(0 | 1) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
67 - s.setsockopt(level, optname, value) --> None
912813d573b4 fixed up comments describing interface
Guido van Rossum <guido@python.org>
parents: 2532
diff changeset
68 - s.shutdown(how) --> None
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
69 - 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
70
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 */
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
73 #include "Python.h"
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
75 #include <sys/types.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
76 #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
77
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
78 #include <signal.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
79 #ifndef NT
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
80 #include <netdb.h>
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 #include <sys/socket.h>
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 #include <netinet/in.h>
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
83 #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
84 #else
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
85 #include <winsock.h>
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
86 #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
87 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
88 #ifdef HAVE_SYS_UN_H
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 #include <sys/un.h>
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
90 #else
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
91 #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
92 #endif
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
93
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
94 #ifndef O_NDELAY
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
95 #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
96 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
97
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
98
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
99 /* 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
100 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
101 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
102 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
103 */
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
104 #ifdef NT
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
105 /* 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
106 #define close closesocket
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
107 #define NO_DUP /* Define for NT 3.1, Win3.1 and Win95, Undefine for NT3.5 */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
108 #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
109 #endif
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
110
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
111 #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
112 #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
113 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
114
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
115 #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
116 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
117
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
118 #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
119 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
120
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
121 #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
122 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
123
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
124 #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
125 #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
126 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
127 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
128
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
129 #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
130 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
131 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
132 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
133
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
134 #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
135 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
136 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
137 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
138 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
139
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
140 #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
141 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
142 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
143 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
144 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
145 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
146
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
147 #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
148
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
149 /* 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
150 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
151
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
152 static PyObject *PySocket_Error;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
153
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
154
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
155 /* 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
156 and return a NULL pointer from a function. */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
158 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
159 PySocket_Err()
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 {
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
161 #ifdef NT
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
162 if (WSAGetLastError()) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
163 PyObject *v;
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
164 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
165 if (v != NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
166 PyErr_SetObject(PySocket_Error, v);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
167 Py_DECREF(v);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
168 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
169 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
170 }
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
171 else
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
172 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
173 return PyErr_SetFromErrno(PySocket_Error);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
176
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
177 /* 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
178 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
179 arguments properly. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
180
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 typedef struct {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
182 PyObject_HEAD
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
183 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
184 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
185 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
186 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
187 union sock_addr {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
188 struct sockaddr_in in;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
189 #ifdef AF_UNIX
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
190 struct sockaddr_un un;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
191 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
192 } sock_addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
193 } PySocketSockObject;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
195
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
196 /* 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
197 The Socktype variable contains pointers to various functions,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
198 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
199 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
200
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
201 staticforward PyTypeObject PySocketSock_Type;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
202
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
203
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
204 /* Create a new socket object.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
205 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
206 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
207 in NEWOBJ()). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
208
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
209 static PySocketSockObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
210 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
211 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
212 PySocketSockObject *s;
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
213 s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 if (s != NULL) {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 s->sock_fd = fd;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 s->sock_family = family;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 s->sock_type = type;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 s->sock_proto = proto;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 return s;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
223
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
224 /* 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
225 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
226 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
227 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
228 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
229
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 static int
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
231 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
232 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 struct hostent *hp;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
234 int d1, d2, d3, d4;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
235 char ch;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
236 #ifdef HAVE_GETHOSTBYNAME_R
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
237 struct hostent hp_allocated;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
238 char buf[1001];
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
239 int buf_len = (sizeof buf) - 1;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
240 int errnop;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
241 #endif /* HAVE_GETHOSTBYNAME_R */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
243 if (name[0] == '\0') {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 addr_ret->sin_addr.s_addr = INADDR_ANY;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 return 4;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
247 if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 addr_ret->sin_addr.s_addr = INADDR_BROADCAST;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 return 4;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
251 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
252 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
253 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
254 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
255 ((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
256 ((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
257 return 4;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
258 }
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
259 #ifdef HAVE_GETHOSTBYNAME_R
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
260 Py_BEGIN_ALLOW_THREADS
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
261 hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
262 Py_END_ALLOW_THREADS
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
263 #else /* not HAVE_GETHOSTBYNAME_R */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
264 hp = gethostbyname(name);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
265 #endif /* HAVE_GETHOSTBYNAME_R */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
266
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 if (hp == NULL) {
2115
7ea369d05c2e better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
268 #ifdef HAVE_HSTRERROR
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
269 /* 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
270 extern int h_errno;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
271 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
272 #else
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
273 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
274 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 return -1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 return hp->h_length;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
281
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
282 /* 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
283 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
284 size numbers). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
285
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
286 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
287 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
288 {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
289 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
290 char buf[100];
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
291 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
292 (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
293 (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
294 return PyString_FromString(buf);
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
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
297
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
298 /* 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
299 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
300 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
301 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
302
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
304 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
305 BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *,addr, int,addrlen)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 {
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
307 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
308 /* No address -- may be recvfrom() from known socket */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
309 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
310 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
311 }
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
312
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
313 switch (addr->sa_family) {
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 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
316 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 struct sockaddr_in *a = (struct sockaddr_in *) addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
318 PyObject *addr = makeipaddr(a);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
319 PyObject *ret = Py_BuildValue("Oi", addr, ntohs(a->sin_port));
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
320 Py_XDECREF(addr);
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
321 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 }
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
323
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
324 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
325 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
326 {
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 struct sockaddr_un *a = (struct sockaddr_un *) addr;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
328 return PyString_FromString(a->sun_path);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
330 #endif /* AF_UNIX */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
331
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
332 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
333
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
334 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
335 PyErr_SetString(PySocket_Error, "return unknown socket address type");
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
336 return NULL;
925
61143bf03b44 Sometimes, recvfrom() returns an empty address; this is not an error.
Guido van Rossum <guido@python.org>
parents: 902
diff changeset
337
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
338 }
294
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
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
341
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
342 /* 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
343 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
344 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
345 through len_ret. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
346
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 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
348 BUILD_FUNC_DEF_4(
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
349 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
350 {
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
351 switch (s->sock_family) {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
352
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
353 #ifdef AF_UNIX
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
354 case AF_UNIX:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
355 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
356 struct sockaddr_un* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
357 char *path;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 int len;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
359 addr = (struct sockaddr_un* )&(s->sock_addr).un;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
360 if (!PyArg_Parse(args, "s#", &path, &len))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
362 if (len > sizeof addr->sun_path) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
363 PyErr_SetString(PySocket_Error, "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
364 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
365 }
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
366 addr->sun_family = AF_UNIX;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
367 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
368 addr->sun_path[len] = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
369 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
370 *len_ret = len + sizeof addr->sun_family;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
373 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
375 case AF_INET:
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
376 {
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
377 struct sockaddr_in* addr;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
378 char *host;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 int port;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
380 addr=(struct sockaddr_in*)&(s->sock_addr).in;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
381 if (!PyArg_Parse(args, "(si)", &host, &port))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
383 if (setipaddr(host, addr) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 return 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
385 addr->sin_family = AF_INET;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
386 addr->sin_port = htons(port);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
387 *addr_ret = (struct sockaddr *) addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
388 *len_ret = sizeof *addr;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 return 1;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
391
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
392 /* More cases here... */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
393
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
394 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
395 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
396 return 0;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
397
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
398 }
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
401
900
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
402 /* 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
403 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
404 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
405
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
406 static int
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
407 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
408 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
409 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
410
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
411 #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
412 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
413 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
414 *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
415 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
416 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
417 #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
418
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
419 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
420 {
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
421 *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
422 return 1;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
423 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
424
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
425 /* 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
426
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
427 default:
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
428 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
429 return 0;
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
430
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
431 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
432 }
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
433
58a7438c2e7e Some UNIX types want the exact size of the address structure
Guido van Rossum <guido@python.org>
parents: 896
diff changeset
434
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
435 /* s.accept() method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
436
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
437 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
438 BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 char addrbuf[256];
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 int addrlen, newfd;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
442 PyObject *sock, *addr, *res;
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
443 if (!PyArg_NoArgs(args))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 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
445 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
446 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
447 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
449 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 if (newfd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
451 return PySocket_Err();
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
452 /* 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
453 to avoid calls to bind() etc. on it. */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
454 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
455 s->sock_family,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
456 s->sock_type,
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
457 s->sock_proto);
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
458 if (sock == NULL)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 close(newfd);
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
460 addr = makesockaddr((struct sockaddr *) addrbuf, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
461 res = Py_BuildValue("OO", sock, addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
462 Py_XDECREF(sock);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
463 Py_XDECREF(addr);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 return res;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
467
1760
48e6b319f3e4 * Modules/{Setup.in,Makefile.pre.in}: renamed some modules to
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
468 #if 0
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
469 /* s.allowbroadcast() method */
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
470 /* XXX obsolete -- will disappear in next release */
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
471
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
472 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
473 BUILD_FUNC_DEF_2(PySocketSock_allowbroadcast,PySocketSockObject *,s, PyObject *,args)
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
474 {
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
475 int flag;
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
476 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
477 if (!PyArg_Parse(args, "i", &flag))
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
478 return NULL;
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
479 res = setsockopt(s->sock_fd, SOL_SOCKET, SO_BROADCAST,
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
480 (ANY *)&flag, sizeof flag);
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
481 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
482 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
483 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
484 return Py_None;
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
485 }
1760
48e6b319f3e4 * Modules/{Setup.in,Makefile.pre.in}: renamed some modules to
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
486 #endif
396
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
487
c262f421a44c Added allowbroadcast()
Guido van Rossum <guido@python.org>
parents: 374
diff changeset
488
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
489 /* 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
490
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
491 static PyObject *
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
492 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
493 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
494 int block;
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
495 int delay_flag;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
496 if (!PyArg_GetInt(args, &block))
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
497 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
498 Py_BEGIN_ALLOW_THREADS
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
499 #ifndef NT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
500 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
501 if (block)
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
502 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
503 else
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
504 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
505 fcntl (s->sock_fd, F_SETFL, delay_flag);
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
506 #else
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
507 block = !block;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
508 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
509 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
510 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
511
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
512 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
513 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
514 }
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
515
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
516
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
517 /* 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
518 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
519 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
520 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
521
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
522 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
523 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
524 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
525 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
526 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
527 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
528 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
529 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
530 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
531
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
532 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
533 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
534 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
535 }
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
536 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
537 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
538 if (!PyArg_Parse(args, "(iis#)", &level, &optname, &buf, &buflen))
1039
6aa0ee14ac2e Made struct a standard built-in module; added string args to {set,get}sockopt;
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
539 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
540 }
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
541 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
542 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
543 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
544 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
545 return Py_None;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
546 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
547
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
548
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
549 /* 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
550 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
551 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
552 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
553
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
554 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
555 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
556 {
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
557 int level;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
558 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
559 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
560 PyObject *buf;
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
561 int buflen;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
562 int flag;
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
563
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
564 if (PyArg_Parse(args, "(ii)", &level, &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
565 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
566 int flagsize = sizeof flag;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
567 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
568 (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
569 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
570 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
571 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
572 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
573 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
574 if (!PyArg_Parse(args, "(iii)", &level, &optname, &buflen))
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
575 return NULL;
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
576 if (buflen <= 0 || buflen > 1024) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
577 PyErr_SetString(PySocket_Error, "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
578 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
579 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
580 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
581 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
582 return NULL;
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
583 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
584 (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
585 if (res < 0) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
586 Py_DECREF(buf);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
587 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
588 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
589 _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
590 return buf;
896
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
591 }
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
592
6459e2f21bf6 Added {get,set}sockopt(). allowbroadcast is now obsolete.
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
593
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
594 /* s.bind(sockaddr) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
595
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
596 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
597 BUILD_FUNC_DEF_2(PySocketSock_bind,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
598 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
601 int res;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 if (!getsockaddrarg(s, args, &addr, &addrlen))
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
604 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
605 res = bind(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
606 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
607 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
608 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
609 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
610 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
612
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
613
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
614 /* s.close() method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
615 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
616 will surely fail. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
617
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
618 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
619 BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
621 if (!PyArg_NoArgs(args))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
623 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 (void) close(s->sock_fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
625 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 s->sock_fd = -1;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
627 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
628 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
630
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
631
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
632 /* s.connect(sockaddr) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
633
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
634 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
635 BUILD_FUNC_DEF_2(PySocketSock_connect,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 struct sockaddr *addr;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
638 int addrlen;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
639 int res;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 if (!getsockaddrarg(s, args, &addr, &addrlen))
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
642 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
643 res = connect(s->sock_fd, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
644 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
645 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
646 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
647 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
648 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
650
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
651
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
652 /* 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
653
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
654 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
655 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
656 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
657 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
658 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
659 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
660 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
661
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents: 900
diff changeset
662
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
663 /* s.getsockname() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
664
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
665 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
666 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
667 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
668 char addrbuf[256];
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
669 int addrlen, res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
670 if (!PyArg_NoArgs(args))
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
671 return NULL;
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
672 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
673 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
674 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
675 res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
676 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
677 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
678 return PySocket_Err();
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
679 return makesockaddr((struct sockaddr *) addrbuf, addrlen);
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
680 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
681
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
682
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
683 #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
684 /* s.getpeername() method */
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
685
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
686 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
687 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
688 {
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
689 char addrbuf[256];
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
690 int addrlen, res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
691 if (!PyArg_NoArgs(args))
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
692 return NULL;
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
693 if (!getsockaddrlen(s, &addrlen))
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
694 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
695 Py_BEGIN_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
696 res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
697 Py_END_ALLOW_THREADS
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
698 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
699 return PySocket_Err();
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
700 return makesockaddr((struct sockaddr *) addrbuf, addrlen);
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
701 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
702 #endif /* HAVE_GETPEERNAME */
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
703
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1039
diff changeset
704
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
705 /* s.listen(n) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
706
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
707 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
708 BUILD_FUNC_DEF_2(PySocketSock_listen,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
709 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
710 int backlog;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
711 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
712 if (!PyArg_GetInt(args, &backlog))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
714 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
715 if (backlog < 1)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
716 backlog = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
717 res = listen(s->sock_fd, backlog);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
718 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
719 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
720 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
721 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
722 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
723 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
724
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
725 #ifndef NO_DUP
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
726 /* s.makefile(mode) method.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
727 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
728 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
729 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
730 of each other.)
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
731 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
732
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
733 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
734 BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 {
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
736 extern int fclose Py_PROTO((FILE *));
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
737 char *mode = "r";
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
738 int bufsize = -1;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
739 int fd;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
740 FILE *fp;
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
741 PyObject *f;
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
742
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
743 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
744 return NULL;
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
745 #ifdef NT
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
746 if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) ||
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
747 ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) {
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
748 #else
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
749 if ((fd = dup(s->sock_fd)) < 0 ||
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
750 (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
751 #endif
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
752 if (fd >= 0)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
753 close(fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
754 return PySocket_Err();
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
755 }
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
756 f = PyFile_FromFile(fp, "<socket>", mode, fclose);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
757 if (f != NULL)
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
758 PyFile_SetBufSize(f, bufsize);
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
759 return f;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
760 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
761 #endif /* NO_DUP */
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
762
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
763 /* 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
764
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
765 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
766 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
767 {
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
768 int len, n, flags;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
769 PyObject *buf;
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
770 flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
771 if (!PyArg_Parse(args, "i", &len)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
772 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
773 if (!PyArg_Parse(args, "(ii)", &len, &flags))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
774 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
775 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
776 buf = PyString_FromStringAndSize((char *) 0, len);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
777 if (buf == NULL)
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
778 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
779 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
780 n = recv(s->sock_fd, PyString_AsString(buf), len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
781 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
782 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
783 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
784 if (_PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 return NULL;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
786 return buf;
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
787 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
788
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
789
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
790 /* 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
791
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
792 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
793 BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
795 char addrbuf[256];
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
796 PyObject *buf, *addr, *ret;
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
797 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
798 flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
799 if (!PyArg_Parse(args, "i", &len)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
800 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
801 if (!PyArg_Parse(args, "(ii)", &len, &flags))
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
802 return NULL;
ac3c80abbf43 * classobject.c: in instance_getattr, don't make a method out of a
Guido van Rossum <guido@python.org>
parents: 1271
diff changeset
803 }
1295
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
804 if (!getsockaddrlen(s, &addrlen))
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
805 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
806 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
807 if (buf == NULL)
4773d5c3b5a4 * socketmodule.c: fix long-standing bug in recvfrom() -- addrlen
Guido van Rossum <guido@python.org>
parents: 1293
diff changeset
808 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
809 Py_BEGIN_ALLOW_THREADS
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
810 n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
811 #ifndef NT
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
812 (ANY *)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
813 #else
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
814 (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
815 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
816 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
818 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
819 if (_PyString_Resize(&buf, n) < 0)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
820 return NULL;
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 1132
diff changeset
821 addr = makesockaddr((struct sockaddr *)addrbuf, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
822 ret = Py_BuildValue("OO", buf, addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
823 Py_XDECREF(addr);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
824 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
825 return ret;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
826 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
827
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
828
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
829 /* 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
830
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
831 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
832 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
833 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
834 char *buf;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
835 int len, n, flags;
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
836 flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
837 if (!PyArg_Parse(args, "s#", &buf, &len)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
838 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
839 if (!PyArg_Parse(args, "(s#i)", &buf, &len, &flags))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
840 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
841 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
842 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
843 n = send(s->sock_fd, buf, len, flags);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
844 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
845 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
846 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
847 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
848 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
849
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
850
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
851 /* 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
852
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
853 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
854 BUILD_FUNC_DEF_2(PySocketSock_sendto,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
855 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
856 PyObject *addro;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
857 char *buf;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
858 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
859 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
860 flags = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
861 if (!PyArg_Parse(args, "(s#O)", &buf, &len, &addro)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
862 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
863 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
864 return NULL;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
865 }
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
866 if (!getsockaddrarg(s, addro, &addr, &addrlen))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
867 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
868 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
869 n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
870 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
871 if (n < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
872 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
873 return PyInt_FromLong((long)n);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
874 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
875
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
876
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
877 /* s.shutdown(how) method */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
878
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
879 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
880 BUILD_FUNC_DEF_2(PySocketSock_shutdown,PySocketSockObject *,s, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
881 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
882 int how;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
883 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
884 if (!PyArg_GetInt(args, &how))
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
885 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
886 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
887 res = shutdown(s->sock_fd, how);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
888 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
889 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
890 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
891 Py_INCREF(Py_None);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
892 return Py_None;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
893 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
894
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
895
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
896 /* List of methods for socket objects */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
897
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
898 static PyMethodDef PySocketSock_methods[] = {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
899 {"accept", (PyCFunction)PySocketSock_accept},
1760
48e6b319f3e4 * Modules/{Setup.in,Makefile.pre.in}: renamed some modules to
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
900 #if 0
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
901 {"allowbroadcast", (PyCFunction)PySocketSock_allowbroadcast},
1760
48e6b319f3e4 * Modules/{Setup.in,Makefile.pre.in}: renamed some modules to
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
902 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
903 {"setblocking", (PyCFunction)PySocketSock_setblocking},
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
904 {"setsockopt", (PyCFunction)PySocketSock_setsockopt},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
905 {"getsockopt", (PyCFunction)PySocketSock_getsockopt},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
906 {"bind", (PyCFunction)PySocketSock_bind},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
907 {"close", (PyCFunction)PySocketSock_close},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
908 {"connect", (PyCFunction)PySocketSock_connect},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
909 {"fileno", (PyCFunction)PySocketSock_fileno},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
910 {"getsockname", (PyCFunction)PySocketSock_getsockname},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
911 #ifdef HAVE_GETPEERNAME
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
912 {"getpeername", (PyCFunction)PySocketSock_getpeername},
1271
2919b448e385 * Microscopic corrections to make things compile on the Cray APP.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
913 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
914 {"listen", (PyCFunction)PySocketSock_listen},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
915 #ifndef NO_DUP
2532
9e5a09841781 mode and optional bufsize for makefile()
Guido van Rossum <guido@python.org>
parents: 2369
diff changeset
916 {"makefile", (PyCFunction)PySocketSock_makefile, 1},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
917 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
918 {"recv", (PyCFunction)PySocketSock_recv},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
919 {"recvfrom", (PyCFunction)PySocketSock_recvfrom},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
920 {"send", (PyCFunction)PySocketSock_send},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
921 {"sendto", (PyCFunction)PySocketSock_sendto},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
922 {"shutdown", (PyCFunction)PySocketSock_shutdown},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
923 {NULL, NULL} /* sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
924 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
925
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
926
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
927 /* 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
928 First close the file description. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
929
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
930 static void
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
931 BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
932 {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
933 (void) close(s->sock_fd);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
934 PyMem_DEL(s);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
935 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
936
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
937
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
938 /* 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
939
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
940 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
941 BUILD_FUNC_DEF_2(PySocketSock_getattr,PySocketSockObject *,s, char *,name)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
942 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
943 return Py_FindMethod(PySocketSock_methods, (PyObject *) s, name);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
944 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
945
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
946
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
947 static PyObject *
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
948 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
949 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
950 PyObject *addro;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
951 struct sockaddr *addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
952 char buf[512];
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
953 PyObject *t, *comma, *v;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
954 int i, len;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
955 sprintf(buf,
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
956 "<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
957 s->sock_fd, s->sock_family, s->sock_type, s->sock_proto);
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
958 t = PyString_FromString(buf);
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
959 return t;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
960 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
961
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
962
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
963 /* 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
964
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
965 static PyTypeObject PySocketSock_Type = {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
966 PyObject_HEAD_INIT(&PyType_Type)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
967 0,
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
968 "socket",
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
969 sizeof(PySocketSockObject),
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
970 0,
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
971 (destructor)PySocketSock_dealloc, /*tp_dealloc*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
972 0, /*tp_print*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
973 (getattrfunc)PySocketSock_getattr, /*tp_getattr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
974 0, /*tp_setattr*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
975 0, /*tp_compare*/
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
976 (reprfunc)PySocketSock_repr, /*tp_repr*/
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
977 0, /*tp_as_number*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
978 0, /*tp_as_sequence*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
979 0, /*tp_as_mapping*/
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
980 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
981
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
982
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
983 /* Python interface to gethostname(). */
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
984
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
985 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
986 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
987 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
988 {
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
989 char buf[1024];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
990 int res;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
991 if (!PyArg_NoArgs(args))
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
992 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
993 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
994 res = gethostname(buf, (int) sizeof buf - 1);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
995 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
996 if (res < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
997 return PySocket_Err();
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
998 buf[sizeof buf - 1] = '\0';
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
999 return PyString_FromString(buf);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1000 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1001
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1002
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1003 /* Python interface to gethostbyname(name). */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1004
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1005 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1006 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1007 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
1008 {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1009 char *name;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1010 struct sockaddr_in addrbuf;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1011 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
1012 return NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1013 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
1014 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1015 return makeipaddr(&addrbuf);
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1016 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1017
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1018 /* Python interface to gethostbyaddr(IP). */
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1019
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1020 /*ARGSUSED*/
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1021 static PyObject *
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1022 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
1023 {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1024 struct sockaddr_in addr;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1025 char *ip_num;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1026 struct hostent *h;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1027 int d1,d2,d3,d4;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1028 char ch, **pch;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1029 PyObject *rtn_tuple = (PyObject *)NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1030 PyObject *name_list = (PyObject *)NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1031 PyObject *addr_list = (PyObject *)NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1032 PyObject *tmp;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1033
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1034 if (!PyArg_Parse(args, "s", &ip_num))
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1035 return NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1036 if (setipaddr(ip_num, &addr) < 0)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1037 return NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1038 h = gethostbyaddr((char *)&addr.sin_addr,
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1039 sizeof(addr.sin_addr),
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1040 AF_INET);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1041 if (h == NULL) {
2115
7ea369d05c2e better test for existence of hstrerror()
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1042 #ifdef HAVE_HSTRERROR
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1043 /* 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
1044 extern int h_errno;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1045 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
1046 #else
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1047 PyErr_SetString(PySocket_Error, "host not found");
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1048 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1049 return NULL;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1050 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1051 if ((name_list = PyList_New(0)) == NULL)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1052 goto err;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1053 if ((addr_list = PyList_New(0)) == NULL)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1054 goto err;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1055 for (pch = h->h_aliases; *pch != NULL; pch++) {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1056 tmp = PyString_FromString(*pch);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1057 if (tmp == NULL)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1058 goto err;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1059 PyList_Append(name_list, tmp);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1060 Py_DECREF(tmp);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1061 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1062 for (pch = h->h_addr_list; *pch != NULL; pch++) {
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1063 memcpy((char *) &addr.sin_addr, *pch, h->h_length);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1064 tmp = makeipaddr(&addr);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1065 if (tmp == NULL)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1066 goto err;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1067 PyList_Append(addr_list, tmp);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1068 Py_DECREF(tmp);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1069 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1070 rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1071 err:
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1072 Py_XDECREF(name_list);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1073 Py_XDECREF(addr_list);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1074 return rtn_tuple;
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1075 }
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1076
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1077
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1078 /* Python interface to getservbyname(name).
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1079 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
1080 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
1081
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1082 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1083 static PyObject *
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1084 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
1085 {
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1086 char *name, *proto;
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1087 struct servent *sp;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1088 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
1089 return NULL;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1090 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 925
diff changeset
1091 sp = getservbyname(name, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1092 Py_END_ALLOW_THREADS
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1093 if (sp == NULL) {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1094 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
1095 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1096 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1097 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
1098 }
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1099
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1100
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1101 /* 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
1102 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
1103 Return a new socket object. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1104
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1105 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1106 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1107 BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1108 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1109 PySocketSockObject *s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1110 int fd, family, type, proto;
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1111 proto = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1112 if (!PyArg_Parse(args, "(ii)", &family, &type)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1113 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1114 if (!PyArg_Parse(args, "(iii)", &family, &type, &proto))
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1115 return NULL;
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1116 }
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1117 Py_BEGIN_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1118 fd = socket(family, type, proto);
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1119 Py_END_ALLOW_THREADS
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1120 if (fd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1121 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1122 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
1123 /* 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
1124 file descriptor again! */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1125 if (s == NULL)
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1126 (void) close(fd);
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1127 /* 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
1128 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
1129 #ifdef SIGPIPE
324
a81020d505bf Add gethostname() and s.avail().
Guido van Rossum <guido@python.org>
parents: 309
diff changeset
1130 (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
1131 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1132 return (PyObject *) s;
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1133 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1134
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 #ifndef NO_DUP
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1136 /* 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
1137 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
1138 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
1139
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1140 /*ARGSUSED*/
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1141 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1142 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
1143 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1144 PySocketSockObject *s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1145 int fd, family, type, proto;
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1146 proto = 0;
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1147 if (!PyArg_Parse(args, "(iii)", &fd, &family, &type)) {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1148 PyErr_Clear();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1149 if (!PyArg_Parse(args, "(iiii)", &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
1150 return NULL;
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1151 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents: 1099
diff changeset
1152 /* 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
1153 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
1154 if (fd < 0)
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1155 return PySocket_Err();
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1156 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
1157 /* 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
1158 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
1159 #ifdef SIGPIPE
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1160 (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
1161 #endif
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1162 return (PyObject *) s;
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1163 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1164 #endif /* NO_DUP */
1099
3dd7b8255619 socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
Guido van Rossum <guido@python.org>
parents: 1094
diff changeset
1165
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1166 /* 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
1167
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1168 static PyMethodDef PySocket_methods[] = {
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1169 {"gethostbyname", PySocket_gethostbyname},
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1170 {"gethostbyaddr", PySocket_gethostbyaddr},
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1171 {"gethostname", PySocket_gethostname},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1172 {"getservbyname", PySocket_getservbyname},
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1173 {"socket", PySocket_socket},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1174 #ifndef NO_DUP
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1175 {"fromfd", PySocket_fromfd},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1176 #endif
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1177 {NULL, NULL} /* Sentinel */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1178 };
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1179
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1180
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1181 /* Convenience routine to export an integer value.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1182 For simplicity, errors (which are unlikely anyway) are ignored. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1183
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1184 static void
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1970
diff changeset
1185 BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value)
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1186 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1187 PyObject *v = PyInt_FromLong((long) value);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1188 if (v == NULL) {
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1189 /* Don't bother reporting this error */
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1190 PyErr_Clear();
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1191 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1192 else {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1193 PyDict_SetItemString(d, name, v);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1194 Py_DECREF(v);
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1195 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1196 }
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1197
295
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1198
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1199 /* Initialize this module.
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1200 This is called when the first 'import socket' is done,
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1201 via a table in config.c, if config.c is compiled with USE_SOCKET
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1202 defined. */
d7a38dece86a Many changes to the interface, and added comments.
Guido van Rossum <guido@python.org>
parents: 294
diff changeset
1203
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1204 void
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1205 initsocket()
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1206 {
1970
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1207 PyObject *m, *d;
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1208 m = Py_InitModule("socket", PySocket_methods);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1209 d = PyModule_GetDict(m);
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1210 PySocket_Error = PyString_FromString("socket.error");
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1211 if (PySocket_Error == NULL ||
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1212 PyDict_SetItemString(d, "error", PySocket_Error) != 0)
84637cfdbc07 new style
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1213 Py_FatalError("can't define socket.error");
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1214 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
1215 #ifdef AF_UNIX
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1216 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
1217 #endif /* AF_UNIX */
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1218 insint(d, "SOCK_STREAM", SOCK_STREAM);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1219 insint(d, "SOCK_DGRAM", SOCK_DGRAM);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1220 insint(d, "SOCK_RAW", SOCK_RAW);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1221 insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET);
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1222 insint(d, "SOCK_RDM", SOCK_RDM);
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1223
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1224 #ifdef SO_DEBUG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1225 insint(d, "SO_DEBUG", SO_DEBUG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1226 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1227 #ifdef SO_ACCEPTCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1228 insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1229 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1230 #ifdef SO_REUSEADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1231 insint(d, "SO_REUSEADDR", SO_REUSEADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1232 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1233 #ifdef SO_KEEPALIVE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1234 insint(d, "SO_KEEPALIVE", SO_KEEPALIVE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1235 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1236 #ifdef SO_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1237 insint(d, "SO_DONTROUTE", SO_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1238 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1239 #ifdef SO_BROADCAST
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1240 insint(d, "SO_BROADCAST", SO_BROADCAST);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1241 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1242 #ifdef SO_USELOOPBACK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1243 insint(d, "SO_USELOOPBACK", SO_USELOOPBACK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1244 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1245 #ifdef SO_LINGER
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1246 insint(d, "SO_LINGER", SO_LINGER);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1247 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1248 #ifdef SO_OOBINLINE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1249 insint(d, "SO_OOBINLINE", SO_OOBINLINE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1250 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1251 #ifdef SO_REUSEPORT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1252 insint(d, "SO_REUSEPORT", SO_REUSEPORT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1253 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1254
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1255 #ifdef SO_SNDBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1256 insint(d, "SO_SNDBUF", SO_SNDBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1257 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1258 #ifdef SO_RCVBUF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1259 insint(d, "SO_RCVBUF", SO_RCVBUF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1260 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1261 #ifdef SO_SNDLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1262 insint(d, "SO_SNDLOWAT", SO_SNDLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1263 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1264 #ifdef SO_RCVLOWAT
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1265 insint(d, "SO_RCVLOWAT", SO_RCVLOWAT);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1266 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1267 #ifdef SO_SNDTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1268 insint(d, "SO_SNDTIMEO", SO_SNDTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1269 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1270 #ifdef SO_RCVTIMEO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1271 insint(d, "SO_RCVTIMEO", SO_RCVTIMEO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1272 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1273 #ifdef SO_ERROR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1274 insint(d, "SO_ERROR", SO_ERROR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1275 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1276 #ifdef SO_TYPE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1277 insint(d, "SO_TYPE", SO_TYPE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1278 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1279
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1280 /* Maximum number of connections for "listen" */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1281 #ifdef SOMAXCONN
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1282 insint(d, "SOMAXCONN", SOMAXCONN);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1283 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1284 insint(d, "SOMAXCONN", 5); /* Common value */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1285 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1286
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1287 /* Flags for send, recv */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1288 #ifdef MSG_OOB
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1289 insint(d, "MSG_OOB", MSG_OOB);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1290 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1291 #ifdef MSG_PEEK
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1292 insint(d, "MSG_PEEK", MSG_PEEK);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1293 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1294 #ifdef MSG_DONTROUTE
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1295 insint(d, "MSG_DONTROUTE", MSG_DONTROUTE);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1296 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1297 #ifdef MSG_EOR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1298 insint(d, "MSG_EOR", MSG_EOR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1299 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1300 #ifdef MSG_TRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1301 insint(d, "MSG_TRUNC", MSG_TRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1302 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1303 #ifdef MSG_CTRUNC
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1304 insint(d, "MSG_CTRUNC", MSG_CTRUNC);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1305 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1306 #ifdef MSG_WAITALL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1307 insint(d, "MSG_WAITALL", MSG_WAITALL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1308 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1309 #ifdef MSG_BTAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1310 insint(d, "MSG_BTAG", MSG_BTAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1311 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1312 #ifdef MSG_ETAG
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1313 insint(d, "MSG_ETAG", MSG_ETAG);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1314 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1315
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1316 /* Protocol level and numbers, usable for [gs]etsockopt */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1317 #ifdef SOL_SOCKET
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1318 insint(d, "SOL_SOCKET", SOL_SOCKET);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1319 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1320 #ifdef IPPROTO_IP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1321 insint(d, "IPPROTO_IP", IPPROTO_IP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1322 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1323 #ifdef IPPROTO_ICMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1324 insint(d, "IPPROTO_ICMP", IPPROTO_ICMP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1325 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1326 #ifdef IPPROTO_IGMP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1327 insint(d, "IPPROTO_IGMP", IPPROTO_IGMP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1328 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1329 #ifdef IPPROTO_GGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1330 insint(d, "IPPROTO_GGP", IPPROTO_GGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1331 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1332 #ifdef IPPROTO_TCP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1333 insint(d, "IPPROTO_TCP", IPPROTO_TCP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1334 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1335 #ifdef IPPROTO_EGP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1336 insint(d, "IPPROTO_EGP", IPPROTO_EGP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1337 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1338 #ifdef IPPROTO_PUP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1339 insint(d, "IPPROTO_PUP", IPPROTO_PUP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1340 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1341 #ifdef IPPROTO_UDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1342 insint(d, "IPPROTO_UDP", IPPROTO_UDP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1343 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1344 #ifdef IPPROTO_IDP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1345 insint(d, "IPPROTO_IDP", IPPROTO_IDP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1346 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1347 #ifdef IPPROTO_HELLO
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1348 insint(d, "IPPROTO_HELLO", IPPROTO_HELLO);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1349 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1350 #ifdef IPPROTO_ND
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1351 insint(d, "IPPROTO_ND", IPPROTO_ND);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1352 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1353 #ifdef IPPROTO_TP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1354 insint(d, "IPPROTO_TP", IPPROTO_TP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1355 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1356 #ifdef IPPROTO_XTP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1357 insint(d, "IPPROTO_XTP", IPPROTO_XTP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1358 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1359 #ifdef IPPROTO_EON
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1360 insint(d, "IPPROTO_EON", IPPROTO_EON);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1361 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1362 #ifdef IPPROTO_BIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1363 insint(d, "IPPROTO_BIP", IPPROTO_BIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1364 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1365 /**/
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1366 #ifdef IPPROTO_RAW
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1367 insint(d, "IPPROTO_RAW", IPPROTO_RAW);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1368 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1369 #ifdef IPPROTO_MAX
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1370 insint(d, "IPPROTO_MAX", IPPROTO_MAX);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1371 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1372
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1373 /* Some port configuration */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1374 #ifdef IPPORT_RESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1375 insint(d, "IPPORT_RESERVED", IPPORT_RESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1376 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1377 insint(d, "IPPORT_RESERVED", 1024);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1378 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1379 #ifdef IPPORT_USERRESERVED
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1380 insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1381 #else
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1382 insint(d, "IPPORT_USERRESERVED", 5000);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1383 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1384
2369
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1385 /* Some reserved IP v.4 addresses */
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1386 #ifdef INADDR_ANY
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1387 insint(d, "INADDR_ANY", INADDR_ANY);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1388 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1389 insint(d, "INADDR_ANY", 0x00000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1390 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1391 #ifdef INADDR_BROADCAST
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1392 insint(d, "INADDR_BROADCAST", INADDR_BROADCAST);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1393 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1394 insint(d, "INADDR_BROADCAST", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1395 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1396 #ifdef INADDR_LOOPBACK
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1397 insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1398 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1399 insint(d, "INADDR_LOOPBACK", 0x7F000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1400 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1401 #ifdef INADDR_UNSPEC_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1402 insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1403 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1404 insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1405 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1406 #ifdef INADDR_ALLHOSTS_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1407 insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1408 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1409 insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1410 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1411 #ifdef INADDR_MAX_LOCAL_GROUP
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1412 insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1413 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1414 insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1415 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1416 #ifdef INADDR_NONE
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1417 insint(d, "INADDR_NONE", INADDR_NONE);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1418 #else
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1419 insint(d, "INADDR_NONE", 0xffffffff);
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1420 #endif
ba1b76c09041 add INADDR_* symbols
Guido van Rossum <guido@python.org>
parents: 2299
diff changeset
1421
2299
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1422 /* IP [gs]etsockopt options */
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1423 #ifdef IP_OPTIONS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1424 insint(d, "IP_OPTIONS", IP_OPTIONS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1425 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1426 #ifdef IP_HDRINCL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1427 insint(d, "IP_HDRINCL", IP_HDRINCL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1428 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1429 #ifdef IP_TOS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1430 insint(d, "IP_TOS", IP_TOS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1431 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1432 #ifdef IP_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1433 insint(d, "IP_TTL", IP_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1434 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1435 #ifdef IP_RECVOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1436 insint(d, "IP_RECVOPTS", IP_RECVOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1437 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1438 #ifdef IP_RECVRETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1439 insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1440 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1441 #ifdef IP_RECVDSTADDR
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1442 insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1443 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1444 #ifdef IP_RETOPTS
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1445 insint(d, "IP_RETOPTS", IP_RETOPTS);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1446 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1447 #ifdef IP_MULTICAST_IF
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1448 insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1449 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1450 #ifdef IP_MULTICAST_TTL
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1451 insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1452 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1453 #ifdef IP_MULTICAST_LOOP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1454 insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1455 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1456 #ifdef IP_ADD_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1457 insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1458 #endif
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1459 #ifdef IP_DROP_MEMBERSHIP
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1460 insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
990099ed7810 add socket related constants
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
1461 #endif
294
8938b3132caa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1462 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1463
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1464 #ifdef NT
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1465 BOOL WINAPI DllMain (HANDLE hInst,
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1466 ULONG ul_reason_for_call,
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1467 LPVOID lpReserved)
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1468 {
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1469 const int opt = SO_SYNCHRONOUS_NONALERT;
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1470 switch (ul_reason_for_call)
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1471 {
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1472 case DLL_PROCESS_ATTACH: {
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1473 WSADATA WSAData;
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1474 BOOL ok = TRUE;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1475 char buf[100] = "Python can't initialize Windows Sockets Module!\n\r";
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1476 if (WSAStartup(MAKEWORD(1,1), &WSAData)) {
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1477 wsprintf(buf+strlen(buf), "WSAStartup failed (%d)",WSAGetLastError());
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1478 ok = FALSE;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1479 }
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1480 /*
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1481 ** Setup sockets in non-overlapped mode by default
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1482 */
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1483 if (ok && setsockopt(INVALID_SOCKET,SOL_SOCKET,SO_OPENTYPE,(const char *)&opt,sizeof(opt)) != 0) {
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1484 wsprintf(buf+strlen(buf),"setsockopt failed (%d)",WSAGetLastError());
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1485 ok = FALSE;
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1486 }
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1487 if (!ok) {
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1488 MessageBox(NULL,buf,"WinSock Error",MB_OK|MB_SETFOREGROUND);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1489 return FALSE;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1490 }
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1491 break;
2736
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1492 }
37c48fde61b8 add setblocking(); NT changes; null-terminate Unix path
Guido van Rossum <guido@python.org>
parents: 2565
diff changeset
1493
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1494 case DLL_PROCESS_DETACH:
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1495 WSACleanup();
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1496 break;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1497
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1498 }
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1499 return TRUE;
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1500 }
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
1501 #endif /* NT */