annotate Modules/socketmodule.c @ 5792:dffabc620e4e legacy-trunk

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