author | Stefan Vogel <sv@exept.de> |
Tue, 09 Apr 2002 16:58:01 +0200 | |
changeset 1035 | 5b0605675dc6 |
parent 1029 | 5906977e62f0 |
child 1110 | 0876a3d30fd2 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
42 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
888 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
63 | 15 |
NonPositionableExternalStream subclass:#Socket |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
16 |
instanceVariableNames:'domain socketType protocol port serviceName peerName' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
17 |
classVariableNames:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
18 |
poolDictionaries:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
19 |
category:'Streams-External' |
0 | 20 |
! |
21 |
||
126 | 22 |
!Socket primitiveDefinitions! |
23 |
%{ |
|
444 | 24 |
|
1009 | 25 |
/* #define DGRAM_DEBUG /* */ |
26 |
||
444 | 27 |
#ifdef LINUX |
28 |
# define BUGGY_STDIO_LIB |
|
822 | 29 |
# include <linux/version.h> |
30 |
||
31 |
# ifndef KERNEL_VERSION |
|
32 |
# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
|
33 |
# endif |
|
34 |
#endif /* LINUX */ |
|
126 | 35 |
|
36 |
#include <stdio.h> |
|
37 |
#include <errno.h> |
|
38 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
39 |
#define UNIX_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
40 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
41 |
#if defined(transputer) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
42 |
# undef UNIX_LIKE |
418 | 43 |
# define NO_SOCKET |
44 |
#endif |
|
45 |
||
525 | 46 |
/* |
47 |
* which protocols can we support ? |
|
48 |
*/ |
|
49 |
#ifndef NO_SOCKET |
|
50 |
# define WANT__AF_INET |
|
51 |
#endif |
|
52 |
||
53 |
#ifdef UNIX_LIKE |
|
54 |
# define WANT__AF_UNIX |
|
55 |
#endif |
|
56 |
||
563 | 57 |
#ifdef __VMS__ |
58 |
# undef WANT__AF_UNIX |
|
571 | 59 |
# define WANT_AF_DECnet |
563 | 60 |
#endif |
61 |
||
527 | 62 |
#ifdef LINUX |
822 | 63 |
# ifndef LINUX_VERSION_CODE |
64 |
/* PRE 2.0 Linux kernel. */ |
|
65 |
# else |
|
66 |
# if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0) |
|
67 |
/* PRE 2.0 Linux kernel. */ |
|
68 |
# else |
|
69 |
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0) |
|
70 |
# define WANT__AF_APPLETALK |
|
71 |
# define xxWANT__AF_X25 |
|
72 |
# define xxWANT__AF_AX25 |
|
73 |
# define xxWANT__AF_IPX |
|
74 |
# define WANT__AF_INET6 */ |
|
869 | 75 |
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) |
875 | 76 |
# define xxWANT__AF_IRDA */ |
869 | 77 |
# endif /* >= 2.2.0 */ |
822 | 78 |
# endif /* >= 2.1.0 */ |
79 |
# endif /* pre 2.0.0 */ |
|
80 |
# endif /* pre 2.0.0 */ |
|
81 |
#endif /* LINIX */ |
|
525 | 82 |
|
819 | 83 |
#ifdef solaris2_0 |
84 |
# define xxxWANT__AF_DECNET |
|
85 |
#endif |
|
86 |
||
126 | 87 |
#ifdef LINUX |
88 |
/* kludge to avoid some redefines ... */ |
|
89 |
# define _ARPA_NAMESER_H |
|
90 |
# define _NETINET_TCP_H |
|
91 |
#endif |
|
92 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
93 |
#if !defined(NO_SOCKET) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
94 |
# include <fcntl.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
95 |
# include <sys/types.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
96 |
# define _SYS_TYPES_H_INCLUDED_ |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
97 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
98 |
# if defined(IRIS) && !defined(IRIX5) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
99 |
/* no socket.h on 4.0.5h ?!?!? */ |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
100 |
# ifndef AF_UNIX |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
101 |
# define AF_UNIX 1 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
102 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
103 |
# ifndef AF_INET |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
104 |
# define AF_INET 2 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
105 |
# endif |
789 | 106 |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
107 |
# ifndef SOCK_STREAM |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
108 |
# define SOCK_STREAM 1 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
109 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
110 |
# ifndef SOCK_DGRAM |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
111 |
# define SOCK_DGRAM 2 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
112 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
113 |
# ifndef SOCK_RAW |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
114 |
# define SOCK_RAW 3 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
115 |
# endif |
656 | 116 |
# else |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
117 |
# include <sys/socket.h> |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
118 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
119 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
120 |
# ifdef NEXT3 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
121 |
# include <netinet/in_systm.h> |
126 | 122 |
# endif |
123 |
#endif |
|
124 |
||
525 | 125 |
|
126 | 126 |
/* |
528 | 127 |
* see what we want ... |
126 | 128 |
*/ |
525 | 129 |
#ifdef WANT__AF_UNIX |
130 |
# ifdef AF_UNIX |
|
131 |
# ifndef PF_UNIX |
|
132 |
# define PF_UNIX AF_UNIX |
|
133 |
# endif |
|
126 | 134 |
# endif |
525 | 135 |
#else |
136 |
# undef AF_UNIX |
|
137 |
#endif |
|
138 |
||
139 |
#ifdef WANT__AF_INET |
|
140 |
# ifdef AF_INET |
|
141 |
# ifndef PF_INET |
|
142 |
# define PF_INET AF_INET |
|
143 |
# endif |
|
144 |
# endif |
|
145 |
#else |
|
146 |
# undef AF_INET |
|
126 | 147 |
#endif |
525 | 148 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
149 |
#ifdef WANT__AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
150 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
151 |
# ifndef PF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
152 |
# define PF_INET6 AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
153 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
154 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
155 |
#else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
156 |
# undef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
157 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
158 |
|
525 | 159 |
#ifdef WANT__AF_DECnet |
160 |
# ifdef AF_DECnet |
|
161 |
# ifndef PF_DECnet |
|
162 |
# define PF_DECnet AF_DECnet |
|
163 |
# endif |
|
164 |
# endif |
|
165 |
#else |
|
166 |
# undef AF_DECnet |
|
167 |
#endif |
|
168 |
||
169 |
#ifdef WANT__AF_APPLETALK |
|
170 |
# ifdef AF_APPLETALK |
|
171 |
# ifndef PF_APPLETALK |
|
172 |
# define PF_APPLETALK AF_APPLETALK |
|
173 |
# endif |
|
126 | 174 |
# endif |
525 | 175 |
#else |
176 |
# undef AF_APPLETALK |
|
126 | 177 |
#endif |
525 | 178 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
179 |
#ifdef WANT__AF_X25 /* X.25 */ |
525 | 180 |
# ifdef AF_X25 |
181 |
# ifndef PF_X25 |
|
182 |
# define PF_X25 AF_X25 |
|
183 |
# endif |
|
184 |
# endif |
|
185 |
#else |
|
186 |
# undef AF_X25 |
|
187 |
#endif |
|
188 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
189 |
#ifdef WANT__AF_NS /* Xerox XNS */ |
525 | 190 |
# ifdef AF_NS |
191 |
# ifndef PF_NS |
|
192 |
# define PF_NS AF_NS |
|
193 |
# endif |
|
126 | 194 |
# endif |
525 | 195 |
#else |
196 |
# undef AF_NS |
|
126 | 197 |
#endif |
525 | 198 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
199 |
#ifdef WANT__AF_SNA /* IBM SNA */ |
525 | 200 |
# ifdef AF_SNA |
201 |
# ifndef PF_SNA |
|
202 |
# define PF_SNA AF_SNA |
|
203 |
# endif |
|
126 | 204 |
# endif |
525 | 205 |
#else |
206 |
# undef AF_SNA |
|
207 |
#endif |
|
208 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
209 |
#ifdef WANT__AF_RAW /* RAW packets */ |
525 | 210 |
# ifdef AF_RAW |
211 |
# ifndef PF_RAW |
|
212 |
# define PF_RAW AF_RAW |
|
213 |
# endif |
|
214 |
# endif |
|
215 |
#else |
|
216 |
# undef AF_RAW |
|
126 | 217 |
#endif |
525 | 218 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
219 |
#ifdef WANT__AF_ISO /* ? */ |
525 | 220 |
# ifdef AF_ISO |
221 |
# ifndef PF_ISO |
|
222 |
# define PF_ISO AF_ISO |
|
223 |
# endif |
|
224 |
# endif |
|
225 |
#else |
|
226 |
# undef AF_ISO |
|
227 |
#endif |
|
228 |
||
823 | 229 |
#ifdef WANT__AF_NETBIOS /* NETBIOS */ |
525 | 230 |
# ifdef AF_NETBIOS |
231 |
# ifndef PF_NETBIOS |
|
232 |
# define PF_NETBIOS AF_NETBIOS |
|
233 |
# endif |
|
126 | 234 |
# endif |
525 | 235 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
236 |
# undef AF_NETBIOS |
126 | 237 |
#endif |
525 | 238 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
239 |
#ifdef WANT__AF_CCITT /* ? */ |
525 | 240 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
241 |
# ifndef PF_CCITT |
|
242 |
# define PF_CCITT AF_CCITT |
|
243 |
# endif |
|
244 |
# endif |
|
245 |
#else |
|
246 |
# undef AF_CCITT |
|
247 |
#endif |
|
248 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
249 |
#ifdef WANT__AF_IPX /* Novell IPX */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
250 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
251 |
# ifndef PF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
252 |
# define PF_IPX AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
253 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
254 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
255 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
256 |
# undef AF_IPX |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
257 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
258 |
|
812 | 259 |
#ifdef WANT__AF_AX25 /* Amateur Radio AX.25 */ |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
260 |
# ifdef AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
261 |
# ifndef PF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
262 |
# define PF_AX25 AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
263 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
264 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
265 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
266 |
# undef AF_AX25 |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
267 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
268 |
|
812 | 269 |
#ifdef WANT__AF_NETROM /* Amateur Radio NET/ROM */ |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
270 |
# ifdef AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
271 |
# ifndef PF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
272 |
# define PF_NETROM AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
273 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
274 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
275 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
276 |
# undef AF_NETROM |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
277 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
278 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
279 |
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
280 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
281 |
# ifndef PF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
282 |
# define PF_BRIDGE AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
283 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
284 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
285 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
286 |
# undef AF_BRIDGE |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
287 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
288 |
|
571 | 289 |
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */ |
290 |
# ifdef AF_BSC |
|
291 |
# ifndef PF_BSC |
|
292 |
# define PF_BSC AF_BSC |
|
293 |
# endif |
|
294 |
# endif |
|
295 |
#else |
|
296 |
# undef AF_BSC |
|
297 |
#endif |
|
298 |
||
812 | 299 |
#ifdef WANT__AF_ROSE /* Amateur Radio X.25 PLP */ |
814 | 300 |
# ifdef AF_ROSE |
301 |
# ifndef PF_ROSE |
|
302 |
# define PF_ROSE AF_ROSE |
|
812 | 303 |
# endif |
304 |
# endif |
|
305 |
#else |
|
814 | 306 |
# undef AF_ROSE |
812 | 307 |
#endif |
308 |
||
823 | 309 |
#ifdef WANT__AF_ATM /* ATM Services */ |
310 |
# ifdef AF_ATM |
|
311 |
# ifndef PF_ATM |
|
312 |
# define PF_ATM AF_ATM |
|
313 |
# endif |
|
314 |
# endif |
|
315 |
#else |
|
316 |
# undef AF_ATM |
|
317 |
#endif |
|
318 |
||
319 |
#ifdef WANT__AF_BAN /* BAN / VINES IP Services */ |
|
320 |
# ifdef AF_BAN |
|
321 |
# ifndef PF_BAN |
|
322 |
# define PF_BAN AF_BAN |
|
323 |
# endif |
|
324 |
# endif |
|
325 |
#else |
|
326 |
# undef AF_BAN |
|
327 |
#endif |
|
328 |
||
329 |
#ifdef WANT__AF_VOICEVIEW /* VoiceView Services W95 only */ |
|
330 |
# ifdef AF_VOICEVIEW |
|
331 |
# ifndef PF_VOICEVIEW |
|
332 |
# define PF_VOICEVIEW AF_VOICEVIEW |
|
333 |
# endif |
|
334 |
# endif |
|
335 |
#else |
|
336 |
# undef AF_VOICEVIEW |
|
337 |
#endif |
|
338 |
||
869 | 339 |
#ifdef WANT__AF_IRDA /* infrared */ |
340 |
# ifdef AF_IRDA |
|
341 |
# ifndef PF_IRDA |
|
342 |
# define PF_IRDA AF_IRDA |
|
343 |
# endif |
|
344 |
# endif |
|
345 |
#else |
|
346 |
# undef AF_IRDA |
|
347 |
#endif |
|
348 |
||
571 | 349 |
|
528 | 350 |
/* |
351 |
* now, include what we have to ... |
|
819 | 352 |
* undef support, if no include file is present |
353 |
* (or I dont know yet, where to find it) |
|
528 | 354 |
*/ |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
355 |
|
823 | 356 |
#ifdef AF_UNIX |
357 |
# ifdef UNIX |
|
358 |
# include <sys/un.h> |
|
359 |
# else |
|
360 |
# undef AF_UNIX |
|
361 |
# endif |
|
362 |
#endif |
|
363 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
364 |
#ifdef AF_INET |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
365 |
# include <netdb.h> |
969 | 366 |
# if defined(PRE_SUSE_7_2) |
367 |
# if defined(LINUX) && defined(AF_INET6) |
|
368 |
# include <linux/in.h> |
|
369 |
# else |
|
370 |
# include <netinet/in.h> |
|
371 |
# endif |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
372 |
# else |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
373 |
# include <netinet/in.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
374 |
# endif |
969 | 375 |
# if !defined(LINUX) |
376 |
# if ! (defined(SYSV3) && defined(mc88k)) |
|
377 |
# include <netinet/tcp.h> |
|
378 |
# endif |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
379 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
380 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
381 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
382 |
#ifdef AF_INET6 |
819 | 383 |
# if defined(LINUX) && defined(__GLIBC__) |
969 | 384 |
# if defined(PRE_SUSE_7_2) |
385 |
# include <linux/in6.h> |
|
386 |
# endif |
|
819 | 387 |
# else |
388 |
# undef AF_INET6 |
|
126 | 389 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
390 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
391 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
392 |
#ifdef AF_APPLETALK |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
393 |
# ifdef LINUX |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
394 |
# include <asm/types.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
395 |
# include <linux/atalk.h> |
819 | 396 |
# else |
397 |
# undef AF_APPLETALK |
|
398 |
# endif |
|
399 |
#endif |
|
400 |
||
401 |
#ifdef AF_DECNET |
|
402 |
# ifdef solaris2_0 |
|
403 |
# include <X11/dni8.h> |
|
404 |
# else |
|
405 |
# undef AF_DECNET |
|
465 | 406 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
407 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
408 |
|
812 | 409 |
#ifdef AF_X25 |
410 |
# ifdef LINUX |
|
411 |
# include <linux/x25.h> |
|
819 | 412 |
# else |
413 |
# undef AF_X25 |
|
414 |
# endif |
|
415 |
#endif |
|
416 |
||
417 |
#ifdef AF_AX25 |
|
418 |
# ifdef LINUX |
|
419 |
# include <linux/ax25.h> |
|
420 |
# else |
|
421 |
# undef AF_AX25 |
|
422 |
# endif |
|
423 |
#endif |
|
424 |
||
425 |
#ifdef AF_IPX |
|
426 |
# ifdef LINUX |
|
427 |
# include <linux/ipx.h> |
|
428 |
# else |
|
823 | 429 |
# ifdef WIN32 |
430 |
# include <wsipx.h> |
|
431 |
# else |
|
432 |
# undef AF_IPX |
|
433 |
# endif |
|
434 |
# endif |
|
435 |
#endif |
|
436 |
||
437 |
#ifdef AF_NETBIOS |
|
438 |
# ifdef WIN32 |
|
439 |
# include <wsnetbs.h> |
|
440 |
# else |
|
441 |
# undef AF_NETBIOS |
|
442 |
# endif |
|
443 |
#endif |
|
444 |
||
445 |
#ifdef AF_ATM |
|
446 |
# ifdef WIN32 |
|
447 |
# include <ws2atm.h> |
|
448 |
# else |
|
449 |
# undef AF_ATM |
|
812 | 450 |
# endif |
451 |
#endif |
|
452 |
||
823 | 453 |
#ifdef AF_BAN |
454 |
# ifdef WIN32 |
|
455 |
# include <wsvns.h> |
|
456 |
# else |
|
457 |
# undef AF_BAN |
|
458 |
# endif |
|
459 |
#endif |
|
460 |
||
461 |
#ifdef AF_VOICEVIEW |
|
462 |
# ifdef WIN32 |
|
463 |
# include <wsvv.h> |
|
464 |
# else |
|
465 |
# undef AF_VOICEVIEW |
|
466 |
# endif |
|
467 |
#endif |
|
468 |
||
869 | 469 |
#ifdef AF_IRDA |
470 |
# ifdef LINUX |
|
471 |
# include <linux/irda.h> |
|
472 |
# else |
|
473 |
# undef AF_IRDA |
|
474 |
# endif |
|
475 |
#endif |
|
476 |
||
823 | 477 |
#undef AF_SNA /* not yet implemented */ |
478 |
#undef AF_RAW /* not yet implemented */ |
|
479 |
#undef AF_NETROM /* not yet implemented */ |
|
480 |
#undef AF_BRIDGE /* not yet implemented */ |
|
481 |
#undef AF_BSC /* not yet implemented */ |
|
482 |
||
819 | 483 |
|
484 |
/* |
|
485 |
* see what is leftOver |
|
486 |
*/ |
|
487 |
union sockaddr_u { |
|
488 |
#ifdef AF_UNIX |
|
489 |
struct sockaddr_un un; |
|
490 |
#endif |
|
491 |
#ifdef AF_INET |
|
492 |
struct sockaddr_in in; |
|
493 |
#endif |
|
494 |
#ifdef AF_INET6 |
|
495 |
struct sockaddr_in6 in6; |
|
496 |
#endif |
|
497 |
#ifdef AF_APPLETALK |
|
498 |
struct sockaddr_at at; |
|
499 |
#endif |
|
500 |
#ifdef AF_DECNET |
|
501 |
struct sockaddr_dn dn; |
|
502 |
#endif |
|
503 |
#ifdef AF_X25 |
|
504 |
struct sockaddr_x25 x25; |
|
505 |
#endif |
|
506 |
#ifdef AF_AX25 |
|
507 |
struct sockaddr_ax25 ax25; |
|
508 |
#endif |
|
509 |
#ifdef AF_IPX |
|
510 |
struct sockaddr_ipx ipx; |
|
511 |
#endif |
|
823 | 512 |
#ifdef AF_NETBIOS |
513 |
struct sockaddr_nb nb; |
|
514 |
#endif |
|
515 |
#ifdef AF_ATM |
|
516 |
struct sockaddr_atm atm; |
|
517 |
#endif |
|
518 |
#ifdef AF_BAN |
|
519 |
struct sockaddr_vns vns; |
|
520 |
#endif |
|
521 |
#ifdef AF_VOICEVIEW |
|
522 |
struct sockaddr_vv vv; |
|
523 |
#endif |
|
869 | 524 |
#ifdef AF_IRDA |
525 |
struct sockaddr_irda irda; |
|
526 |
#endif |
|
819 | 527 |
}; |
528 |
||
529 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
530 |
#if defined(TRY_AGAIN) || defined(HOST_NOT_FOUND) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
531 |
# define USE_H_ERRNO |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
532 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
533 |
|
126 | 534 |
|
819 | 535 |
|
126 | 536 |
/* |
537 |
* on some systems errno is a macro ... check for it here |
|
538 |
*/ |
|
539 |
#ifndef errno |
|
540 |
extern errno; |
|
541 |
#endif |
|
542 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
543 |
#ifdef USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
544 |
# ifndef h_errno |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
545 |
extern h_errno; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
546 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
547 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
548 |
|
720 | 549 |
#ifdef xxLINUX |
550 |
/* use inline string macros ... */ |
|
551 |
# define __STRINGDEFS__ |
|
552 |
# include <linuxIntern.h> |
|
553 |
#endif |
|
554 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
555 |
/* |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
556 |
* gethostbyname seems to have trouble |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
557 |
* sometimes, if interrupted while a request |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
558 |
* is on its way the name server. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
559 |
* (although specified in the man-page, |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
560 |
* a check on TRY_AGAIN fails on iris) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
561 |
*/ |
692
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
562 |
#ifdef LINUX |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
563 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
564 |
# define GETHOSTBYNAME(hp, name) \ |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
565 |
hp = gethostbyname((char *) name); |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
566 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
567 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
568 |
hp = gethostbyaddr(addr, alen, af); |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
569 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
570 |
#else |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
571 |
|
693 | 572 |
# ifdef IRIX5_3 |
573 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
574 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
575 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
576 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
577 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
578 |
} while ((hp == NULL) && \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
579 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
580 |
|
693 | 581 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
789 | 582 |
do { \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
583 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
584 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
585 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
586 |
} while ((hp == NULL) && \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
587 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
693 | 588 |
# else |
589 |
# ifdef USE_H_ERRNO |
|
590 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
591 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
592 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
593 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
594 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
595 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
596 |
|
693 | 597 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
598 |
do { \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
599 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
600 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
601 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
602 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
693 | 603 |
# else |
604 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
605 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
606 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
607 |
__END_INTERRUPTABLE__ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
608 |
|
693 | 609 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
610 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
611 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
612 |
__END_INTERRUPTABLE__ |
693 | 613 |
# endif |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
614 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
615 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
616 |
|
126 | 617 |
#ifdef DEBUG |
618 |
# define DBGPRINTF(x) { if (__debugging__) printf x; } |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
619 |
# define DBGFPRINTF(x) { if (__debugging__) fprintf x; } |
126 | 620 |
#else |
621 |
# define DBGPRINTF(x) /* as nothing */ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
622 |
# define DBGFPRINTF(x) /* as nothing */ |
126 | 623 |
#endif |
624 |
||
625 |
%} |
|
626 |
! ! |
|
627 |
||
511 | 628 |
!Socket primitiveVariables! |
629 |
%{ |
|
630 |
static int __debugging__ = 0; |
|
631 |
%} |
|
632 |
! ! |
|
633 |
||
464 | 634 |
!Socket class methodsFor:'documentation'! |
25 | 635 |
|
31 | 636 |
copyright |
637 |
" |
|
638 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
42 | 639 |
All Rights Reserved |
31 | 640 |
|
641 |
This software is furnished under a license and may be used |
|
642 |
only in accordance with the terms of that license and with the |
|
643 |
inclusion of the above copyright notice. This software may not |
|
644 |
be provided or otherwise made available to, or used by, any |
|
645 |
other person. No title to or ownership of the software is |
|
646 |
hereby transferred. |
|
647 |
" |
|
648 |
! |
|
649 |
||
25 | 650 |
documentation |
651 |
" |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
652 |
This class provides access to sockets for interprocess communication. |
25 | 653 |
The message protocol is preliminary, until someone tells me how |
31 | 654 |
other smalltalk's socket interfaces look like. |
25 | 655 |
|
525 | 656 |
Currently, only IP and UNIX domain sockets are supported. |
657 |
Code for appletalk is included, but was never tested ... |
|
658 |
More may be added in the future. |
|
659 |
(the code is prepared for things like SNA or decNet; |
|
660 |
however, right now, this code is empty and needs a little work. |
|
661 |
Implementing those is pretty straight forward, once the address |
|
662 |
data structures are known.) |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
663 |
|
28 | 664 |
Due to historic reasons (I started this class, before I got hold of some |
665 |
code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface |
|
71 | 666 |
still provided. |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
667 |
This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces, |
71 | 668 |
together with the bind/listen and accept calls, |
669 |
which are meant to be compatible to ST-80's UnixSocketAccessor interface. |
|
670 |
||
869 | 671 |
ST/X does not yet use IPSocketAddress, UDSocketAddress etc; all addressing |
71 | 672 |
is done by passing appropriate string- or byteArray objects containing |
673 |
the addresses. This may change, too. |
|
674 |
||
675 |
TODO: cleanup historic leftovers, implement other than inet domain stuff. |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
676 |
(mhmh - how can I test those ?) |
532 | 677 |
change to raise more signals on errors. |
529 | 678 |
Help - could someone who has a linux machine connected to an appletalk |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
679 |
net please test this (and send bug fixes ...) |
259 | 680 |
|
681 |
[author:] |
|
425 | 682 |
Claus Gittinger |
48 | 683 |
" |
684 |
! |
|
28 | 685 |
|
48 | 686 |
examples |
687 |
" |
|
28 | 688 |
example (get help info from an nntp server): |
1009 | 689 |
[exBegin] |
690 |
|sock host| |
|
691 |
||
692 |
host := OperatingSystem getEnvironment:'NNTPSERVER'. |
|
693 |
||
694 |
sock := Socket newTCPclientToHost:host port:'nntp'. |
|
695 |
Transcript showCR:sock nextLine. |
|
696 |
sock buffered:false. |
|
697 |
||
698 |
sock nextPutAll:'HELP'; cr. |
|
699 |
[:exit | |
|
700 |
|line| |
|
701 |
||
702 |
line := sock nextLine. |
|
703 |
line = '.' ifTrue:[exit value:nil]. |
|
704 |
Transcript showCR:line. |
|
705 |
] loopWithExit. |
|
706 |
sock close |
|
707 |
[exEnd] |
|
209 | 708 |
|
28 | 709 |
|
209 | 710 |
example (connect to finger daemon, get users entry): |
1009 | 711 |
[exBegin] |
712 |
|sock host entry| |
|
713 |
||
714 |
host := OperatingSystem getHostName. |
|
715 |
||
716 |
sock := Socket newTCPclientToHost:host port:'finger'. |
|
717 |
sock isNil ifTrue:[ |
|
718 |
self warn:'no finger daemon is running'. |
|
719 |
^ self |
|
720 |
]. |
|
721 |
sock useCRLF:true. |
|
722 |
sock buffered:false. |
|
723 |
sock isNil ifTrue:[ |
|
724 |
Transcript showCR:'cannot connect to local finger daemon' |
|
725 |
] ifFalse:[ |
|
726 |
sock nextPutAll:(OperatingSystem getLoginName). |
|
727 |
sock cr. |
|
728 |
||
729 |
entry := sock nextLine. |
|
730 |
Transcript showCR:entry. |
|
731 |
||
732 |
sock close |
|
733 |
] |
|
734 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
735 |
|
28 | 736 |
example (connect to an ftp server): |
1009 | 737 |
[exBegin] |
738 |
|sock host| |
|
739 |
||
740 |
host := OperatingSystem getHostName. |
|
741 |
sock := Socket newTCPclientToHost:host port:'ftp'. |
|
742 |
||
743 |
sock buffered:false. |
|
744 |
Transcript showCR:sock nextLine. |
|
745 |
sock nextPutAll:('USER ' , 'anonymous'); cr. |
|
746 |
Transcript showCR:sock nextLine. |
|
747 |
sock nextPutAll:('PASS ' , 'fooBar'); cr. |
|
748 |
Transcript showCR:sock nextLine. |
|
749 |
sock nextPutAll:'LIST'; cr. |
|
750 |
Transcript showCR:sock nextLine. |
|
751 |
sock close. |
|
752 |
||
753 |
'dont know enough of the ftp protocol to continue here ...' |
|
754 |
[exEnd] |
|
28 | 755 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
756 |
|
93 | 757 |
example (connect to an snmp server [UDP]): |
1009 | 758 |
[exBegin] |
759 |
|sock port| |
|
760 |
||
761 |
sock := Socket newUDP. |
|
762 |
port := Socket portOfService:'snmp'. |
|
763 |
sock connectTo:(OperatingSystem getHostName) port:port. |
|
764 |
sock buffered:false. |
|
765 |
Transcript showCR:'got it'. |
|
766 |
sock close. |
|
767 |
[exEnd] |
|
42 | 768 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
769 |
|
42 | 770 |
example (await connection from a client and read some data): |
1009 | 771 |
[exBegin] |
772 |
|connectSock sock| |
|
773 |
||
774 |
connectSock := Socket newTCPserverAtPort:9998. |
|
775 |
connectSock isNil ifTrue:[ |
|
776 |
Transcript showCR:'socket setup failed.'. |
|
777 |
] ifFalse:[ |
|
778 |
Transcript showCR:'listen ..'. |
|
779 |
(connectSock listenFor:5) ifFalse:[ |
|
780 |
Transcript showCR:'listen failed.'. |
|
781 |
] ifTrue:[ |
|
782 |
Transcript showCR:'wait'. |
|
783 |
connectSock readWait. |
|
784 |
Transcript showCR:'accept'. |
|
785 |
sock := connectSock accept. |
|
786 |
sock isNil ifTrue:[ |
|
787 |
Transcript showCR:'accept failed.'. |
|
788 |
] ifFalse:[ |
|
789 |
sock buffered:false. |
|
790 |
Transcript showCR:'server: got it'. |
|
791 |
'can now do transfer via sock'. |
|
792 |
Transcript showCR:'read'. |
|
793 |
Transcript showCR:('got: ' , sock nextLine). |
|
794 |
||
795 |
Transcript showCR:'close'. |
|
796 |
sock close |
|
797 |
]. |
|
798 |
connectSock close. |
|
799 |
] |
|
800 |
] |
|
801 |
[exEnd] |
|
42 | 802 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
803 |
|
42 | 804 |
example (connect to above server and send some data): |
1009 | 805 |
[exBegin] |
806 |
|sock| |
|
807 |
||
808 |
sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998. |
|
809 |
sock isNil ifTrue:[ |
|
810 |
Transcript showCR:'nope' |
|
811 |
] ifFalse:[ |
|
812 |
sock buffered:false. |
|
813 |
Transcript showCR:'client: got it'. |
|
814 |
'can now do transfer via sock'. |
|
815 |
Transcript showCR:'sending <hello>'. |
|
816 |
sock nextPutLine:'hello'. |
|
817 |
sock close |
|
818 |
] |
|
819 |
[exEnd] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
820 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
821 |
example: UNIX domain socket (await connection from a client and read some data): |
1009 | 822 |
|
823 |
|connectSock sock| |
|
824 |
||
825 |
'/tmp/ud_socket' asFilename remove. |
|
826 |
connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'. |
|
827 |
connectSock isNil ifTrue:[ |
|
828 |
Transcript showCR:'socket setup failed.'. |
|
829 |
] ifFalse:[ |
|
830 |
Transcript showCR:'listen ..'. |
|
831 |
(connectSock listenFor:5) ifFalse:[ |
|
832 |
Transcript showCR:'listen failed.'. |
|
833 |
] ifTrue:[ |
|
834 |
Transcript showCR:'wait'. |
|
835 |
connectSock buffered:false. |
|
836 |
connectSock readWait. |
|
837 |
Transcript showCR:'accept'. |
|
838 |
sock := connectSock accept. |
|
839 |
sock isNil ifTrue:[ |
|
840 |
Transcript showCR:'accept failed.'. |
|
841 |
] ifFalse:[ |
|
842 |
sock buffered:false. |
|
843 |
Transcript showCR:'server: got it'. |
|
844 |
'can now do transfer via sock'. |
|
845 |
Transcript showCR:'read'. |
|
846 |
Transcript showCR:('got: ' , sock nextLine). |
|
847 |
||
848 |
Transcript showCR:'close'. |
|
849 |
sock close |
|
850 |
]. |
|
851 |
connectSock close. |
|
852 |
] |
|
853 |
] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
854 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
855 |
|
118 | 856 |
example (connect to above server and send some data; |
1009 | 857 |
Notice, this fails, if above server code is executed in the same ST/X image |
858 |
(at least on LINUX), since the OS does not correctly handle |
|
859 |
a connect from within an interrupted accept system call |
|
860 |
On SGI's SVR4, this works ok |
|
861 |
[exBegin] |
|
862 |
|sock| |
|
863 |
||
864 |
sock := Socket newUNIXclientTo:'/tmp/ud_socket'. |
|
865 |
sock isNil ifTrue:[ |
|
866 |
Transcript showCR:'nope' |
|
867 |
] ifFalse:[ |
|
868 |
sock buffered:false. |
|
869 |
Transcript showCR:'client: got it'. |
|
870 |
'can now do transfer via sock'. |
|
871 |
Transcript showCR:'sending <hello>'. |
|
872 |
sock nextPutLine:'hello'. |
|
873 |
sock close |
|
874 |
] |
|
875 |
[exEnd] |
|
1007 | 876 |
|
877 |
||
878 |
example (UDP await packet from a client and read some data): |
|
1009 | 879 |
[exBegin] |
880 |
|udpSock sock addr n dataBuffer| |
|
881 |
||
882 |
udpSock := Socket newUDPserverAtPort:9999. |
|
883 |
udpSock isNil ifTrue:[ |
|
884 |
Transcript showCR:'socket setup failed.'. |
|
885 |
] ifFalse:[ |
|
886 |
Transcript showCR:'wait'. |
|
887 |
udpSock readWait. |
|
888 |
||
889 |
addr := IPSocketAddress new. |
|
890 |
dataBuffer := ByteArray new:1000. |
|
891 |
n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size. |
|
892 |
n > 0 ifTrue:[ |
|
893 |
Transcript showCR:('got: ' , n printString , 'bytes from ' , addr printString). |
|
894 |
Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString). |
|
895 |
] ifFalse:[ |
|
896 |
Transcript showCR:'read failed'. |
|
897 |
]. |
|
898 |
||
899 |
Transcript showCR:'close'. |
|
900 |
udpSock close |
|
901 |
] |
|
902 |
[exEnd] |
|
1007 | 903 |
example (connect to above UDP server and send some data; |
1009 | 904 |
[exBegin] |
905 |
|sock| |
|
906 |
||
907 |
sock := Socket newUDP. |
|
908 |
sock isNil ifTrue:[ |
|
909 |
Transcript showCR:'nope' |
|
910 |
] ifFalse:[ |
|
911 |
sock sendTo:(IPSocketAddress new hostName:'localhost' port:9999) buffer:'hello world'. |
|
912 |
sock close |
|
913 |
] |
|
914 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
915 |
|
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
916 |
example: pingWalk (try to ping hosts on the local network) |
1009 | 917 |
[exBegin] |
918 |
|myName myAddress list top hosts walkProcess port| |
|
919 |
||
920 |
myName := OperatingSystem getHostName. |
|
921 |
myAddress := Socket ipAddressOfHost:myName. |
|
922 |
||
923 |
port := Socket portOfService:'echo'. |
|
924 |
port isNil ifTrue:[ |
|
925 |
self error:'dont know echo port'. |
|
926 |
^ self |
|
927 |
]. |
|
928 |
||
929 |
top := StandardSystemView new. |
|
930 |
top label:'PING net walk'. |
|
931 |
||
932 |
list := ScrollableView for:ListView in:top. |
|
933 |
list origin:0.0@0.0 corner:1.0@1.0. |
|
934 |
||
935 |
top openAndWait. |
|
936 |
||
937 |
walkProcess := [ |
|
938 |
|l low hi direction tryHostID dottedName hostName conn addr| |
|
939 |
||
940 |
l := SortedCollection new. |
|
941 |
||
942 |
' only works with type C-net |
|
943 |
the code below could simply do 1 to:254 do:[:hostID } |
|
944 |
but, to probe likely hosts earlier, the probing is done |
|
945 |
ping-pong like around my ip-address (assuming, that other machines |
|
946 |
have numbers around my own)'. |
|
947 |
||
948 |
low := hi := (myAddress at:4). |
|
949 |
direction := 1. |
|
950 |
||
951 |
[low > 0 or:[hi < 255]] whileTrue:[ |
|
952 |
direction > 0 ifTrue:[ |
|
953 |
hi := hi + 1. |
|
954 |
tryHostID := hi. |
|
955 |
direction := -1. |
|
956 |
] ifFalse:[ |
|
957 |
low := low - 1. |
|
958 |
tryHostID := low. |
|
959 |
direction := 1. |
|
960 |
]. |
|
961 |
(tryHostID between:1 and:254) ifTrue:[ |
|
962 |
dottedName := (myAddress at:1) printString |
|
963 |
, '.' , (myAddress at:2) printString |
|
964 |
, '.' , (myAddress at:3) printString |
|
965 |
, '.' , tryHostID printString. |
|
966 |
||
967 |
top label:'PING net walk - trying ' , dottedName. |
|
968 |
||
969 |
top windowGroup withCursor:Cursor wait do:[ |
|
970 |
conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000. |
|
971 |
conn notNil ifTrue:[ |
|
972 |
addr := Socket ipAddressOfHost:dottedName. |
|
973 |
hostName := Socket hostWithIpAddress:addr. |
|
974 |
hostName isNil ifTrue:[ |
|
975 |
hostName :='?' |
|
976 |
]. |
|
977 |
l add:(dottedName paddedTo:15 with:Character space) |
|
978 |
, ' ' |
|
979 |
, (hostName paddedTo:15 with:Character space) |
|
980 |
, ' up & reachable'. |
|
981 |
list list:l. |
|
982 |
conn close. |
|
983 |
] |
|
984 |
]. |
|
985 |
]. |
|
986 |
]. |
|
987 |
top label:'PING reachable hosts'. |
|
988 |
] forkAt:(Processor userBackgroundPriority). |
|
989 |
walkProcess name:'ping net walker'. |
|
990 |
[exEnd] |
|
991 |
||
992 |
||
993 |
This example creates a simple UDP server that accepts |
|
994 |
single packets from anybody and broadcasts them to all |
|
995 |
clients that have connected so far. |
|
996 |
||
997 |
[exBegin] |
|
998 |
| socket address buffer msgSize clients | |
|
999 |
clients := Set new. |
|
1000 |
address := IPSocketAddress new. |
|
1001 |
buffer := String new: 1024. |
|
1002 |
||
1003 |
socket := self newUDPserverAtPort: 6666. |
|
1004 |
||
1005 |
Transcript showCR: 'server starting'. |
|
1006 |
||
1007 |
[ |
|
1008 |
[true] whileTrue: [ |
|
1009 |
(socket readWaitWithTimeoutMs: 200) ifFalse: [ |
|
1010 |
msgSize := socket |
|
1011 |
receiveFrom: address |
|
1012 |
buffer: buffer |
|
1013 |
start: 1 |
|
1014 |
for: buffer size. |
|
1015 |
||
1016 |
clients add: address copy. |
|
1017 |
clients do: [ :clientAddress | |
|
1018 |
socket |
|
1019 |
sendTo: clientAddress |
|
1020 |
buffer: buffer |
|
1021 |
start: 1 |
|
1022 |
for: msgSize]] |
|
1023 |
] |
|
1024 |
] valueNowOrOnUnwindDo:[ |
|
1025 |
Transcript showCR: 'server shutting down'. |
|
1026 |
socket close |
|
1027 |
] |
|
1028 |
[exEnd] |
|
817 | 1029 |
|
1030 |
send a datagram to above server: |
|
1009 | 1031 |
[exBegin] |
1032 |
||
1033 |
| socket address buffer host msg | |
|
1034 |
||
1035 |
host := Dialog |
|
1036 |
request: 'What is the name of the server''s host?' |
|
1037 |
initialAnswer: 'localhost'. |
|
1038 |
||
1039 |
socket := self newUDP. |
|
1040 |
||
1041 |
address := IPSocketAddress hostName: host port: 6666. |
|
1042 |
||
1043 |
buffer := ByteArray new: 1000. |
|
1044 |
[ |
|
1045 |
[(msg := Dialog request: 'Say something') isEmpty] whileFalse:[ |
|
1046 |
| replySize stream | |
|
1047 |
||
1048 |
socket writeWait. |
|
1049 |
stream := buffer writeStream. |
|
1050 |
stream nextPutAll: msg. |
|
1051 |
socket sendTo:address buffer:buffer start:1 for:stream position. |
|
1052 |
socket readWait. |
|
1053 |
||
1054 |
replySize := socket receiveFrom:address buffer:buffer. |
|
1055 |
replySize > 0 ifTrue: [ |
|
1056 |
Transcript cr; nextPutAll: 'Server acknowledged: '. |
|
1057 |
Transcript show: ((buffer copyFrom: 1 to: replySize) asString) |
|
1058 |
] |
|
1059 |
] |
|
1060 |
] valueNowOrOnUnwindDo: [socket close]. |
|
1061 |
Transcript cr |
|
1062 |
[exEnd] |
|
25 | 1063 |
" |
1064 |
! ! |
|
1065 |
||
867 | 1066 |
!Socket class methodsFor:'Compatibility ST80'! |
91 | 1067 |
|
126 | 1068 |
family:domainSymbol type:typeSymbol |
1069 |
"create a socket for domain and type - ST80 simply uses a different name. |
|
1070 |
Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns; |
|
1071 |
Type must be #stream, #datagram or #raw |
|
91 | 1072 |
|
811 | 1073 |
XXX: currently only the #inet and #unix domains is supported" |
91 | 1074 |
|
126 | 1075 |
^ self domain:domainSymbol type:typeSymbol |
51 | 1076 |
|
126 | 1077 |
" |
1078 |
Socket family:#inet type:#stream |
|
1079 |
Socket family:#inet type:#datagram |
|
1080 |
Socket family:#unix type:#stream |
|
1081 |
" |
|
867 | 1082 |
! |
115 | 1083 |
|
617
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1084 |
getHostname |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1085 |
"return the computers hostname string" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1086 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1087 |
^ OperatingSystem getHostName |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1088 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1089 |
"Created: / 27.2.1998 / 02:32:17 / cg" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1090 |
! |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1091 |
|
126 | 1092 |
sockStream |
1093 |
"return the type code for stream sockets" |
|
51 | 1094 |
|
126 | 1095 |
^ #stream |
44 | 1096 |
! ! |
1097 |
||
464 | 1098 |
!Socket class methodsFor:'Signal constants'! |
21 | 1099 |
|
1100 |
brokenConnectionSignal |
|
1101 |
"return the signal used to tell broken connections. |
|
1102 |
Since in unix, this is the same as the broken pipe signal, |
|
1103 |
return that one. |
|
1104 |
(for other Operatingsystems, this may change ..)" |
|
1105 |
||
1106 |
^ PipeStream brokenPipeSignal |
|
887 | 1107 |
! |
1108 |
||
1109 |
invalidArgumentsSignal |
|
1110 |
"dummy for compatibility" |
|
1111 |
||
1112 |
^ self errorSignal |
|
21 | 1113 |
! ! |
1114 |
||
464 | 1115 |
!Socket class methodsFor:'debugging'! |
71 | 1116 |
|
1117 |
debug:aBoolean |
|
1118 |
"turn on/off internal debugprints. |
|
1119 |
This method is for ST/X debugging only and |
|
1120 |
may be removed in later versions" |
|
1121 |
||
1122 |
%{ /* NOCONTEXT */ |
|
1123 |
||
1124 |
__debugging__ = (aBoolean == true); |
|
1125 |
%} |
|
93 | 1126 |
" |
1127 |
Socket debug:true |
|
1128 |
Socket debug:false |
|
1129 |
" |
|
71 | 1130 |
! ! |
1131 |
||
464 | 1132 |
!Socket class methodsFor:'easy tcp/ip instance creation'! |
126 | 1133 |
|
1134 |
connectTo:service on:host |
|
1135 |
"standard & easy client setup: |
|
1009 | 1136 |
create new client tcp socket, bind and connect; |
1137 |
return the socket. |
|
811 | 1138 |
The thread block (interruptable), until the connection is |
126 | 1139 |
established." |
1140 |
||
968 | 1141 |
self obsoleteMethodWarning:'use newTCP: / connect'. |
1142 |
||
126 | 1143 |
^ (self new) for:host port:(self portOfService:service). |
1144 |
||
1145 |
" |
|
1146 |
Socket connectTo:9995 on:'clam' |
|
1147 |
Socket connectTo:'finger' on:'clam' |
|
1148 |
Socket connectTo:'ftp' on:'clam' |
|
1149 |
Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER') |
|
1150 |
" |
|
1151 |
! |
|
1152 |
||
1153 |
provide:service |
|
1154 |
"standard & easy server setup: |
|
811 | 1155 |
create a new TCP server socket providing a service." |
126 | 1156 |
|
1157 |
|newSock| |
|
1158 |
||
968 | 1159 |
self obsoleteMethodWarning:'use newTCP: / listen'. |
1160 |
||
126 | 1161 |
newSock := (self new) for:nil port:(self portOfService:service). |
1162 |
newSock notNil ifTrue:[ |
|
1009 | 1163 |
newSock listenFor:5. |
126 | 1164 |
]. |
1165 |
^ newSock |
|
1166 |
||
1167 |
" |
|
1168 |
Socket provide:9995 |
|
1169 |
(Socket provide:9996) accept |
|
1170 |
Socket provide:'nntp' |
|
1171 |
" |
|
1172 |
! ! |
|
1173 |
||
464 | 1174 |
!Socket class methodsFor:'general instance creation'! |
126 | 1175 |
|
1176 |
domain:domainSymbol type:type |
|
1177 |
"create a socket for domain and type - |
|
1178 |
neither any connect nor binding is done. |
|
819 | 1179 |
Domain must be one of the symbols: |
1180 |
#inet, #unix, #appletalk, #decnet, #xns, ...; |
|
1181 |
Type must be: |
|
1182 |
#stream, #datagram or #raw |
|
126 | 1183 |
|
1184 |
XXX: currently only the #inet domain is supported" |
|
1185 |
||
1186 |
^ self new domain:domainSymbol type:type |
|
1187 |
||
1188 |
" |
|
1189 |
Socket domain:#inet type:#stream |
|
1190 |
Socket domain:#inet type:#datagram |
|
1191 |
Socket domain:#unix type:#stream |
|
1192 |
Socket domain:#appletalk type:#stream |
|
819 | 1193 |
Socket domain:#decnet type:#stream |
869 | 1194 |
Socket domain:#irda type:#stream |
126 | 1195 |
" |
1196 |
! |
|
1197 |
||
576 | 1198 |
new |
1199 |
"create a TCP socket" |
|
1200 |
||
1201 |
^ super new buffered:false |
|
1202 |
! |
|
1203 |
||
126 | 1204 |
newTCP |
1205 |
"create a TCP socket - no binding or other setup is done, |
|
1206 |
neither connect nor connect-wait is done." |
|
1207 |
||
1208 |
^ self new domain:#inet type:#stream |
|
1209 |
||
1210 |
"Socket newUDP" |
|
1211 |
! |
|
1212 |
||
1213 |
newTCP:aServiceOrNil |
|
1214 |
"create a TCP socket for a service - |
|
1215 |
neither connect nor connect-wait is done." |
|
1216 |
||
1217 |
|newSock| |
|
1218 |
||
1219 |
newSock := self newTCP. |
|
1220 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
819 | 1221 |
(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[ |
1222 |
^ nil |
|
1223 |
] |
|
126 | 1224 |
]. |
1225 |
^ newSock |
|
1226 |
||
1227 |
||
1228 |
"Socket newTCP:'nntp'" |
|
1229 |
"Socket newTCP:9995" |
|
1230 |
! |
|
1231 |
||
576 | 1232 |
newTCPclientToAddress:aHostAddress port:aService |
1233 |
"create a new TCP client socket connecting to a service. |
|
1234 |
Return a socket instance if ok, nil on failure. |
|
1235 |
Block until a connection is established (but only the current thread; |
|
1236 |
not the whole smalltalk). |
|
1237 |
See also: #newTCPclientToAddress:port:withTimeout:" |
|
1238 |
||
1239 |
^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil |
|
1240 |
! |
|
1241 |
||
1242 |
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis |
|
1243 |
"create a new TCP client socket connecting to a service. |
|
1244 |
Return a socket instance if ok, nil on failure. |
|
1245 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 1246 |
and return nil." |
576 | 1247 |
|
1248 |
^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis |
|
1249 |
! |
|
1250 |
||
126 | 1251 |
newTCPclientToHost:hostname port:aService |
1252 |
"create a new TCP client socket connecting to a service. |
|
1253 |
Return a socket instance if ok, nil on failure. |
|
1254 |
Block until a connection is established (but only the current thread; |
|
1255 |
not the whole smalltalk). |
|
1256 |
See also: #newTCPclientToHost:port:withTimeout:" |
|
1257 |
||
1258 |
^ self newTCPclientToHost:hostname port:aService withTimeout:nil |
|
1259 |
||
1260 |
" |
|
1261 |
Socket newTCPclientToHost:'localhost' port:'nntp' |
|
1262 |
" |
|
1263 |
||
1264 |
"Created: 31.10.1995 / 18:54:11 / cg" |
|
1265 |
! |
|
1266 |
||
1267 |
newTCPclientToHost:hostname port:aService withTimeout:millis |
|
1268 |
"create a new TCP client socket connecting to a service. |
|
1269 |
Return a socket instance if ok, nil on failure. |
|
1270 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
1271 |
and return nil.." |
|
1272 |
||
1273 |
|newSock| |
|
1274 |
||
1275 |
newSock := self newTCP. |
|
1276 |
newSock notNil ifTrue:[ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1277 |
(newSock connectTo:hostname |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1278 |
port:(self portOfService:aService protocol:'tcp') |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1279 |
withTimeout:millis |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1280 |
) ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1281 |
newSock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1282 |
^ nil |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1283 |
] |
126 | 1284 |
]. |
1285 |
^ newSock |
|
1286 |
" |
|
1287 |
same as: |
|
1288 |
^ (self new) for:hostname port:(self portOfService:aPort). |
|
1289 |
" |
|
1290 |
" |
|
1291 |
Socket newTCPclientToHost:'slsv6bt' port:'nntp' |
|
1292 |
Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000 |
|
1293 |
" |
|
604 | 1294 |
|
1295 |
"Modified: / 16.1.1998 / 09:47:06 / stefan" |
|
126 | 1296 |
! |
1297 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1298 |
newTCPserverAtAnonymousPort |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1299 |
"create a new TCP server socket providing service on |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1300 |
a new anonymous port. The portNr is assigned by the OS." |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1301 |
|
811 | 1302 |
^ self newTCPserverAtPort:0 |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1303 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1304 |
! |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1305 |
|
126 | 1306 |
newTCPserverAtPort:aService |
1307 |
"create a new TCP server socket providing service." |
|
1308 |
||
1309 |
|newSock| |
|
1310 |
||
1311 |
newSock := self newTCP. |
|
1312 |
newSock notNil ifTrue:[ |
|
1313 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1314 |
^ nil |
|
1315 |
] |
|
1316 |
]. |
|
1317 |
^ newSock |
|
1318 |
" |
|
1319 |
same as: |
|
1320 |
^ (self new) for:nil port:aPort |
|
1321 |
" |
|
1322 |
! |
|
1323 |
||
1324 |
newUDP |
|
1325 |
"create a UDP socket - no binding or other setup is done, |
|
1326 |
neither connect nor connect-wait is done." |
|
1327 |
||
1328 |
^ self new domain:#inet type:#datagram |
|
1329 |
||
1330 |
"Socket newUDP" |
|
1331 |
! |
|
1332 |
||
1333 |
newUDP:aServiceOrNil |
|
1334 |
"create a UDP socket for a service - |
|
1335 |
neither connect nor connect-wait is done." |
|
1336 |
||
1337 |
|newSock| |
|
1338 |
||
1339 |
newSock := self newUDP. |
|
1340 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
819 | 1341 |
(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[ |
1342 |
^ nil |
|
1343 |
] |
|
126 | 1344 |
]. |
1345 |
^ newSock |
|
1346 |
||
1347 |
"Socket newUDP:nil" |
|
1348 |
! |
|
1349 |
||
1350 |
newUDPserverAtPort:aService |
|
1351 |
"create a new UDP server socket providing service." |
|
1352 |
||
1353 |
|newSock| |
|
1354 |
||
1355 |
newSock := self newUDP. |
|
1356 |
newSock notNil ifTrue:[ |
|
1357 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1358 |
^ nil |
|
1359 |
] |
|
1360 |
]. |
|
1361 |
^ newSock |
|
1362 |
" |
|
1363 |
same as: |
|
1364 |
^ (self new) for:nil udpPort:aPort |
|
1365 |
" |
|
1366 |
! |
|
1367 |
||
1368 |
newUNIX |
|
1369 |
"create a UNIX domain socket - no binding or other setup is done, |
|
811 | 1370 |
neither connect nor connect-wait is done. |
1371 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1372 |
return nil." |
|
126 | 1373 |
|
1374 |
^ self new domain:#unix type:#stream |
|
1375 |
||
1376 |
" |
|
1377 |
Socket newUNIX |
|
1378 |
" |
|
1379 |
! |
|
1380 |
||
1381 |
newUNIXclientTo:pathName |
|
1382 |
"create a new UNIX client socket connecting to a pathname. |
|
1383 |
Return a socket instance if ok, nil on failure. |
|
1384 |
Block until a connection is established (but only the current thread; |
|
1385 |
not the whole smalltalk). |
|
811 | 1386 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
1387 |
return nil. |
|
126 | 1388 |
See also: #newUNIXclientTo:withTimeout:" |
1389 |
||
1390 |
^ self newUNIXclientTo:pathName withTimeout:nil |
|
1391 |
||
1392 |
! |
|
1393 |
||
1394 |
newUNIXclientTo:pathName withTimeout:millis |
|
1395 |
"create a new UNIX client socket connecting to a pathname. |
|
1396 |
Return a socket instance if ok, nil on failure. |
|
1397 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 1398 |
and return nil. |
1399 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1400 |
return nil." |
|
126 | 1401 |
|
1402 |
|newSock| |
|
1403 |
||
1404 |
newSock := self newUNIX. |
|
1405 |
newSock notNil ifTrue:[ |
|
812 | 1406 |
(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[ |
1407 |
newSock close. |
|
1408 |
^ nil |
|
1409 |
] |
|
126 | 1410 |
]. |
1411 |
^ newSock |
|
1412 |
||
1413 |
" |
|
1414 |
|s| |
|
1415 |
||
1416 |
s := Socket newUNIXclientTo:'/tmp/foo' |
|
1417 |
" |
|
1418 |
! |
|
1419 |
||
1420 |
newUNIXserverAt:pathName |
|
811 | 1421 |
"create a new UNIX server socket providing service at a pathname. |
1422 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1423 |
return nil." |
|
126 | 1424 |
|
1425 |
|newSock| |
|
1426 |
||
1427 |
newSock := self newUNIX. |
|
1428 |
newSock notNil ifTrue:[ |
|
812 | 1429 |
(newSock bindTo:pathName address:nil) ifFalse:[ |
1430 |
^ nil |
|
1431 |
] |
|
126 | 1432 |
]. |
1433 |
^ newSock |
|
1434 |
||
1435 |
" |
|
1436 |
|s s2| |
|
1437 |
||
1438 |
s := Socket newUNIXserverAt:'/tmp/foo'. |
|
1439 |
s listenFor:5. |
|
1440 |
s2 := s accept. |
|
1441 |
" |
|
1442 |
! ! |
|
1443 |
||
525 | 1444 |
!Socket class methodsFor:'host queries'! |
1445 |
||
1446 |
appletalkAddressOfHost:aHostName |
|
1447 |
"return the APPLETALK address for a hostname as a byteArray, |
|
819 | 1448 |
where the network bytes come first (no matter what the local byteorder is) |
1449 |
followed by the node byte. |
|
525 | 1450 |
If the host is unknown, return nil. |
812 | 1451 |
This is the reverse operation to #hostWithAppletalkAddress:. |
1452 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1453 |
|
1454 |
%{ |
|
526 | 1455 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
819 | 1456 |
struct sockaddr_at sa; |
525 | 1457 |
struct hostent *hp ; |
1458 |
long addr; |
|
653 | 1459 |
OBJ rslt; |
525 | 1460 |
|
529 | 1461 |
sa.sat_family = -1; |
525 | 1462 |
|
1463 |
if (__isString(aHostName)) { |
|
789 | 1464 |
bzero(&sa, sizeof(sa)) ; |
1465 |
||
1466 |
/* do we know the host's address? */ |
|
1467 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1468 |
if (hp == NULL) { |
|
819 | 1469 |
DBGPRINTF(("SOCKET: unknown appletalk host: %s\n", __stringVal(aHostName))); |
789 | 1470 |
RETURN ( nil ); |
1471 |
} |
|
1472 |
bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ; |
|
1473 |
sa.sat_family = hp->h_addrtype; |
|
525 | 1474 |
} |
1475 |
||
752 | 1476 |
/* if the addressing family is not AF_APPLETALK, Return nil */ |
812 | 1477 |
if (sa.sat_family != AF_APPLETALK) { |
789 | 1478 |
DBGPRINTF(("SOCKET: not an appletalk host\n")); |
1479 |
RETURN ( nil ); |
|
525 | 1480 |
} |
1481 |
||
1482 |
sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net); |
|
653 | 1483 |
rslt = __BYTEARRAY_NEW_INT(3); |
1484 |
if (rslt != nil) { |
|
789 | 1485 |
__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sat_addr.s_net >> 8) & 0xFF; |
1486 |
__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF; |
|
1487 |
__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sat_addr.s_node) & 0xFF; |
|
653 | 1488 |
RETURN (rslt); |
1489 |
} |
|
525 | 1490 |
#endif |
1491 |
%}. |
|
653 | 1492 |
^ nil |
525 | 1493 |
|
1494 |
! |
|
1495 |
||
1496 |
hostWithAppletalkAddress:anAddress |
|
1497 |
"return the hostname for an APPLETALK address. |
|
1498 |
The address is supposed to be a byteArray consisting of 3 bytes, |
|
1499 |
the network bytes come first (no matter what the local byteorder is). |
|
1500 |
The last byte is the node number. |
|
1501 |
Nil is returned for an unknown host or if its not an appletalk host. |
|
812 | 1502 |
This is is the reverse operation to #appletalkAddressOfHost:. |
1503 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1504 |
|
1505 |
|b1 b2 b3 b4| |
|
1506 |
||
812 | 1507 |
b1 := anAddress at:1. "/ net-hi |
1508 |
b2 := anAddress at:2. "/ net-low |
|
1509 |
b3 := anAddress at:3. "/ node |
|
525 | 1510 |
%{ |
1511 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
|
1512 |
struct sockaddr_at sa ; |
|
1513 |
struct hostent *hp ; |
|
1514 |
||
1515 |
sa.sat_family = -1; |
|
1516 |
||
1517 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
|
1518 |
bzero(&sa, sizeof(sa)) ; |
|
1519 |
||
1009 | 1520 |
sa.sat_addr.s_net = __intVal(b1) & 0xFF; |
1521 |
sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (__intVal(b2) & 0xFF); |
|
529 | 1522 |
sa.sat_addr.s_net = htons(sa.sat_addr.s_net); |
1009 | 1523 |
sa.sat_addr.s_node = __intVal(b3) & 0xFF; |
529 | 1524 |
sa.sat_family = AF_APPLETALK; |
1525 |
||
525 | 1526 |
/* do we know the host's address? */ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
1527 |
GETHOSTBYADDR(hp, (char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK); |
525 | 1528 |
if (hp != NULL) { |
1529 |
sa.sat_family = hp->h_addrtype; |
|
1530 |
} else { |
|
819 | 1531 |
DBGPRINTF(("SOCKET: unknown appletalk address: %d.%d.%d.%d\n", |
1009 | 1532 |
__intVal(b1), __intVal(b2), __intVal(b3))); |
525 | 1533 |
} |
1534 |
} |
|
1535 |
||
752 | 1536 |
/* if the addressing family is not AF_APPLETALK, Return nil */ |
525 | 1537 |
if (sa.sat_family != AF_APPLETALK) { |
819 | 1538 |
DBGPRINTF(("SOCKET: not an appletalk host\n")); |
525 | 1539 |
RETURN ( nil ); |
1540 |
} |
|
1541 |
||
1542 |
if (hp != NULL) { |
|
1543 |
RETURN (__MKSTRING(hp->h_name)); |
|
1544 |
} |
|
1545 |
#endif |
|
1546 |
RETURN (nil); |
|
1547 |
%}. |
|
1548 |
" |
|
1549 |
Socket appletalkAddressOfHost:'clam' |
|
1550 |
Socket hostWithAppletalkAddress:#[1 2 3] |
|
1551 |
" |
|
126 | 1552 |
! |
1553 |
||
1554 |
hostWithIpAddress:anAddress |
|
1555 |
"return the hostname for an IP (internet-) address. |
|
1556 |
The address is supposed to be a byteArray consisting of 4 bytes, |
|
1557 |
the network bytes come first (no matter what the local byteorder is). |
|
525 | 1558 |
Nil is returned for an unknown host or if its not an internet host. |
126 | 1559 |
This is the reverse operation to #ipAddressOfHost:." |
1560 |
||
1561 |
|b1 b2 b3 b4| |
|
1562 |
||
1563 |
b1 := anAddress at:1. |
|
1564 |
b2 := anAddress at:2. |
|
1565 |
b3 := anAddress at:3. |
|
1566 |
b4 := anAddress at:4. |
|
1567 |
%{ |
|
525 | 1568 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
126 | 1569 |
struct sockaddr_in sa ; |
1570 |
struct hostent *hp ; |
|
1571 |
||
525 | 1572 |
sa.sin_family = -1; |
126 | 1573 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
822 | 1574 |
bzero(&sa, sizeof(sa)) ; |
1009 | 1575 |
sa.sin_addr.s_addr = __intVal(b1) & 0xFF; |
1576 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b2) & 0xFF); |
|
1577 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b3) & 0xFF); |
|
1578 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b4) & 0xFF); |
|
822 | 1579 |
sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr); |
1580 |
sa.sin_family = AF_INET; |
|
1581 |
/* do we know the host's address? */ |
|
1582 |
GETHOSTBYADDR(hp, (char *) &sa.sin_addr, sizeof(sa.sin_addr), AF_INET); |
|
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1583 |
|
822 | 1584 |
if (hp == NULL) { |
1585 |
DBGPRINTF(("SOCKET: unknown ip address: %d.%d.%d.%d\n", |
|
1009 | 1586 |
__intVal(b1), __intVal(b2), __intVal(b3), __intVal(b4))); |
822 | 1587 |
} else { |
1588 |
sa.sin_family = hp->h_addrtype; |
|
1589 |
} |
|
126 | 1590 |
} |
1591 |
||
752 | 1592 |
/* if the addressing family is not AF_INET, Return nil */ |
126 | 1593 |
if (sa.sin_family != AF_INET) { |
822 | 1594 |
RETURN ( nil ); |
126 | 1595 |
} |
525 | 1596 |
|
1597 |
if (hp != NULL) { |
|
822 | 1598 |
RETURN (__MKSTRING(hp->h_name)); |
525 | 1599 |
} |
1600 |
||
1601 |
/* |
|
752 | 1602 |
* Return it in dot-notation |
525 | 1603 |
*/ |
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1604 |
RETURN (__MKSTRING(inet_ntoa(sa.sin_addr))); |
418 | 1605 |
#else |
1606 |
RETURN (nil); |
|
1607 |
#endif |
|
126 | 1608 |
%} |
1609 |
||
1610 |
" |
|
1611 |
Socket ipAddressOfHost:'clam' |
|
1612 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') |
|
1613 |
Socket ipAddressOfHost:'porty' |
|
1614 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') |
|
1615 |
Socket hostWithIpAddress:#[1 2 3 4] |
|
796 | 1616 |
Socket hostWithIpAddress:#[127 0 0 1] |
126 | 1617 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4') |
1618 |
" |
|
1619 |
! |
|
1620 |
||
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1621 |
hostWithIpV6Address:anAddress |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1622 |
"return the hostname for an IPv6 (internet-) address. |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1623 |
The address is supposed to be a byteArray consisting ??? bytes, |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1624 |
the network bytes come first (no matter what the local byteorder is). |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1625 |
Nil is returned for an unknown host or if its not an internet host. |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1626 |
This is the reverse operation to #ipV6AddressOfHost:." |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1627 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1628 |
%{ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1629 |
#if !defined(NO_SOCKET) && defined(AF_INET6) |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1630 |
struct sockaddr_in6 sa ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1631 |
struct hostent *hp ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1632 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1633 |
sa.sin6_family = -1; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1634 |
if (__isByteArray(anAddress)) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1635 |
bzero(&sa, sizeof(sa)) ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1636 |
if (__byteArraySize(anAddress) <= sizeof(sa.sin6_addr.s6_addr)) |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1637 |
goto bad; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1638 |
bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(anAddress)->ba_element, sizeof(sa.sin6_addr.s6_addr)); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1639 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1640 |
sa.sin6_family = AF_INET6; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1641 |
/* do we know the host's address? */ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1642 |
GETHOSTBYADDR(hp, (char *) &sa.sin6_addr, sizeof(sa.sin6_addr), AF_INET6); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1643 |
if (hp == NULL) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1644 |
DBGPRINTF(("SOCKET: unknown ipv6 address: %d.%d.%d.%d...\n", |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1645 |
sa.sin6_addr.s6_addr[0], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1646 |
sa.sin6_addr.s6_addr[1], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1647 |
sa.sin6_addr.s6_addr[2], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1648 |
sa.sin6_addr.s6_addr[3] )); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1649 |
} else { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1650 |
sa.sin6_family = hp->h_addrtype; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1651 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1652 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1653 |
bad: ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1654 |
/* if the addressing family is not AF_INET6, Return nil */ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1655 |
if (sa.sin6_family != AF_INET6) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1656 |
DBGPRINTF(("SOCKET: not an ipv6 host\n")); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1657 |
RETURN ( nil ); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1658 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1659 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1660 |
if (hp != NULL) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1661 |
RETURN (__MKSTRING(hp->h_name)); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1662 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1663 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1664 |
/* |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1665 |
* Return it in dot-notation |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1666 |
*/ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1667 |
RETURN (__MKSTRING(inet_ntoa(sa.sin6_addr))); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1668 |
#else |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1669 |
RETURN (nil); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1670 |
#endif |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1671 |
%} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1672 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1673 |
" |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1674 |
Socket ipV6AddressOfHost:'clam' |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1675 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1676 |
Socket ipV6AddressOfHost:'porty' |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1677 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1678 |
Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14] |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1679 |
" |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1680 |
! |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1681 |
|
6 | 1682 |
ipAddressOfHost:aHostName |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1683 |
"return the IP (internet-) number for a hostname as a byteArray, |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1684 |
where the network bytes come first (no matter what the cpus byteOrder is). |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1685 |
If the host is unknown, return nil. |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1686 |
This is the reverse operation to #hostWithIpAddress:." |
6 | 1687 |
|
1688 |
%{ |
|
525 | 1689 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
6 | 1690 |
struct sockaddr_in sa ; |
1691 |
struct hostent *hp ; |
|
1692 |
long addr; |
|
653 | 1693 |
OBJ rslt; |
6 | 1694 |
|
525 | 1695 |
sa.sin_family = -1; |
1696 |
||
21 | 1697 |
if (__isString(aHostName)) { |
812 | 1698 |
bzero(&sa, sizeof(sa)) ; |
1699 |
if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) { |
|
1700 |
/* is Internet addr in octet notation */ |
|
1701 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); |
|
1702 |
sa.sin_family = AF_INET; |
|
1703 |
} else { |
|
1704 |
/* do we know the host's address? */ |
|
1705 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1706 |
if (hp == NULL) { |
|
819 | 1707 |
DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName))); |
812 | 1708 |
RETURN ( nil ); |
1709 |
} |
|
1710 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
1711 |
sa.sin_family = hp->h_addrtype; |
|
1712 |
} |
|
6 | 1713 |
} |
525 | 1714 |
|
752 | 1715 |
/* if the addressing family is not AF_INET, Return nil */ |
6 | 1716 |
if (sa.sin_family != AF_INET) { |
819 | 1717 |
DBGPRINTF(("SOCKET: not an ip host\n")); |
812 | 1718 |
RETURN ( nil ); |
6 | 1719 |
} |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1720 |
|
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1721 |
sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr); |
653 | 1722 |
rslt = __BYTEARRAY_NEW_INT(4); |
1723 |
if (rslt != nil) { |
|
812 | 1724 |
__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF; |
1725 |
__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF; |
|
1726 |
__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF; |
|
1727 |
__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF; |
|
653 | 1728 |
RETURN (rslt); |
1729 |
} |
|
418 | 1730 |
#endif |
525 | 1731 |
%}. |
653 | 1732 |
^ nil |
21 | 1733 |
|
71 | 1734 |
" |
796 | 1735 |
Socket ipAddressOfHost:'localhost' |
1736 |
Socket ipAddressOfHost:'exept' |
|
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1737 |
Socket ipAddressOfHost:'1.2.3.4' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1738 |
Socket ipAddressOfHost:'193.15.16.17' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1739 |
Socket ipAddressOfHost:'josef' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1740 |
Socket ipAddressOfHost:'styx.com' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1741 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1742 |
Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') |
71 | 1743 |
" |
819 | 1744 |
! |
1745 |
||
1746 |
ipV6AddressOfHost:aHostName |
|
1747 |
"return the IPv6 (internet-) number for a hostname as a byteArray, |
|
1748 |
where the network bytes come first (no matter what the cpus byteOrder is). |
|
1749 |
If the host is unknown, return nil. |
|
1750 |
This is the reverse operation to #hostWithIpV6Address:." |
|
1751 |
||
1752 |
%{ |
|
1753 |
#if !defined(NO_SOCKET) && defined(AF_INET6) |
|
1754 |
struct sockaddr_in6 sa; |
|
1755 |
struct hostent *hp ; |
|
1756 |
long addr; |
|
1757 |
OBJ rslt; |
|
1758 |
||
1759 |
sa.sin6_family = -1; |
|
1760 |
||
1761 |
if (__isString(aHostName)) { |
|
1762 |
bzero(&sa, sizeof(sa)) ; |
|
1763 |
#if 0 |
|
1764 |
if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) { |
|
1765 |
/* is Internet addr in octet notation */ |
|
1766 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); |
|
1767 |
sa.sin_family = AF_INET; |
|
1768 |
} else |
|
1769 |
#endif |
|
1770 |
{ |
|
1771 |
/* do we know the host's address? */ |
|
1772 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1773 |
if (hp == NULL) { |
|
1774 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName))); |
|
1775 |
RETURN ( nil ); |
|
1776 |
} |
|
1777 |
bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ; |
|
1778 |
sa.sin6_family = hp->h_addrtype; |
|
1779 |
} |
|
1780 |
} |
|
1781 |
||
1782 |
/* if the addressing family is not AF_INET, Return nil */ |
|
1783 |
if (sa.sin6_family != AF_INET) { |
|
1784 |
DBGPRINTF(("SOCKET: not an ipv6 host\n")); |
|
1785 |
RETURN ( nil ); |
|
1786 |
} |
|
1787 |
||
1788 |
rslt = __BYTEARRAY_NEW_INT(hp->h_length); |
|
1789 |
if (rslt != nil) { |
|
1790 |
bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(rslt)->ba_element, hp->h_length); |
|
1791 |
RETURN (rslt); |
|
1792 |
} |
|
1793 |
#endif |
|
1794 |
%}. |
|
1795 |
^ nil |
|
1796 |
||
1797 |
" |
|
1798 |
Socket ipV6AddressOfHost:'localhost' |
|
1799 |
Socket ipV6AddressOfHost:'exept' |
|
1800 |
Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16' |
|
1801 |
Socket ipV6AddressOfHost:'193.15.16.17' |
|
1802 |
Socket ipV6AddressOfHost:'josef' |
|
1803 |
Socket ipV6AddressOfHost:'styx.com' |
|
1804 |
Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') |
|
1805 |
Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') |
|
1806 |
" |
|
531 | 1807 |
! ! |
1808 |
||
1809 |
!Socket class methodsFor:'queries'! |
|
1810 |
||
1811 |
domainOfProtocol:aProtocol |
|
1812 |
"given a protocols name (i.e. tcp, udp etc) return the domain. |
|
1813 |
This method needs more ... - or is there a way to get this from the system ?" |
|
1814 |
||
1815 |
" |
|
1816 |
tcp/ip stuff |
|
1817 |
" |
|
1818 |
(aProtocol = 'tcp') ifTrue:[^ #inet]. |
|
1819 |
(aProtocol = 'udp') ifTrue:[^ #inet]. |
|
1820 |
(aProtocol = 'ip') ifTrue:[^ #inet]. |
|
1821 |
" |
|
1822 |
unix domain |
|
1823 |
" |
|
1824 |
(aProtocol = 'ud') ifTrue:[^ #unix]. |
|
1825 |
||
1826 |
" |
|
1827 |
add x25 stuff (if any) here ... |
|
1828 |
" |
|
1829 |
" |
|
1830 |
add appletalk stuff (if any) here ... |
|
1831 |
" |
|
1832 |
" |
|
1833 |
add other stuff (if any) here ... |
|
1834 |
" |
|
1835 |
^ nil |
|
1836 |
||
1837 |
" |
|
1838 |
Socket domainOfProtocol:'tcp' |
|
1839 |
Socket domainOfProtocol:'ucp' |
|
1840 |
Socket domainOfProtocol:(Socket protocolOfService:'nntp') |
|
1841 |
Socket domainOfProtocol:(Socket protocolOfService:'echo') |
|
1842 |
" |
|
6 | 1843 |
! |
1844 |
||
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1845 |
networkLongOrderIsMSB |
964 | 1846 |
"return true, if the network-byte-order of longs is MSB (which it is). |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1847 |
To be used as in: |
1009 | 1848 |
'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'." |
964 | 1849 |
|
1850 |
^ true |
|
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1851 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1852 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1853 |
Socket networkLongOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1854 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1855 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1856 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1857 |
networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1858 |
"return true, if the network-byte-order of shorts is MSB. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1859 |
To be used as in: |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1860 |
'aStream nextPutShort:someValue MSB:(Socket networkShortOrderIsMSB)'." |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1861 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1862 |
%{ /* NOCONTEXT */ |
418 | 1863 |
#ifndef NO_SOCKET |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1864 |
/* |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1865 |
* mhmh - do c-compilers optimize this away ? |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1866 |
*/ |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1867 |
if (htons(0x3210) == 0x3210) { |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1868 |
RETURN (true); |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1869 |
} |
418 | 1870 |
#endif |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1871 |
%}. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1872 |
^ false |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1873 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1874 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1875 |
Socket networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1876 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1877 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1878 |
|
0 | 1879 |
portOfService:aNameOrNumber |
819 | 1880 |
"returns the port-number for a given IP-service |
0 | 1881 |
or nil if no such service exists; |
1882 |
- used to convert service names to portNumbers" |
|
1883 |
||
91 | 1884 |
^ self portOfService:aNameOrNumber protocol:nil |
1885 |
||
28 | 1886 |
" |
1887 |
Socket portOfService:'finger' |
|
74 | 1888 |
Socket portOfService:'nntp' |
1889 |
Socket portOfService:'echo' |
|
1890 |
Socket portOfService:'snmp' |
|
28 | 1891 |
" |
0 | 1892 |
! |
1893 |
||
91 | 1894 |
portOfService:aNameOrNumber protocol:aProtocol |
819 | 1895 |
"returns the port-number for a given IP-service |
91 | 1896 |
or nil if no such service exists; |
1897 |
- used to convert service names to portNumbers" |
|
1898 |
||
604 | 1899 |
%{ /* NOCONTEXT */ |
418 | 1900 |
#ifndef NO_SOCKET |
91 | 1901 |
struct servent *servent = NULL; |
1902 |
char *protocol; |
|
1903 |
int tryBoth = 0; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1904 |
short portNo; |
91 | 1905 |
|
604 | 1906 |
if (__isSmallInteger(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1907 |
RETURN ( aNameOrNumber ); |
92 | 1908 |
} |
1909 |
||
604 | 1910 |
if (__isString(aProtocol)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1911 |
protocol = (char *)__stringVal(aProtocol); |
604 | 1912 |
} else { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1913 |
protocol = "tcp"; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1914 |
tryBoth = 1; |
91 | 1915 |
} |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1916 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1917 |
if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1918 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1919 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1920 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1921 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1922 |
if (tryBoth) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1923 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1924 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1925 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1926 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1927 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1928 |
RETURN ( nil ); |
91 | 1929 |
} |
418 | 1930 |
#endif |
91 | 1931 |
RETURN ( nil ); |
1932 |
%} |
|
1933 |
" |
|
1934 |
Socket portOfService:'echo' protocol:'udp' |
|
1935 |
Socket portOfService:'echo' protocol:'tcp' |
|
1936 |
" |
|
1937 |
! |
|
1938 |
||
0 | 1939 |
protocolOfService:aNameOrNumber |
819 | 1940 |
"returns the protocol (as string) for a given IP-service |
28 | 1941 |
or nil if no such service exists." |
0 | 1942 |
%{ |
418 | 1943 |
#ifndef NO_SOCKET |
0 | 1944 |
struct servent *servent = NULL; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1945 |
short portNo; |
0 | 1946 |
|
58 | 1947 |
if (__isSmallInteger(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1948 |
portNo = __intVal(aNameOrNumber); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1949 |
servent = getservbyport(htons(portNo), "tcp") ; |
42 | 1950 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1951 |
servent = getservbyport(htons(portNo), "udp") ; |
42 | 1952 |
if (servent == NULL) { |
1953 |
RETURN ( nil ); |
|
1954 |
} |
|
1955 |
} |
|
0 | 1956 |
} else { |
42 | 1957 |
if (__isString(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1958 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp"); |
42 | 1959 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1960 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
42 | 1961 |
if (servent == NULL) { |
1962 |
RETURN ( nil ); |
|
1963 |
} |
|
1964 |
} |
|
1965 |
} |
|
0 | 1966 |
} |
1967 |
if (servent) { |
|
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1968 |
RETURN ( __MKSTRING(servent->s_proto) ); |
0 | 1969 |
} |
418 | 1970 |
#endif |
0 | 1971 |
RETURN ( nil ); |
1972 |
%} |
|
28 | 1973 |
" |
74 | 1974 |
Socket protocolOfService:'finger' |
1975 |
Socket protocolOfService:'nntp' |
|
28 | 1976 |
Socket protocolOfService:'xxx' |
1977 |
Socket protocolOfService:79 |
|
74 | 1978 |
Socket protocolOfService:'snmp' |
28 | 1979 |
" |
1980 |
! |
|
1981 |
||
532 | 1982 |
supportedProtocolFamilies |
1983 |
"return a collection of supported protocol families. |
|
1984 |
This list specifies what the Socket class supports - |
|
1985 |
socket creation may still fail, if your system was built |
|
1986 |
without it." |
|
1987 |
||
1988 |
|list hasIt| |
|
1989 |
||
1990 |
list := OrderedCollection new. |
|
1991 |
||
1992 |
%{ |
|
1993 |
#ifdef AF_INET |
|
812 | 1994 |
%}. |
1995 |
list add:#inet. |
|
1996 |
%{ |
|
532 | 1997 |
#endif |
1998 |
%}. |
|
1999 |
||
2000 |
%{ |
|
2001 |
#ifdef AF_UNIX |
|
812 | 2002 |
%}. |
2003 |
list add:#unix. |
|
2004 |
%{ |
|
532 | 2005 |
#endif |
2006 |
%}. |
|
2007 |
||
2008 |
%{ |
|
2009 |
#ifdef AF_INET6 |
|
812 | 2010 |
%}. |
2011 |
list add:#inet6. "/ internet v6 |
|
2012 |
%{ |
|
532 | 2013 |
#endif |
2014 |
%}. |
|
2015 |
||
2016 |
%{ |
|
2017 |
#ifdef AF_APPLETALK |
|
812 | 2018 |
%}. |
2019 |
list add:#appletalk. "/ appletalk |
|
2020 |
%{ |
|
532 | 2021 |
#endif |
2022 |
%}. |
|
2023 |
||
2024 |
%{ |
|
2025 |
#ifdef AF_DECnet |
|
812 | 2026 |
%}. |
2027 |
list add:#decnet. "/ dec net |
|
2028 |
%{ |
|
532 | 2029 |
#endif |
2030 |
%}. |
|
2031 |
||
2032 |
%{ |
|
2033 |
#ifdef AF_NS |
|
812 | 2034 |
%}. |
2035 |
list add:#xns. "/ Xerox XNS |
|
2036 |
%{ |
|
532 | 2037 |
#endif |
2038 |
%}. |
|
2039 |
||
2040 |
%{ |
|
812 | 2041 |
#ifdef AF_X25 |
2042 |
%}. |
|
2043 |
list add:#x25. "/ X.25 |
|
2044 |
%{ |
|
532 | 2045 |
#endif |
2046 |
%}. |
|
2047 |
||
2048 |
%{ |
|
2049 |
#ifdef AF_SNA |
|
812 | 2050 |
%}. |
2051 |
list add:#sna. "/ IBM SNA |
|
2052 |
%{ |
|
532 | 2053 |
#endif |
2054 |
%}. |
|
2055 |
||
2056 |
%{ |
|
2057 |
#ifdef AF_RAW |
|
812 | 2058 |
%}. |
2059 |
list add:#raw. "/ ?? RAW packets |
|
2060 |
%{ |
|
532 | 2061 |
#endif |
2062 |
%}. |
|
2063 |
||
2064 |
%{ |
|
2065 |
#ifdef AF_ISO |
|
812 | 2066 |
%}. |
2067 |
list add:#iso. "/ ?? |
|
2068 |
%{ |
|
532 | 2069 |
#endif |
2070 |
%}. |
|
2071 |
||
2072 |
%{ |
|
2073 |
#ifdef AF_NETBIOS |
|
812 | 2074 |
%}. |
2075 |
list add:#netbios. "/ ?? |
|
2076 |
%{ |
|
532 | 2077 |
#endif |
2078 |
%}. |
|
2079 |
||
2080 |
%{ |
|
2081 |
#ifdef AF_IPX |
|
812 | 2082 |
%}. |
2083 |
list add:#ipx. "/ Novell IPX |
|
2084 |
%{ |
|
532 | 2085 |
#endif |
2086 |
%}. |
|
2087 |
||
2088 |
%{ |
|
2089 |
#ifdef AF_AX25 |
|
812 | 2090 |
%}. |
2091 |
list add:#ax25. "/ Amateur Radio AX.25 |
|
2092 |
%{ |
|
532 | 2093 |
#endif |
2094 |
%}. |
|
2095 |
||
2096 |
%{ |
|
2097 |
#ifdef AF_NETROM |
|
812 | 2098 |
%}. |
2099 |
list add:#netrom. "/ Amateur Radio NET/ROM |
|
2100 |
%{ |
|
532 | 2101 |
#endif |
2102 |
%}. |
|
2103 |
||
2104 |
%{ |
|
2105 |
#ifdef AF_BRIDGE |
|
812 | 2106 |
%}. |
2107 |
list add:#bridge. "/ multiprotocol bridge |
|
2108 |
%{ |
|
532 | 2109 |
#endif |
2110 |
%}. |
|
2111 |
||
571 | 2112 |
%{ |
2113 |
#ifdef AF_BSC |
|
812 | 2114 |
%}. |
2115 |
list add:#bsc. "/ BISYNC 2780/3780 |
|
2116 |
%{ |
|
571 | 2117 |
#endif |
2118 |
%}. |
|
812 | 2119 |
|
2120 |
%{ |
|
2121 |
#ifdef AF_ROSE |
|
2122 |
%}. |
|
2123 |
list add:#rose. "/ Amateur Radio X.25 PLP |
|
2124 |
%{ |
|
2125 |
#endif |
|
2126 |
%}. |
|
571 | 2127 |
|
869 | 2128 |
%{ |
2129 |
#ifdef AF_IRDA |
|
2130 |
%}. |
|
2131 |
list add:#irda. "/ infrared |
|
2132 |
%{ |
|
2133 |
#endif |
|
2134 |
%}. |
|
2135 |
||
571 | 2136 |
|
532 | 2137 |
^ list |
2138 |
||
2139 |
" |
|
2140 |
Socket supportedProtocolFamilies |
|
2141 |
" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2142 |
! |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2143 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2144 |
typeOfProtocol:aProtocol |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2145 |
"given a protocols name (i.e. tcp, udp etc) return the connection type. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2146 |
This method needs more ... - or is there a way to get this from the system ?" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2147 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2148 |
(aProtocol = 'tcp') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2149 |
(aProtocol = 'udp') ifTrue:[^ #datagram]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2150 |
(aProtocol = 'ip') ifTrue:[^ #raw]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2151 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2152 |
unix domain |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2153 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2154 |
(aProtocol = 'ud') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2155 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2156 |
add x25 stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2157 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2158 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2159 |
add appletalk stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2160 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2161 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2162 |
add other stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2163 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2164 |
^ nil |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2165 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2166 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2167 |
Socket typeOfProtocol:'tcp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2168 |
Socket typeOfProtocol:'ucp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2169 |
Socket typeOfProtocol:(Socket protocolOfService:'nntp') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2170 |
Socket typeOfProtocol:(Socket protocolOfService:'echo') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2171 |
" |
28 | 2172 |
! ! |
2173 |
||
867 | 2174 |
!Socket methodsFor:'Compatibility - ST80'! |
28 | 2175 |
|
887 | 2176 |
acceptNonBlock |
2177 |
^ self accept |
|
2178 |
! |
|
2179 |
||
870 | 2180 |
connectTo:aSocketAddress |
2181 |
^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port |
|
2182 |
! |
|
2183 |
||
126 | 2184 |
errorReporter |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2185 |
"ST-80 mimicry." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2186 |
|
126 | 2187 |
^ self |
28 | 2188 |
! |
2189 |
||
887 | 2190 |
ioConnection |
2191 |
^ self |
|
2192 |
! |
|
2193 |
||
126 | 2194 |
notReadySignal |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2195 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2196 |
for now - this is not yet raised" |
71 | 2197 |
|
126 | 2198 |
^ Signal new |
486 | 2199 |
! |
2200 |
||
576 | 2201 |
readAppendStream |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2202 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2203 |
In ST-80, socket is not a stream, but referes to one. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2204 |
ST-80 code therefore uses 'Socket readWriteStream' to access |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2205 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2206 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2207 |
this method returns the receiver, for transparency" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2208 |
|
576 | 2209 |
^ self |
2210 |
! |
|
2211 |
||
486 | 2212 |
readStream |
2213 |
"ST-80 mimicry. |
|
2214 |
In ST-80, socket is not a stream, but referes to one. |
|
2215 |
ST-80 code therefore uses 'Socket readStream' to access |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2216 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2217 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2218 |
this method returns the receiver, for transparency" |
486 | 2219 |
|
2220 |
^ self |
|
2221 |
||
2222 |
"Created: 24.1.1997 / 23:52:57 / cg" |
|
2223 |
! |
|
2224 |
||
576 | 2225 |
shutdown:how |
2226 |
"ST-80 compatibility" |
|
2227 |
||
2228 |
self shutDown |
|
2229 |
! |
|
2230 |
||
486 | 2231 |
writeStream |
2232 |
"ST-80 mimicry. |
|
2233 |
In ST-80, socket is not a stream, but referes to one. |
|
2234 |
ST-80 code therefore uses 'Socket writeStream' to access |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2235 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2236 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2237 |
this method returns the receiver, for transparency" |
486 | 2238 |
|
2239 |
^ self |
|
2240 |
||
2241 |
"Created: 24.1.1997 / 10:34:35 / cg" |
|
2242 |
"Modified: 24.1.1997 / 23:52:52 / cg" |
|
71 | 2243 |
! ! |
2244 |
||
827 | 2245 |
!Socket methodsFor:'Compatibility - Squeak'! |
771 | 2246 |
|
2247 |
peerName |
|
2248 |
"return my peer (i.e. ipAddr + port); |
|
2249 |
May return nil if not yet setup completely." |
|
2250 |
||
2251 |
^ self getPeer |
|
2252 |
! ! |
|
2253 |
||
126 | 2254 |
!Socket methodsFor:'datagram transmission'! |
28 | 2255 |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2256 |
receiveBuffer:aDataBuffer start:startIndex for:nBytes |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2257 |
"receive data |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2258 |
Return the number of bytes received, or a negative number on error. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2259 |
On error, the unix error code is left in the lastErrorNumber |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2260 |
instance variable. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2261 |
The thread blocks until data arrives - you may want to wait before |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2262 |
receiving, using #readWait or #readWaitWithTimeout:." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2263 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2264 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2265 |
|nReceived| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2266 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2267 |
%{ |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2268 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2269 |
OBJ oClass, myDomain; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2270 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2271 |
int nInstVars, nInstBytes, objSize; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2272 |
int sock; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2273 |
int n; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2274 |
char *cp; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2275 |
int flags = 0; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2276 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2277 |
if (fp != nil) { |
1009 | 2278 |
sock = fileno(__FILEVal(fp)); |
2279 |
||
2280 |
oClass = __Class(aDataBuffer); |
|
2281 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2282 |
case BYTEARRAY: |
|
2283 |
case WORDARRAY: |
|
2284 |
case SWORDARRAY: |
|
2285 |
case LONGARRAY: |
|
2286 |
case SLONGARRAY: |
|
2287 |
case FLOATARRAY: |
|
2288 |
case DOUBLEARRAY: |
|
2289 |
break; |
|
2290 |
default: |
|
2291 |
goto bad; |
|
2292 |
} |
|
2293 |
||
2294 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2295 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2296 |
objSize = _Size(aDataBuffer) - nInstBytes; |
|
2297 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
|
2298 |
if (__isSmallInteger(startIndex)) { |
|
2299 |
cp += __intVal(startIndex); |
|
2300 |
objSize -= __intVal(startIndex); |
|
2301 |
} |
|
2302 |
if (__isSmallInteger(nBytes)) { |
|
2303 |
if (__intVal(nBytes) < objSize) { |
|
2304 |
objSize = __intVal(nBytes); |
|
2305 |
} |
|
2306 |
} |
|
2307 |
||
2308 |
__BEGIN_INTERRUPTABLE__ |
|
2309 |
do { |
|
2310 |
n = recv(sock, cp, objSize, flags); |
|
2311 |
} while ((n < 0) && (errno == EINTR)); |
|
2312 |
__END_INTERRUPTABLE__ |
|
2313 |
||
2314 |
if (n < 0) { |
|
2315 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2316 |
} |
|
2317 |
nReceived = __MKSMALLINT(n); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2318 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2319 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2320 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2321 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2322 |
nReceived notNil ifTrue:[ |
1009 | 2323 |
nReceived < 0 ifTrue:[ |
2324 |
'Socket [warning]: ' infoPrint. |
|
2325 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
|
2326 |
]. |
|
2327 |
^ nReceived |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2328 |
]. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2329 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2330 |
arrive here if you try to receive into an invalid buffer |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2331 |
(i.e. not ByteArray-like), |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2332 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2333 |
or if the addressBuffer is nonNil AND too small. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2334 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2335 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2336 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2337 |
|
126 | 2338 |
receiveFrom:anAddressBuffer buffer:aDataBuffer |
2339 |
"receive datagramm data - put address of originating host into |
|
2340 |
anAddressBuffer, data into aBuffer. |
|
2341 |
Both must be ByteArray-like. The addressBuffer must |
|
2342 |
provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2343 |
Return the number of bytes received, or a negative number on error. |
|
2344 |
On error, the unix error code is left in the lastErrorNumber |
|
2345 |
instance variable." |
|
28 | 2346 |
|
126 | 2347 |
^ self receiveFrom:anAddressBuffer buffer:aDataBuffer start:1 for:(aDataBuffer size) |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2348 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2349 |
|
126 | 2350 |
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes |
2351 |
"receive datagramm data - put address of originating host into |
|
2352 |
anAddressBuffer, data into aBuffer. For ST-80 compatibility, |
|
2353 |
the addressBuffer may be a non-ByteArray; then, it must understand |
|
2354 |
the addressBytes-message (i.e. be a SocketAddress instance). |
|
2355 |
Return the number of bytes received, or a negative number on error. |
|
2356 |
On error, the unix error code is left in the lastErrorNumber |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2357 |
instance variable. |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2358 |
The thread blocks until data arrives - you may want to wait before |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2359 |
receiving, using #readWait or #readWaitWithTimeout:." |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2360 |
|
1009 | 2361 |
|addrBytes addrLen nReceived addrPort| |
28 | 2362 |
|
126 | 2363 |
addrBytes := ByteArray new:100. |
2364 |
%{ |
|
418 | 2365 |
#ifndef NO_SOCKET |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2366 |
OBJ oClass, myDomain; |
217 | 2367 |
OBJ fp = __INST(filePointer); |
126 | 2368 |
int nInstVars, nInstBytes, objSize; |
2369 |
int sock; |
|
819 | 2370 |
union sockaddr_u sa; |
1009 | 2371 |
int alen = 0; |
2372 |
int n, offs, sIdx; |
|
126 | 2373 |
char *cp; |
2374 |
int flags = 0; |
|
2375 |
||
2376 |
if (fp != nil) { |
|
1009 | 2377 |
sock = fileno(__FILEVal(fp)); |
2378 |
||
2379 |
oClass = __Class(aDataBuffer); |
|
2380 |
offs = 0; |
|
1010 | 2381 |
sIdx = 0; |
2382 |
if (__isSmallInteger(startIndex)) { |
|
2383 |
sIdx = __intVal(startIndex) - 1; |
|
2384 |
} |
|
1009 | 2385 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
2386 |
case BYTEARRAY: |
|
2387 |
offs = sIdx; |
|
2388 |
break; |
|
2389 |
case WORDARRAY: |
|
2390 |
case SWORDARRAY: |
|
2391 |
offs = sIdx * 2; |
|
2392 |
break; |
|
2393 |
case LONGARRAY: |
|
2394 |
case SLONGARRAY: |
|
2395 |
offs = sIdx * 4; |
|
2396 |
break; |
|
2397 |
case LONGLONGARRAY: |
|
2398 |
case SLONGLONGARRAY: |
|
2399 |
offs = sIdx * 8; |
|
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2400 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2401 |
offs += 4; |
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2402 |
# endif |
1010 | 2403 |
break; |
1009 | 2404 |
case FLOATARRAY: |
2405 |
offs = sIdx * sizeof(float); |
|
2406 |
break; |
|
2407 |
case DOUBLEARRAY: |
|
2408 |
offs = sIdx * sizeof(double); |
|
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2409 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2410 |
offs += 4; |
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2411 |
# endif |
1009 | 2412 |
break; |
2413 |
default: |
|
2414 |
goto bad; |
|
2415 |
} |
|
2416 |
||
2417 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2418 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2419 |
objSize = _Size(aDataBuffer) - nInstBytes; |
|
2420 |
objSize -= offs; |
|
2421 |
if (__isSmallInteger(nBytes)) { |
|
2422 |
if (__intVal(nBytes) < objSize) { |
|
2423 |
objSize = __intVal(nBytes); |
|
2424 |
} |
|
2425 |
} |
|
2426 |
||
2427 |
__BEGIN_INTERRUPTABLE__ |
|
2428 |
do { |
|
2429 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs; |
|
2430 |
alen = sizeof(sa); |
|
2431 |
n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen); |
|
2432 |
} while ((n < 0) && (errno == EINTR)); |
|
2433 |
__END_INTERRUPTABLE__ |
|
2434 |
||
2435 |
if (n >= 0) { |
|
2436 |
if (__isNonNilObject(addrBytes)) { |
|
2437 |
oClass = __qClass(addrBytes); |
|
2438 |
if ((__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) |
|
2439 |
goto bad; |
|
2440 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2441 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
|
2442 |
objSize = __qSize(addrBytes) - nInstBytes; |
|
2443 |
cp = (char *)__InstPtr(addrBytes) + nInstBytes; |
|
2444 |
if (objSize < alen) |
|
2445 |
goto bad; |
|
2446 |
||
2447 |
myDomain = __INST(domain); |
|
2448 |
||
2449 |
/* |
|
2450 |
* extract the datagrams address |
|
2451 |
*/ |
|
2452 |
if (0) { |
|
2453 |
/* for else below */ |
|
2454 |
} |
|
653 | 2455 |
# ifdef AF_INET |
1009 | 2456 |
else if (myDomain == @symbol(inet)) { |
2457 |
if (objSize < 4) |
|
2458 |
goto bad; |
|
2459 |
# ifdef DGRAM_DEBUG |
|
2460 |
printf("alen: %d s_addr:%x\n", alen, sa.in.sin_addr.s_addr); |
|
2461 |
# endif /* DGRAM_DEBUG */ |
|
2462 |
addrPort = __MKSMALLINT( ntohs(sa.in.sin_port) ); |
|
2463 |
sa.in.sin_addr.s_addr = ntohl(sa.in.sin_addr.s_addr); |
|
2464 |
cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF; |
|
2465 |
cp[1] = (sa.in.sin_addr.s_addr >> 16) & 0xFF; |
|
2466 |
cp[2] = (sa.in.sin_addr.s_addr >> 8) & 0xFF; |
|
2467 |
cp[3] = (sa.in.sin_addr.s_addr >> 0) & 0xFF; |
|
1010 | 2468 |
alen = 4; |
1009 | 2469 |
# ifdef DGRAM_DEBUG |
2470 |
printf("addr:%d.%d.%d.%d\n", cp[0], cp[1], cp[2], cp[3]); |
|
2471 |
# endif /* DGRAM_DEBUG */ |
|
2472 |
} |
|
653 | 2473 |
# endif /* AF_INET */ |
2474 |
||
812 | 2475 |
# ifdef AF_INET6 |
1009 | 2476 |
else if (myDomain == @symbol(inet6)) { |
2477 |
if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) |
|
2478 |
goto bad; |
|
2479 |
bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr)); |
|
2480 |
alen = sizeof(sa.in6.sin6_addr.s6_addr); |
|
2481 |
} |
|
812 | 2482 |
# endif /* AF_INET6 */ |
2483 |
||
2484 |
# ifdef AF_APPLETALK |
|
1009 | 2485 |
else if (myDomain == @symbol(appletalk)) { |
2486 |
if (objSize < 3) |
|
2487 |
goto bad; |
|
2488 |
cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF; |
|
2489 |
cp[1] = (sa.at.sat_addr.s_net) & 0xFF; |
|
2490 |
cp[2] = (sa.at.sat_addr.s_node) & 0xFF; |
|
2491 |
alen = 3; |
|
2492 |
} |
|
812 | 2493 |
# endif /* AF_APPLETALK */ |
2494 |
||
1009 | 2495 |
/* |
2496 |
* XXXX add addressing stuff for other domains here ... |
|
2497 |
*/ |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2498 |
# ifdef AF_X25 |
1009 | 2499 |
else if (myDomain == @symbol(x25)) { |
2500 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2501 |
# endif |
812 | 2502 |
|
2503 |
# ifdef AF_AX25 |
|
1009 | 2504 |
else if (myDomain == @symbol(ax25)) { |
2505 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2506 |
# endif |
812 | 2507 |
|
2508 |
# ifdef AF_NS |
|
1009 | 2509 |
else if ((myDomain == @symbol(ns)) |
2510 |
|| (myDomain == @symbol(xns))) { |
|
2511 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2512 |
# endif |
812 | 2513 |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2514 |
# ifdef AF_SNA |
1009 | 2515 |
else if (myDomain == @symbol(sna)) { |
2516 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2517 |
# endif |
812 | 2518 |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2519 |
# ifdef AF_RAW |
1009 | 2520 |
else if (myDomain == @symbol(raw)) { |
2521 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2522 |
# endif |
812 | 2523 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2524 |
# ifdef AF_ISO |
1009 | 2525 |
else if (myDomain == @symbol(iso)) { |
2526 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2527 |
# endif |
812 | 2528 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2529 |
# ifdef AF_DECnet |
1009 | 2530 |
else if (myDomain == @symbol(decnet)) { |
2531 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2532 |
# endif |
812 | 2533 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2534 |
# ifdef AF_NETBIOS |
1009 | 2535 |
else if (myDomain == @symbol(netbios)) { |
2536 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2537 |
# endif |
812 | 2538 |
|
653 | 2539 |
# ifdef AF_IPX |
1009 | 2540 |
else if (myDomain == @symbol(ipx)) { |
2541 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2542 |
# endif |
812 | 2543 |
|
653 | 2544 |
# ifdef AF_BRIDGE |
1009 | 2545 |
else if (myDomain == @symbol(bridge)) { |
2546 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2547 |
# endif |
812 | 2548 |
|
653 | 2549 |
# ifdef AF_BSC |
1009 | 2550 |
else if (myDomain == @symbol(bsc)) { |
2551 |
} |
|
571 | 2552 |
# endif |
812 | 2553 |
|
2554 |
# ifdef AF_ROSE |
|
1009 | 2555 |
else if (myDomain == @symbol(rose)) { |
2556 |
} |
|
812 | 2557 |
# endif |
2558 |
||
869 | 2559 |
# ifdef AF_IRDA |
1009 | 2560 |
else if (myDomain == @symbol(irda)) { |
2561 |
} |
|
869 | 2562 |
# endif |
2563 |
||
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2564 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 2565 |
else if (myDomain == @symbol(ccitt)) { |
2566 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2567 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2568 |
|
1009 | 2569 |
addrLen = __MKSMALLINT(alen); |
2570 |
} |
|
2571 |
} |
|
2572 |
if (n < 0) { |
|
2573 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2574 |
} |
|
2575 |
nReceived = __MKSMALLINT(n); |
|
126 | 2576 |
} |
418 | 2577 |
#endif |
126 | 2578 |
bad: ; |
2579 |
%}. |
|
2580 |
nReceived notNil ifTrue:[ |
|
1009 | 2581 |
nReceived < 0 ifTrue:[ |
2582 |
'Socket [warning]: ' infoPrint. |
|
2583 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
|
2584 |
]. |
|
2585 |
addrLen notNil ifTrue:[ |
|
2586 |
(anAddressBuffer isKindOf:SocketAddress) ifFalse:[ |
|
2587 |
"/ can be a ByteArray for ST/X compatibility |
|
2588 |
anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes |
|
2589 |
domain == #inet ifTrue:[ |
|
2590 |
addrBytes := anAddressBuffer copyFrom:1 to:4. |
|
2591 |
anAddressBuffer at:5 put:(addrPort digitByteAt:2). |
|
2592 |
anAddressBuffer at:6 put:(addrPort digitByteAt:1). |
|
2593 |
] ifFalse:[ |
|
2594 |
domain == #appletalk ifTrue:[ |
|
2595 |
addrBytes := anAddressBuffer copyFrom:1 to:3. |
|
2596 |
anAddressBuffer at:4 put:(addrPort digitByteAt:2). |
|
2597 |
anAddressBuffer at:5 put:(addrPort digitByteAt:1). |
|
2598 |
] ifFalse:[ |
|
2599 |
self error:'please use a SocketAddress' |
|
2600 |
] |
|
2601 |
] |
|
2602 |
] ifTrue:[ |
|
2603 |
"/ can be a SocketAddress for ST-80 compatibility |
|
2604 |
anAddressBuffer hostAddress:(addrBytes copyTo:addrLen) port:addrPort. |
|
2605 |
]. |
|
2606 |
]. |
|
2607 |
^ nReceived |
|
28 | 2608 |
]. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2609 |
" |
126 | 2610 |
arrive here if you try to receive into an invalid buffer |
2611 |
(i.e. not ByteArray-like), |
|
2612 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2613 |
or if the addressBuffer is nonNil AND too small. |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2614 |
" |
126 | 2615 |
self primitiveFailed |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2616 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2617 |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2618 |
sendBuffer:aDataBuffer start:startIndex for:count flags:flags |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2619 |
"send data. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2620 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2621 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2622 |
Return the number of bytes transmitted, or a negative number on error. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2623 |
On error, the unix error code is left in the lastErrorNumber |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2624 |
instance variable." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2625 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2626 |
|nReceived portNo| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2627 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2628 |
%{ |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2629 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2630 |
OBJ oClass; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2631 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2632 |
int nInstVars, nInstBytes, objSize; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2633 |
int sock; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2634 |
int n; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2635 |
char *cp; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2636 |
int _flags = 0; |
1009 | 2637 |
int offs, nBytes, sIdx; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2638 |
unsigned long norder; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2639 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2640 |
_flags = __longIntVal(flags); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2641 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2642 |
if ((fp != nil) |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2643 |
&& __isSmallInteger(startIndex) |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2644 |
&& __isSmallInteger(count)) { |
1009 | 2645 |
sock = fileno(__FILEVal(fp)); |
2646 |
||
2647 |
oClass = __Class(aDataBuffer); |
|
2648 |
sIdx = __intVal(startIndex) - 1; |
|
2649 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2650 |
case BYTEARRAY: |
|
2651 |
offs = sIdx; |
|
2652 |
break; |
|
2653 |
case WORDARRAY: |
|
2654 |
case SWORDARRAY: |
|
2655 |
offs = sIdx * 2; |
|
2656 |
break; |
|
2657 |
case LONGARRAY: |
|
2658 |
case SLONGARRAY: |
|
2659 |
offs = sIdx * 4; |
|
2660 |
break; |
|
2661 |
case LONGLONGARRAY: |
|
2662 |
case SLONGLONGARRAY: |
|
2663 |
offs = sIdx * 8; |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2664 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2665 |
offs += 4; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2666 |
# endif |
1010 | 2667 |
break; |
1009 | 2668 |
case FLOATARRAY: |
2669 |
offs = sIdx * sizeof(float); |
|
2670 |
break; |
|
2671 |
case DOUBLEARRAY: |
|
2672 |
offs = sIdx * sizeof(double); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2673 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2674 |
offs += 4; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2675 |
# endif |
1009 | 2676 |
break; |
2677 |
default: |
|
2678 |
goto bad; |
|
2679 |
} |
|
2680 |
nBytes = __intVal(count); |
|
2681 |
||
2682 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2683 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2684 |
objSize = __qSize(aDataBuffer) - nInstBytes; |
|
2685 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
|
2686 |
cp += offs; |
|
2687 |
if ((offs + nBytes) > objSize) { |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2688 |
# ifdef DGRAM_DEBUG |
1009 | 2689 |
printf("cut off ...\n"); |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2690 |
# endif |
1009 | 2691 |
nBytes = objSize - offs; |
2692 |
} |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2693 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2694 |
# ifdef DGRAM_DEBUG |
1009 | 2695 |
printf("sending %d bytes ...\n", nBytes); |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2696 |
# endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2697 |
|
1009 | 2698 |
__BEGIN_INTERRUPTABLE__ |
2699 |
do { |
|
2700 |
n = send(sock, cp, nBytes, _flags); |
|
2701 |
} while ((n < 0) && (errno == EINTR)); |
|
2702 |
__END_INTERRUPTABLE__ |
|
2703 |
||
2704 |
if (n < 0) { |
|
2705 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2706 |
} |
|
2707 |
RETURN (__MKSMALLINT(n)); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2708 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2709 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2710 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2711 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2712 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2713 |
arrive here if you try to send from an invalid buffer |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2714 |
(i.e. not ByteArray-like), |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2715 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2716 |
or if the addressBuffer is nonNil AND too small. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2717 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2718 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2719 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2720 |
|
126 | 2721 |
sendTo:anAddressBuffer buffer:buffer |
2722 |
"send datagramm data - fetch address of destination host from |
|
2723 |
anAddressBuffer, data from aDataBuffer. |
|
2724 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2725 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2726 |
Return the number of bytes transmitted, or a negative number on error. |
|
2727 |
On error, the unix error code is left in the lastErrorNumber |
|
2728 |
instance variable. |
|
2729 |
Flags is currently ignored; it is there for ST-80 compatibility." |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2730 |
|
126 | 2731 |
^ self sendTo:anAddressBuffer buffer:buffer start:1 for:buffer size flags:0 |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2732 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2733 |
|
817 | 2734 |
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count |
2735 |
"send datagramm data - fetch address of destination host from |
|
2736 |
anAddressBuffer, data from aDataBuffer. |
|
2737 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2738 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2739 |
Return the number of bytes transmitted, or a negative number on error. |
|
2740 |
On error, the unix error code is left in the lastErrorNumber |
|
2741 |
instance variable. |
|
2742 |
Flags is currently ignored; it is there for ST-80 compatibility." |
|
2743 |
||
2744 |
^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 |
|
2745 |
! |
|
2746 |
||
126 | 2747 |
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags |
2748 |
"send datagramm data - fetch address of destination host from |
|
2749 |
anAddressBuffer, data from aDataBuffer starting at startIndex, |
|
2750 |
sending count bytes. |
|
2751 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2752 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2753 |
Return the number of bytes transmitted, or a negative number on error. |
|
2754 |
On error, the unix error code is left in the lastErrorNumber |
|
2755 |
instance variable." |
|
0 | 2756 |
|
126 | 2757 |
|addrBytes addrLen nReceived portNo| |
93 | 2758 |
|
819 | 2759 |
"/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first) |
2760 |
"/ or (better) an instance of SocketAddress |
|
126 | 2761 |
"/ |
888 | 2762 |
(anAddressBuffer isKindOf:SocketAddress) ifFalse:[ |
1009 | 2763 |
domain == #inet ifTrue:[ |
2764 |
addrBytes := anAddressBuffer copyFrom:1 to:4. |
|
2765 |
portNo := ((anAddressBuffer at:5) bitShift:8) |
|
2766 |
+ (anAddressBuffer at:6). |
|
2767 |
] ifFalse:[ |
|
2768 |
domain == #appletalk ifTrue:[ |
|
2769 |
addrBytes := anAddressBuffer copyFrom:1 to:3. |
|
2770 |
portNo := ((anAddressBuffer at:5) bitShift:8) |
|
2771 |
+ (anAddressBuffer at:6). |
|
2772 |
] ifFalse:[ |
|
2773 |
self error:'please use a SocketAddress' |
|
2774 |
] |
|
2775 |
]. |
|
888 | 2776 |
] ifTrue:[ |
1009 | 2777 |
addrBytes := anAddressBuffer hostAddress. |
2778 |
portNo := anAddressBuffer port. |
|
28 | 2779 |
]. |
0 | 2780 |
%{ |
418 | 2781 |
#ifndef NO_SOCKET |
126 | 2782 |
OBJ oClass; |
217 | 2783 |
OBJ fp = __INST(filePointer); |
126 | 2784 |
int nInstVars, nInstBytes, objSize; |
2785 |
int sock; |
|
819 | 2786 |
union sockaddr_u sa; |
126 | 2787 |
struct sockaddr *saPtr = (struct sockaddr *)&sa; |
2788 |
int alen = sizeof(sa); |
|
2789 |
int n; |
|
2790 |
char *cp; |
|
2791 |
int _flags = 0; |
|
2792 |
int offs, nBytes; |
|
2793 |
unsigned long norder; |
|
21 | 2794 |
|
126 | 2795 |
_flags = __longIntVal(flags); |
2796 |
||
2797 |
if ((fp != nil) |
|
2798 |
&& __isSmallInteger(startIndex) |
|
2799 |
&& __isSmallInteger(count)) { |
|
1009 | 2800 |
sock = fileno(__FILEVal(fp)); |
2801 |
||
2802 |
if (addrBytes == nil) { |
|
2803 |
alen = 0; |
|
2804 |
saPtr = (struct sockaddr *)0; |
|
2805 |
} else { |
|
2806 |
if (! __isByteArray(addrBytes)) goto bad; |
|
2807 |
||
2808 |
cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element; |
|
2809 |
n = __byteArraySize(addrBytes); |
|
2810 |
if (alen < n) n = alen; |
|
790 | 2811 |
# ifdef DGRAM_DEBUG |
1009 | 2812 |
printf("address is %d bytes ... %d.%d.%d.%d\n", n, cp[0], cp[1], cp[2], cp[3]); |
790 | 2813 |
# endif |
1009 | 2814 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
2815 |
||
2816 |
if (0) { |
|
2817 |
/* for else below */ |
|
2818 |
} |
|
790 | 2819 |
# ifdef AF_INET |
1009 | 2820 |
else if (__INST(domain) == @symbol(inet)) { |
2821 |
sa.in.sin_family = AF_INET; |
|
2822 |
sa.in.sin_port = htons((u_short) __intVal(portNo)); |
|
2823 |
} |
|
790 | 2824 |
# endif |
2825 |
# ifdef AF_INET6 |
|
1009 | 2826 |
else if (__INST(domain) == @symbol(inet6)) { |
2827 |
sa.in6.sin6_family = AF_INET6; |
|
2828 |
sa.in6.sin6_port = htons((u_short) __intVal(portNo)); |
|
2829 |
} |
|
790 | 2830 |
# endif |
2831 |
# ifdef AF_APPLETALK |
|
1009 | 2832 |
else if (__INST(domain) == @symbol(appletalk)) { |
2833 |
sa.at.sat_family = AF_APPLETALK; |
|
2834 |
sa.at.sat_port = __intVal(portNo); |
|
2835 |
} |
|
790 | 2836 |
# endif |
869 | 2837 |
# ifdef AF_IRDA |
1009 | 2838 |
else if (__INST(domain) == @symbol(irda)) { |
2839 |
} |
|
869 | 2840 |
# endif |
1009 | 2841 |
} |
2842 |
||
2843 |
oClass = __Class(aDataBuffer); |
|
2844 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2845 |
case BYTEARRAY: |
|
2846 |
offs = __intVal(startIndex) - 1; |
|
2847 |
break; |
|
2848 |
case WORDARRAY: |
|
2849 |
case SWORDARRAY: |
|
2850 |
offs = (__intVal(startIndex) - 1) * 2; |
|
2851 |
break; |
|
2852 |
case LONGARRAY: |
|
2853 |
case SLONGARRAY: |
|
2854 |
offs = (__intVal(startIndex) - 1) * 4; |
|
2855 |
break; |
|
2856 |
case LONGLONGARRAY: |
|
2857 |
case SLONGLONGARRAY: |
|
2858 |
offs = (__intVal(startIndex) - 1) * 8; |
|
790 | 2859 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2860 |
offs += 4; |
790 | 2861 |
# endif |
1010 | 2862 |
break; |
1009 | 2863 |
case FLOATARRAY: |
2864 |
offs = (__intVal(startIndex) - 1) * sizeof(float); |
|
2865 |
break; |
|
2866 |
case DOUBLEARRAY: |
|
2867 |
offs = (__intVal(startIndex) - 1) * sizeof(double); |
|
790 | 2868 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2869 |
offs += 4; |
790 | 2870 |
# endif |
1009 | 2871 |
break; |
2872 |
default: |
|
2873 |
goto bad; |
|
2874 |
} |
|
2875 |
nBytes = __intVal(count); |
|
2876 |
||
2877 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2878 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2879 |
objSize = __qSize(aDataBuffer) - nInstBytes; |
|
2880 |
if ((offs + nBytes) > objSize) { |
|
790 | 2881 |
# ifdef DGRAM_DEBUG |
1009 | 2882 |
printf("cut off ...\n"); |
790 | 2883 |
# endif |
1009 | 2884 |
nBytes = objSize - offs; |
2885 |
} |
|
2886 |
||
2887 |
norder = htonl(sa.in.sin_addr.s_addr); |
|
790 | 2888 |
# ifdef DGRAM_DEBUG |
1009 | 2889 |
printf("sending %d bytes ... to ", nBytes); |
2890 |
printf("%d.%d.%d.%d\n", |
|
2891 |
(norder >> 24) & 0xFF, |
|
2892 |
(norder >> 16) & 0xFF, |
|
2893 |
(norder >> 8) & 0xFF, |
|
2894 |
norder & 0xFF); |
|
790 | 2895 |
# endif |
0 | 2896 |
|
1009 | 2897 |
__BEGIN_INTERRUPTABLE__ |
2898 |
do { |
|
2899 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs; |
|
2900 |
n = sendto(sock, cp, nBytes, _flags, saPtr, alen); |
|
2901 |
} while ((n < 0) && (errno == EINTR)); |
|
2902 |
__END_INTERRUPTABLE__ |
|
2903 |
||
2904 |
if (n < 0) { |
|
2905 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2906 |
} |
|
2907 |
RETURN (__MKSMALLINT(n)); |
|
0 | 2908 |
} |
418 | 2909 |
#endif |
126 | 2910 |
bad: ; |
42 | 2911 |
%}. |
2912 |
" |
|
126 | 2913 |
arrive here if you try to send from an invalid buffer |
2914 |
(i.e. not ByteArray-like), |
|
2915 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2916 |
or if the addressBuffer is nonNil AND too small. |
|
42 | 2917 |
" |
126 | 2918 |
self primitiveFailed |
0 | 2919 |
! ! |
2920 |
||
2921 |
!Socket methodsFor:'low level'! |
|
2922 |
||
507 | 2923 |
bindAnonymously |
2924 |
^ self |
|
2925 |
bindTo:0 |
|
2926 |
address:nil |
|
509 | 2927 |
reuseAddress:false |
2928 |
! |
|
2929 |
||
2930 |
bindAnonymouslyToAddress:addressString |
|
2931 |
^ self |
|
2932 |
bindTo:0 |
|
2933 |
address:addressString |
|
2934 |
reuseAddress:false |
|
507 | 2935 |
! |
2936 |
||
71 | 2937 |
bindTo:aSocketAddress |
425 | 2938 |
"ST80 compatible bind, expecting a socketAddress argument. |
2939 |
The socketAddress object (an instance of SocketAddress) |
|
2940 |
is supposed to respond to #portOrName and #address requests." |
|
71 | 2941 |
|
2942 |
^ self bindTo:(aSocketAddress portOrName) |
|
2943 |
address:(aSocketAddress address) |
|
425 | 2944 |
reuseAddress:true |
71 | 2945 |
! |
2946 |
||
425 | 2947 |
bindTo:portNrOrNameString address:addressString |
28 | 2948 |
"low level bind - returns true if ok, false otherwise. |
71 | 2949 |
Currently only non-address binding is supported; |
425 | 2950 |
i.e. the address must always be nil. |
71 | 2951 |
|
2952 |
The interpretation of portNrOrName depends on the domain: |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2953 |
inet domain uses (4byte) byteArray like internet numbers, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2954 |
unix domain uses pathname strings, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2955 |
others use whatever will come up in the future |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2956 |
" |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2957 |
|
425 | 2958 |
^ self |
2959 |
bindTo:portNrOrNameString |
|
2960 |
address:addressString |
|
2961 |
reuseAddress:true |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2962 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2963 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2964 |
bindTo:portNrOrName address:address reuseAddress:reuse |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2965 |
"low level bind - returns true if ok, false otherwise. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2966 |
Currently only non-address binding is supported; |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2967 |
i.e. address must always be nil. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2968 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2969 |
The interpretation of portNrOrName depends on the domain: |
789 | 2970 |
inet domain uses (4byte) byteArray like internet numbers, |
2971 |
unix domain uses pathname strings, |
|
2972 |
others use whatever will come up in the future |
|
425 | 2973 |
|
2974 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
2975 |
is to be set (to avoid the 'bind: address in use' error). |
|
2976 |
" |
|
28 | 2977 |
|
2978 |
filePointer isNil ifTrue:[ |
|
789 | 2979 |
^ self errorNotOpen |
28 | 2980 |
]. |
0 | 2981 |
%{ |
418 | 2982 |
#ifndef NO_SOCKET |
217 | 2983 |
OBJ t = __INST(filePointer); |
71 | 2984 |
OBJ myDomain; |
28 | 2985 |
int sock; |
819 | 2986 |
union sockaddr_u sa; |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2987 |
int sockaddr_size; |
6 | 2988 |
int ret; |
25 | 2989 |
int on = 1; |
28 | 2990 |
int ok; |
0 | 2991 |
|
217 | 2992 |
if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) { |
789 | 2993 |
DBGPRINTF(("SOCKET: invalid domain arg\n")); |
2994 |
RETURN (false); |
|
28 | 2995 |
} |
2996 |
||
2997 |
ok = 0; |
|
217 | 2998 |
myDomain = __INST(domain); |
525 | 2999 |
|
1009 | 3000 |
if (0) { |
3001 |
/* for else below */ |
|
3002 |
} |
|
3003 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3004 |
# ifdef AF_INET |
1009 | 3005 |
else if (myDomain == @symbol(inet)) { |
789 | 3006 |
/* |
3007 |
* INET addresses - port must be a smallinteger or nil |
|
3008 |
*/ |
|
3009 |
sa.in.sin_family = AF_INET; |
|
3010 |
||
3011 |
if (portNrOrName == nil) { |
|
3012 |
sa.in.sin_port = 0; |
|
3013 |
} else { |
|
3014 |
if (! __isSmallInteger(portNrOrName)) { |
|
3015 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3016 |
RETURN (false); |
|
3017 |
} |
|
1009 | 3018 |
sa.in.sin_port = htons((u_short) __intVal(portNrOrName)); |
789 | 3019 |
} |
3020 |
||
3021 |
/* |
|
3022 |
* INET addresses - addr must be nil, integer or byteArray |
|
3023 |
*/ |
|
3024 |
if (address == nil) { |
|
3025 |
sa.in.sin_addr.s_addr = htonl(INADDR_ANY); |
|
3026 |
} else { |
|
3027 |
if (__isInteger(address)) { |
|
3028 |
sa.in.sin_addr.s_addr = htonl(__longIntVal(address)); |
|
3029 |
} else { |
|
3030 |
if (__isByteArray(address)) { |
|
3031 |
unsigned char *cp; |
|
3032 |
int n; |
|
3033 |
||
3034 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
3035 |
n = __byteArraySize(address); |
|
3036 |
if (n > 4) n = 4; |
|
3037 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
|
3038 |
} else { |
|
3039 |
unsigned addr; |
|
3040 |
struct hostent *hp ; |
|
3041 |
||
3042 |
if (! __isString(address)) { |
|
3043 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
3044 |
RETURN (false); |
|
3045 |
} |
|
3046 |
||
3047 |
if ((addr = inet_addr(__stringVal(address))) != -1) { |
|
3048 |
/* |
|
3049 |
* is Internet addr in octet notation |
|
3050 |
*/ |
|
3051 |
bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */ |
|
3052 |
} else { |
|
3053 |
/* |
|
3054 |
* do we know the host's address? |
|
3055 |
*/ |
|
3056 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
3057 |
if (hp == NULL) { |
|
3058 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
|
3059 |
RETURN (false); |
|
3060 |
} |
|
812 | 3061 |
if (hp->h_addrtype != AF_INET) { |
3062 |
DBGPRINTF(("SOCKET: host:%s is not an inet host\n", __stringVal(address))); |
|
3063 |
RETURN (false); |
|
3064 |
} |
|
789 | 3065 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
3066 |
sa.in.sin_family = hp->h_addrtype; |
|
3067 |
} |
|
3068 |
} |
|
3069 |
} |
|
3070 |
} |
|
3071 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
|
3072 |
sockaddr_size = sizeof(struct sockaddr_in); |
|
3073 |
ok = 1; |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3074 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3075 |
# endif /* AF_INET */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3076 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3077 |
# ifdef AF_INET6 |
1009 | 3078 |
else if (myDomain == @symbol(inet6)) { |
789 | 3079 |
/* |
3080 |
* INET6 addresses - port must be a smallinteger or nil |
|
3081 |
*/ |
|
3082 |
sa.in6.sin6_family = AF_INET6; |
|
3083 |
||
3084 |
if (portNrOrName == nil) { |
|
3085 |
sa.in6.sin6_port = 0; |
|
3086 |
} else { |
|
3087 |
if (! __isSmallInteger(portNrOrName)) { |
|
3088 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3089 |
RETURN (false); |
|
3090 |
} |
|
1009 | 3091 |
sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName)); |
789 | 3092 |
} |
3093 |
||
3094 |
/* |
|
3095 |
* INET6 addresses - addr must be nil or byteArray or string |
|
3096 |
*/ |
|
3097 |
if (address == nil) { |
|
812 | 3098 |
bzero(sa.in6.sin6_addr.s6_addr, sizeof(sa.in6.sin6_addr.s6_addr)); |
789 | 3099 |
} else { |
3100 |
if (__isByteArray(address)) { |
|
3101 |
unsigned char *cp; |
|
3102 |
int n; |
|
3103 |
||
3104 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
3105 |
n = __byteArraySize(address); |
|
812 | 3106 |
if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr); |
3107 |
bcopy(cp, sa.in6.sin6_addr.s6_addr, n); |
|
789 | 3108 |
} else { |
3109 |
unsigned addr; |
|
3110 |
struct hostent *hp ; |
|
3111 |
||
3112 |
if (! __isString(address)) { |
|
3113 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
3114 |
RETURN (false); |
|
3115 |
} |
|
3116 |
||
3117 |
/* |
|
3118 |
* do we know the host's address? |
|
3119 |
*/ |
|
3120 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
3121 |
if (hp == NULL) { |
|
3122 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
|
3123 |
RETURN (false); |
|
3124 |
} |
|
812 | 3125 |
if (hp->h_addrtype != AF_INET6) { |
3126 |
DBGPRINTF(("SOCKET: host:%s is not an ipv6 host\n", __stringVal(address))); |
|
3127 |
RETURN (false); |
|
3128 |
} |
|
789 | 3129 |
bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ; |
3130 |
sa.in.sin_family = hp->h_addrtype; |
|
3131 |
} |
|
3132 |
} |
|
3133 |
||
812 | 3134 |
DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x... port: %x\n", |
789 | 3135 |
sa.in6.sin6_addr.s6_addr[0], |
3136 |
sa.in6.sin6_addr.s6_addr[1], |
|
3137 |
sa.in6.sin6_addr.s6_addr[2], |
|
3138 |
sa.in6.sin6_addr.s6_addr[3], |
|
3139 |
sa.in6.sin6_addr.s6_addr[4], |
|
3140 |
sa.in6.sin6_addr.s6_addr[5], |
|
3141 |
sa.in6.sin6_port)); |
|
3142 |
sockaddr_size = sizeof(struct sockaddr_in6); |
|
3143 |
ok = 1; |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3144 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3145 |
# endif /* AF_INET6 */ |
525 | 3146 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3147 |
# ifdef AF_UNIX |
525 | 3148 |
/* |
3149 |
* UNIX domain - port is ignored; address must be a string (path) |
|
3150 |
*/ |
|
1009 | 3151 |
else if (myDomain == @symbol(unix)) { |
789 | 3152 |
char *pathName; |
3153 |
int l; |
|
3154 |
||
3155 |
if (! __isString(portNrOrName)) { |
|
3156 |
DBGPRINTF(("SOCKET: invalid port (pathname) arg\n")); |
|
3157 |
RETURN (false); |
|
3158 |
} |
|
3159 |
pathName = (char *)__stringVal(portNrOrName); |
|
3160 |
l = strlen(pathName); |
|
3161 |
if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) { |
|
3162 |
DBGPRINTF(("SOCKET: pathname too long\n")); |
|
3163 |
RETURN (false); |
|
3164 |
} |
|
3165 |
||
3166 |
strcpy(sa.un.sun_path, pathName); |
|
3167 |
sa.un.sun_family = AF_UNIX; |
|
3168 |
sockaddr_size = l + sizeof ( sa.un.sun_family ); |
|
3169 |
ok = 1; |
|
28 | 3170 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3171 |
# endif /* AF_UNIX */ |
525 | 3172 |
|
3173 |
# ifdef AF_APPLETALK |
|
3174 |
/* |
|
3175 |
* this has never been tested .... |
|
3176 |
*/ |
|
1009 | 3177 |
else if (myDomain == @symbol(appletalk)) { |
789 | 3178 |
/* |
3179 |
* APPLETALK addresses - port must be a smallinteger or nil |
|
3180 |
*/ |
|
3181 |
sa.at.sat_family = AF_APPLETALK; |
|
3182 |
||
3183 |
if (portNrOrName == nil) { |
|
3184 |
sa.at.sat_port = 0; |
|
3185 |
} else { |
|
3186 |
if (! __isSmallInteger(portNrOrName)) { |
|
3187 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3188 |
RETURN (false); |
|
3189 |
} |
|
3190 |
sa.at.sat_port = __intVal(portNrOrName); |
|
3191 |
} |
|
3192 |
||
3193 |
/* |
|
3194 |
* APPLETALK addresses - addr must be nil, integer or byteArray |
|
819 | 3195 |
* if integer, the first byte are the hi net bits, next byte are low net bits, |
3196 |
* last byte is node. |
|
789 | 3197 |
*/ |
3198 |
if (address == nil) { |
|
3199 |
sa.at.sat_addr.s_net = ATADDR_ANYNET; |
|
3200 |
sa.at.sat_addr.s_node = ATADDR_ANYNODE; |
|
3201 |
} else { |
|
3202 |
if (__isInteger(address)) { |
|
3203 |
unsigned a = __longIntVal(address); |
|
3204 |
sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF); |
|
3205 |
sa.at.sat_addr.s_node = htons(a & 0xFF); |
|
3206 |
} else { |
|
3207 |
if (__isByteArray(address)) { |
|
3208 |
unsigned char *cp; |
|
3209 |
int n; |
|
3210 |
||
3211 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
3212 |
n = __byteArraySize(address); |
|
3213 |
if (n > 3) n = 3; |
|
3214 |
bcopy(cp, &sa.at.sat_addr, n); |
|
3215 |
} else { |
|
3216 |
unsigned addr; |
|
3217 |
struct hostent *hp ; |
|
3218 |
||
3219 |
if (! __isString(address)) { |
|
3220 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
3221 |
RETURN (false); |
|
3222 |
} |
|
3223 |
||
3224 |
/* |
|
3225 |
* do we know the host's address? |
|
3226 |
*/ |
|
3227 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
3228 |
if (hp == NULL) { |
|
3229 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address))); |
|
3230 |
RETURN (false); |
|
3231 |
} |
|
3232 |
if (hp->h_addrtype != AF_APPLETALK) { |
|
3233 |
DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(address))); |
|
3234 |
RETURN (false); |
|
3235 |
} |
|
3236 |
bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ; |
|
3237 |
sa.at.sat_family = hp->h_addrtype; |
|
3238 |
} |
|
3239 |
} |
|
3240 |
} |
|
3241 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
|
3242 |
sockaddr_size = sizeof(struct sockaddr_at); |
|
3243 |
ok = 1; |
|
525 | 3244 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3245 |
# endif /* AF_APPLETALK */ |
525 | 3246 |
|
28 | 3247 |
/* |
3248 |
* XXXX add addressing stuff for other domains here ... |
|
3249 |
*/ |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3250 |
# ifdef AF_X25 |
1009 | 3251 |
else if (myDomain == @symbol(x25)) { |
28 | 3252 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3253 |
# endif |
819 | 3254 |
# ifdef AF_AX25 |
1009 | 3255 |
else if (myDomain == @symbol(ax25)) { |
819 | 3256 |
} |
3257 |
# endif |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3258 |
# ifdef AF_NS |
1009 | 3259 |
else if ((myDomain == @symbol(ns)) |
812 | 3260 |
|| (myDomain == @symbol(xns))) { |
28 | 3261 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3262 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3263 |
# ifdef AF_DECnet |
1009 | 3264 |
else if (myDomain == @symbol(decnet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3265 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3266 |
# endif |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3267 |
# ifdef AF_SNA |
1009 | 3268 |
else if (myDomain == @symbol(sna)) { |
93 | 3269 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3270 |
# endif |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3271 |
# ifdef AF_RAW |
1009 | 3272 |
else if (myDomain == @symbol(raw)) { |
93 | 3273 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3274 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3275 |
# ifdef AF_ISO |
1009 | 3276 |
else if (myDomain == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3277 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3278 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3279 |
# ifdef AF_NETBIOS |
1009 | 3280 |
else if (myDomain == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3281 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3282 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3283 |
# ifdef AF_IPX |
1009 | 3284 |
else if (myDomain == @symbol(ipx)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3285 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3286 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3287 |
# ifdef AF_BRIDGE |
1009 | 3288 |
else if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3289 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3290 |
# endif |
571 | 3291 |
# ifdef AF_BSC |
1009 | 3292 |
else if (myDomain == @symbol(bsc)) { |
571 | 3293 |
} |
3294 |
# endif |
|
812 | 3295 |
# ifdef AF_ROSE |
1009 | 3296 |
else if (myDomain == @symbol(rose)) { |
812 | 3297 |
} |
3298 |
# endif |
|
869 | 3299 |
# ifdef AF_IRDA |
1009 | 3300 |
else if (myDomain == @symbol(irda)) { |
869 | 3301 |
} |
3302 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3303 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3304 |
else if (myDomain == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3305 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3306 |
# endif |
0 | 3307 |
|
28 | 3308 |
if (! ok) { |
789 | 3309 |
DBGPRINTF(("SOCKET: unsupported domain\n")); |
3310 |
RETURN (false); |
|
28 | 3311 |
} |
3312 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
3313 |
sock = fileno(__FILEVal(t)); |
28 | 3314 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3315 |
# ifdef SO_REUSEADDR |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3316 |
if (reuse == true) { |
789 | 3317 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
3318 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
3319 |
} |
|
28 | 3320 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3321 |
# endif /* SO_REUSEADDR */ |
28 | 3322 |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3323 |
__BEGIN_INTERRUPTABLE__ |
28 | 3324 |
do { |
789 | 3325 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
28 | 3326 |
} while ((ret < 0) && (errno == EINTR)); |
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3327 |
__END_INTERRUPTABLE__ |
28 | 3328 |
|
3329 |
if (ret < 0) { |
|
789 | 3330 |
DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno)); |
3331 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3332 |
RETURN (false); |
|
0 | 3333 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3334 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3335 |
__INST(port) = portNrOrName; __STORE(self, portNrOrName); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3336 |
|
1009 | 3337 |
if (0) { |
3338 |
/* for else below */ |
|
3339 |
} |
|
3340 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3341 |
# ifdef AF_INET |
1009 | 3342 |
else if (myDomain == @symbol(inet)) { |
789 | 3343 |
if (! __isSmallInteger(portNrOrName) |
3344 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3345 |
int p; |
|
3346 |
||
3347 |
/* |
|
3348 |
* INET anonymous port - get the actual portNr |
|
3349 |
*/ |
|
3350 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3351 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3352 |
} else { |
|
3353 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3354 |
p = ntohs(sa.in.sin_port); |
|
3355 |
__INST(port) = __MKSMALLINT(p); |
|
3356 |
} |
|
3357 |
} |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3358 |
} |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3359 |
# endif |
819 | 3360 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3361 |
# ifdef AF_INET6 |
1009 | 3362 |
else if (myDomain == @symbol(inet6)) { |
789 | 3363 |
if (! __isSmallInteger(portNrOrName) |
3364 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3365 |
int p; |
|
3366 |
||
3367 |
/* |
|
3368 |
* INET6 anonymous port - get the actual portNr |
|
3369 |
*/ |
|
3370 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3371 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3372 |
} else { |
|
3373 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3374 |
p = ntohs(sa.in6.sin6_port); |
|
3375 |
__INST(port) = __MKSMALLINT(p); |
|
3376 |
} |
|
3377 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3378 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3379 |
# endif |
819 | 3380 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3381 |
# ifdef AF_APPLETALK |
1009 | 3382 |
else if (myDomain == @symbol(appletalk)) { |
789 | 3383 |
if (! __isSmallInteger(portNrOrName) |
3384 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3385 |
int p; |
|
3386 |
||
3387 |
/* |
|
3388 |
* APPLETALK anonymous port - get the actual portNr |
|
3389 |
*/ |
|
3390 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3391 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3392 |
} else { |
|
3393 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3394 |
p = sa.at.sat_port; |
|
3395 |
__INST(port) = __MKSMALLINT(p); |
|
3396 |
} |
|
3397 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3398 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3399 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3400 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3401 |
#else /* NO_SOCKET */ |
418 | 3402 |
RETURN (false); |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3403 |
#endif /* NO_SOCKET */ |
42 | 3404 |
%}. |
28 | 3405 |
^ true |
0 | 3406 |
|
28 | 3407 |
" |
3408 |
(Socket domain:#inet type:#stream) |
|
789 | 3409 |
bindTo:9999 |
3410 |
address:nil |
|
28 | 3411 |
" |
0 | 3412 |
! |
3413 |
||
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3414 |
closeFile |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3415 |
"low level close" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3416 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3417 |
%{ /* NOCONTEXT */ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3418 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3419 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3420 |
OBJ t; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3421 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3422 |
t = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3423 |
if (t != nil) { |
812 | 3424 |
FILE *fp; |
3425 |
||
3426 |
fp = __FILEVal(t); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3427 |
DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fileno(fp))); |
812 | 3428 |
fflush(fp); |
3429 |
/* shutdown(fileno(fp), 2); */ |
|
1035 | 3430 |
if (@global(FileOpenTrace) == true) { |
876 | 3431 |
fprintf(stderr, "fclose [Socket] %x\n", fp); |
3432 |
} |
|
812 | 3433 |
fclose(fp); |
3434 |
__INST(filePointer) = nil; |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3435 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3436 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3437 |
%} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3438 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3439 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3440 |
getSocketError |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3441 |
"get the SO_ERROR form the socket, which indicates the |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3442 |
result of an asynchronous operation" |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3443 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3444 |
%{ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3445 |
OBJ t; |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3446 |
int err; |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3447 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3448 |
t = __INST(filePointer); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3449 |
if (t == nil) |
1009 | 3450 |
err = EBADF; |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3451 |
else { |
1009 | 3452 |
int sz, fd; |
3453 |
||
3454 |
fd = fileno(__FILEVal(t)); |
|
3455 |
sz = sizeof(err); |
|
3456 |
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) |
|
3457 |
err = errno; |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3458 |
} |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3459 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3460 |
RETURN(__MKSMALLINT(err)); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3461 |
%} |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3462 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3463 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3464 |
! |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3465 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3466 |
listenFor:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3467 |
"same as listenWithBacklog: - for ST-80 compatibility" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3468 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3469 |
^ self listenWithBacklog:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3470 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3471 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3472 |
listenWithBacklog:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3473 |
"start listening; return true if ok, false on error" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3474 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3475 |
filePointer isNil ifTrue:[ |
789 | 3476 |
^ self errorNotOpen |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3477 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3478 |
%{ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3479 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3480 |
OBJ fp = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3481 |
int sock; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3482 |
int ret; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3483 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3484 |
if (! __isSmallInteger(aNumber)) { |
789 | 3485 |
DBGPRINTF(("SOCKET: invalid arg\n")); |
3486 |
RETURN (false); |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3487 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3488 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3489 |
sock = fileno(__FILEVal(fp)); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3490 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3491 |
__BEGIN_INTERRUPTABLE__ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3492 |
do { |
1009 | 3493 |
ret = listen(sock, __intVal(aNumber)); |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3494 |
} while ((ret < 0) && (errno == EINTR)); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3495 |
__END_INTERRUPTABLE__ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3496 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3497 |
if (ret < 0) { |
789 | 3498 |
DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno)); |
3499 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3500 |
RETURN (false); |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3501 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3502 |
#else |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3503 |
RETURN (false); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3504 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3505 |
%}. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3506 |
^ true |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3507 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3508 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3509 |
shutDown |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3510 |
"shutDown without flushing " |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3511 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3512 |
filePointer isNil ifTrue:[^ self]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3513 |
Lobby unregister:self. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3514 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3515 |
%{ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3516 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3517 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3518 |
OBJ fp; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3519 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3520 |
fp = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3521 |
if (fp != nil) { |
812 | 3522 |
FILE *f; |
3523 |
int fd; |
|
3524 |
||
3525 |
__INST(filePointer) = nil; |
|
3526 |
f = __FILEVal(fp); |
|
3527 |
fd = fileno(f); |
|
3528 |
__BEGIN_INTERRUPTABLE__ |
|
3529 |
shutdown(fd, 2); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3530 |
DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fd)); |
1035 | 3531 |
if (@global(FileOpenTrace) == true) { |
876 | 3532 |
fprintf(stderr, "fclose [Socket] %x\n", f); |
3533 |
} |
|
812 | 3534 |
fclose(f); |
3535 |
/* close(fd); */ |
|
3536 |
__END_INTERRUPTABLE__ |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3537 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3538 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3539 |
%} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3540 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3541 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3542 |
!Socket methodsFor:'low level-accepting'! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3543 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3544 |
accept |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3545 |
"create a new TCP socket from accepting on the receiver. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3546 |
This method will suspend the current process if no connection is waiting. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3547 |
For ST-80 compatibility" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3548 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3549 |
|newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3550 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3551 |
newSock := self class new. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3552 |
(newSock acceptOn:self) ifFalse:[^ nil]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3553 |
^ newSock |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3554 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3555 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3556 |
|sock newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3557 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3558 |
sock := Socket provide:8004. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3559 |
sock listenFor:5. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3560 |
newSock := sock accept. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3561 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3562 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3563 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3564 |
acceptOn:aSocket |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3565 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3566 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3567 |
This method will suspend the current process if no connection is waiting. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3568 |
Return the true if ok; false if not." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3569 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3570 |
aSocket readWait. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3571 |
^ self primAcceptOn:aSocket |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3572 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3573 |
"Modified: / 11.3.1996 / 14:21:31 / stefan" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3574 |
"Modified: / 1.8.1998 / 23:39:10 / cg" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3575 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3576 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3577 |
primAcceptOn:aSocket |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3578 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3579 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3580 |
Return the true if ok; false if not." |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3581 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3582 |
|serverSocketFd| |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3583 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3584 |
filePointer notNil ifTrue:[ |
1009 | 3585 |
^ self errorAlreadyOpen |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3586 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3587 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3588 |
domain := aSocket domain. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3589 |
socketType := aSocket type. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3590 |
serverSocketFd := aSocket fileDescriptor. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3591 |
serverSocketFd isNil ifTrue:[ |
1009 | 3592 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3593 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3594 |
(serverSocketFd isMemberOf:SmallInteger) ifFalse:[ |
1009 | 3595 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3596 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3597 |
%{ |
418 | 3598 |
#ifndef NO_SOCKET |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3599 |
FILE *fp; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3600 |
int flags; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3601 |
int sock, newSock; |
819 | 3602 |
union sockaddr_u sa; |
464 | 3603 |
int alen, alen0; |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3604 |
struct hostent *he ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3605 |
char dotted[20] ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3606 |
|
1009 | 3607 |
if (0) { |
3608 |
/* for else below */ |
|
3609 |
} |
|
876 | 3610 |
# ifdef AF_INET |
1009 | 3611 |
else if (__INST(domain) == @symbol(inet)) { |
3612 |
alen0 = sizeof(sa.in); |
|
464 | 3613 |
} |
876 | 3614 |
# endif |
3615 |
# ifdef AF_INET6 |
|
1009 | 3616 |
else if (__INST(domain) == @symbol(inet6)) { |
3617 |
alen0 = sizeof(sa.in6); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3618 |
} |
876 | 3619 |
# endif |
3620 |
# ifdef AF_UNIX |
|
1009 | 3621 |
else if (__INST(domain) == @symbol(unix)) { |
3622 |
alen0 = sizeof(sa.un); |
|
464 | 3623 |
} |
876 | 3624 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3625 |
# ifdef AF_APPLETALK |
1009 | 3626 |
else if (__INST(domain) == @symbol(appletalk)) { |
3627 |
alen0 = sizeof(sa.at); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3628 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3629 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3630 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3631 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3632 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3633 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3634 |
# ifdef AF_X25 |
1009 | 3635 |
else if (__INST(domain) == @symbol(x25)) { |
3636 |
alen0 = sizeof(sa.x25); |
|
819 | 3637 |
} |
3638 |
# endif |
|
3639 |
# ifdef AF_AX25 |
|
1009 | 3640 |
else if (__INST(domain) == @symbol(ax25)) { |
3641 |
alen0 = sizeof(sa.ax25); |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3642 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3643 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3644 |
# ifdef AF_NS |
1009 | 3645 |
else if ((__INST(domain) == @symbol(ns)) |
812 | 3646 |
|| (__INST(domain) == @symbol(xns))) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3647 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3648 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3649 |
# ifdef AF_DECnet |
1009 | 3650 |
else if (__INST(domain) == @symbol(decnet)) { |
3651 |
alen0 = sizeof(sa.dn); |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3652 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3653 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3654 |
# ifdef AF_SNA |
1009 | 3655 |
else if (__INST(domain) == @symbol(sna)) { |
3656 |
alen0 = sizeof(sa.sna); |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3657 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3658 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3659 |
# ifdef AF_RAW |
1009 | 3660 |
else if (__INST(domain) == @symbol(raw)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3661 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3662 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3663 |
# ifdef AF_ISO |
1009 | 3664 |
else if (__INST(domain) == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3665 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3666 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3667 |
# ifdef AF_NETBIOS |
1009 | 3668 |
else if (__INST(domain) == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3669 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3670 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3671 |
# ifdef AF_IPX |
1009 | 3672 |
else if (__INST(domain) == @symbol(ipx)) { |
3673 |
alen0 = sizeof(sa.ipx); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3674 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3675 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3676 |
# ifdef AF_BRIDGE |
1009 | 3677 |
else if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3678 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3679 |
# endif |
571 | 3680 |
# ifdef AF_BSC |
1009 | 3681 |
else if (__INST(domain) == @symbol(bsc)) { |
571 | 3682 |
} |
3683 |
# endif |
|
812 | 3684 |
# ifdef AF_ROSE |
1009 | 3685 |
else if (__INST(domain) == @symbol(rose)) { |
812 | 3686 |
} |
3687 |
# endif |
|
869 | 3688 |
# ifdef AF_IRDA |
1009 | 3689 |
else if (__INST(domain) == @symbol(irda)) { |
869 | 3690 |
} |
3691 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3692 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3693 |
else if (__INST(domain) == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3694 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3695 |
# endif |
464 | 3696 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3697 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3698 |
sock = __intVal(serverSocketFd); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3699 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3700 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3701 |
flags = ioctl(sock, F_GETFL, 0); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3702 |
ioctl(sock, F_SETFL, flags | O_NDELAY); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3703 |
# endif |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3704 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3705 |
__BEGIN_INTERRUPTABLE__ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3706 |
do { |
1009 | 3707 |
alen = alen0; |
3708 |
newSock = accept(sock, (struct sockaddr *) &sa, &alen); |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3709 |
} while ((newSock < 0) && (errno == EINTR)); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3710 |
__END_INTERRUPTABLE__ |
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3711 |
DBGFPRINTF((stderr, "socket accept newSock=%d\n", newSock)); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3712 |
|
876 | 3713 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3714 |
ioctl(sock, F_SETFL, flags); |
876 | 3715 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3716 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3717 |
if (newSock < 0) { |
1009 | 3718 |
DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno)); |
3719 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3720 |
RETURN (false); |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3721 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3722 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3723 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3724 |
* extract the partners address |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3725 |
*/ |
1009 | 3726 |
if (0) { |
3727 |
/* for else below */ |
|
3728 |
} |
|
876 | 3729 |
# ifdef AF_INET |
1009 | 3730 |
else if (__INST(domain) == @symbol(inet)) { |
3731 |
GETHOSTBYADDR(he, (char *) &sa.in.sin_addr, sizeof(sa.in.sin_addr), AF_INET); |
|
3732 |
if (! he) { |
|
3733 |
unsigned long norder; |
|
3734 |
||
3735 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
|
3736 |
sprintf(dotted, "%d.%d.%d.%d", |
|
3737 |
(norder >> 24) & 0xFF, |
|
3738 |
(norder >> 16) & 0xFF, |
|
3739 |
(norder >> 8) & 0xFF, |
|
3740 |
norder & 0xFF); |
|
3741 |
} |
|
3742 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
|
3743 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
|
3744 |
__STORESELF(peerName); |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3745 |
} |
876 | 3746 |
# endif |
3747 |
||
3748 |
# ifdef AF_INET6 |
|
1009 | 3749 |
else if (__INST(domain) == @symbol(inet6)) { |
3750 |
GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr, sizeof(sa.in6.sin6_addr), AF_INET6); |
|
3751 |
if (! he) { |
|
3752 |
unsigned long norder; |
|
3753 |
||
3754 |
/* |
|
3755 |
* XXX: what is inet6's naming convention ? |
|
3756 |
*/ |
|
3757 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
|
3758 |
sprintf(dotted, "%d.%d.%d.%d.%d.%d...", |
|
3759 |
sa.in6.sin6_addr.s6_addr[0], |
|
3760 |
sa.in6.sin6_addr.s6_addr[1], |
|
3761 |
sa.in6.sin6_addr.s6_addr[2], |
|
3762 |
sa.in6.sin6_addr.s6_addr[3], |
|
3763 |
sa.in6.sin6_addr.s6_addr[4], |
|
3764 |
sa.in6.sin6_addr.s6_addr[5]); |
|
3765 |
} |
|
3766 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
|
3767 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
|
3768 |
__STORESELF(peerName); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3769 |
} |
876 | 3770 |
# endif |
3771 |
||
3772 |
# ifdef AF_UNIX |
|
1009 | 3773 |
else if (__INST(domain) == @symbol(unix)) { |
3774 |
DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ; |
|
3775 |
/* nothing to be done here */ |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3776 |
} |
876 | 3777 |
# endif |
3778 |
||
3779 |
# ifdef AF_APPLETALK |
|
1009 | 3780 |
else if (__INST(domain) == @symbol(appletalk)) { |
3781 |
GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, sizeof(sa.at.sat_addr), AF_APPLETALK); |
|
3782 |
if (! he) { |
|
3783 |
unsigned net; |
|
3784 |
||
3785 |
/* |
|
3786 |
* XXX: what is apples naming convention ? |
|
3787 |
*/ |
|
3788 |
net = htons(sa.at.sat_addr.s_net) ; |
|
3789 |
sprintf(dotted, "%d.%d", |
|
3790 |
net, |
|
3791 |
sa.at.sat_addr.s_node); |
|
3792 |
} |
|
3793 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
|
3794 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
|
3795 |
__STORESELF(peerName); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3796 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3797 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3798 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3799 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3800 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3801 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3802 |
# ifdef AF_X25 |
1009 | 3803 |
else if (__INST(domain) == @symbol(x25)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3804 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3805 |
# endif |
819 | 3806 |
# ifdef AF_AX25 |
1009 | 3807 |
else if (__INST(domain) == @symbol(ax25)) { |
819 | 3808 |
} |
3809 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3810 |
# ifdef AF_NS |
1009 | 3811 |
else if ((__INST(domain) == @symbol(ns)) |
812 | 3812 |
|| (__INST(domain) == @symbol(xns))) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3813 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3814 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3815 |
# ifdef AF_DECnet |
1009 | 3816 |
else if (__INST(domain) == @symbol(decnet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3817 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3818 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3819 |
# ifdef AF_SNA |
1009 | 3820 |
else if (__INST(domain) == @symbol(sna)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3821 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3822 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3823 |
# ifdef AF_RAW |
1009 | 3824 |
else if (__INST(domain) == @symbol(raw)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3825 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3826 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3827 |
# ifdef AF_ISO |
1009 | 3828 |
else if (__INST(domain) == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3829 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3830 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3831 |
# ifdef AF_NETBIOS |
1009 | 3832 |
else if (__INST(domain) == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3833 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3834 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3835 |
# ifdef AF_IPX |
1009 | 3836 |
else if (__INST(domain) == @symbol(ipx)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3837 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3838 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3839 |
# ifdef AF_BRIDGE |
1009 | 3840 |
else if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3841 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3842 |
# endif |
571 | 3843 |
# ifdef AF_BSC |
1009 | 3844 |
else if (__INST(domain) == @symbol(bsc)) { |
571 | 3845 |
} |
3846 |
# endif |
|
812 | 3847 |
# ifdef AF_ROSE |
1009 | 3848 |
else if (__INST(domain) == @symbol(rose)) { |
812 | 3849 |
} |
3850 |
# endif |
|
869 | 3851 |
# ifdef AF_IRDA |
1009 | 3852 |
else if (__INST(domain) == @symbol(irda)) { |
869 | 3853 |
} |
3854 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3855 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3856 |
else if (__INST(domain) == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3857 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3858 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3859 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3860 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3861 |
* make it a FILE * |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3862 |
*/ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3863 |
fp = fdopen(newSock, "r+"); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3864 |
if (! fp) { |
1009 | 3865 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
3866 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3867 |
close(newSock); |
|
3868 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", newSock)); |
|
3869 |
RETURN (false); |
|
876 | 3870 |
} |
1035 | 3871 |
if (@global(FileOpenTrace) == true) { |
1009 | 3872 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3873 |
} |
876 | 3874 |
|
3875 |
# ifdef BUGGY_STDIO_LIB |
|
3876 |
setbuf(fp, NULL); |
|
3877 |
__INST(buffered) = false; |
|
3878 |
# endif |
|
3879 |
||
3880 |
__INST(filePointer) = __MKOBJ(fp); |
|
3881 |
__STORESELF(filePointer); |
|
3882 |
#endif /* not NO_SOCKET */ |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3883 |
%}. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3884 |
mode := #readwrite. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3885 |
Lobby register:self. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3886 |
binary := false. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3887 |
port := aSocket port. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3888 |
^ true |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3889 |
! |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3890 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3891 |
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3892 |
"suspend the current process, until either a new connection comes |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3893 |
in at the receiver, or data arrives on any of the otherConnections. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3894 |
For a new connection, an accept is performed and the new socket is returned. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3895 |
For an old connection, that socket is returned. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3896 |
In any case, the caller gets a socket to operate on as return value, |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3897 |
or nil, if a timeout occured. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3898 |
This method implements the inner wait-primitive of a multi-connection |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3899 |
server application." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3900 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3901 |
"/ first, a quick check if data is already available |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3902 |
|
1035 | 3903 |
|wasBlocked sema| |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3904 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3905 |
self canReadWithoutBlocking ifTrue:[ |
789 | 3906 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3907 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3908 |
otherConnections do:[:aConnection | |
789 | 3909 |
aConnection canReadWithoutBlocking ifTrue:[ |
3910 |
^ aConnection |
|
3911 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3912 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3913 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3914 |
[ |
789 | 3915 |
"/ check again - prevent incoming interrupts from disturbing our setup |
3916 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3917 |
||
3918 |
self canReadWithoutBlocking ifTrue:[ |
|
3919 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3920 |
^ self accept. |
|
3921 |
]. |
|
3922 |
otherConnections do:[:aConnection | |
|
3923 |
aConnection canReadWithoutBlocking ifTrue:[ |
|
3924 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3925 |
^ aConnection |
|
3926 |
] |
|
3927 |
]. |
|
3928 |
||
3929 |
"/ nope - must wait. |
|
3930 |
||
3931 |
sema := Semaphore new name:'multiReadWait'. |
|
3932 |
otherConnections do:[:aConnection | |
|
3933 |
Processor signal:sema onInput:(aConnection fileDescriptor). |
|
3934 |
]. |
|
3935 |
Processor signal:sema onInput:(self fileDescriptor). |
|
3936 |
timeoutSeconds notNil ifTrue:[ |
|
3937 |
Processor signal:sema afterSeconds:timeoutSeconds |
|
3938 |
]. |
|
3939 |
Processor activeProcess state:#ioWait. |
|
3940 |
sema wait. |
|
3941 |
Processor disableSemaphore:sema. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3942 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3943 |
] valueOnUnwindDo:[ |
789 | 3944 |
Processor disableSemaphore:sema. |
3945 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3946 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3947 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3948 |
"/ see who it was ... |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3949 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3950 |
self canReadWithoutBlocking ifTrue:[ |
789 | 3951 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3952 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3953 |
otherConnections do:[:aConnection | |
789 | 3954 |
aConnection canReadWithoutBlocking ifTrue:[ |
3955 |
^ aConnection |
|
3956 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3957 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3958 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3959 |
"/ none - a timeout |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3960 |
^ nil |
867 | 3961 |
! |
3962 |
||
3963 |
waitForNewConnectionWithTimeout:timeoutSeconds |
|
3964 |
"suspend the current process, until a new connection comes |
|
3965 |
in at the receiver or a timeout occurs. |
|
3966 |
For a new connection, an accept is performed and the new socket is returned. |
|
3967 |
Returns nil, if a timeout occured. |
|
3968 |
This method implements the inner wait-primitive of a single-connection |
|
3969 |
server application." |
|
3970 |
||
3971 |
(self readWaitWithTimeout:timeoutSeconds) ifTrue:[ |
|
3972 |
"/ a timeout occurred - no connection within timeout |
|
3973 |
^ nil |
|
3974 |
]. |
|
3975 |
^ self accept. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3976 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3977 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3978 |
!Socket methodsFor:'low level-connecting'! |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
3979 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3980 |
connectTo:hostOrPathName port:portNrOrName |
71 | 3981 |
"low level connect; connect to port, portNrOrName on host, hostName. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3982 |
For unix-domain sockets, the port argument is ignored and pathName is taken. |
115 | 3983 |
Other sockets are not yet implemented. |
71 | 3984 |
Return true if ok, false otherwise. |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
3985 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
3986 |
The current process will block (but not the whole Smalltalk) until the connection |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3987 |
is established. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3988 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
28 | 3989 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3990 |
^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil |
649 | 3991 |
! |
3992 |
||
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3993 |
connectTo:hostOrPathName port:portNrOrName withTimeout:timeout |
649 | 3994 |
"low level connect; connect to port, portNrOrName on host, hostName. |
3995 |
For unix-domain sockets, the port argument is ignored and pathName is taken. |
|
3996 |
Other sockets are not yet implemented. |
|
3997 |
Return true if ok, false otherwise. |
|
3998 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
|
3999 |
The current process will block (but not the whole Smalltalk) until the connection |
|
4000 |
is established. |
|
4001 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
|
4002 |
||
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4003 |
|isAsync err| |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4004 |
|
28 | 4005 |
filePointer isNil ifTrue:[ |
1009 | 4006 |
^ self errorNotOpen |
28 | 4007 |
]. |
0 | 4008 |
%{ |
649 | 4009 |
|
418 | 4010 |
#ifndef NO_SOCKET |
217 | 4011 |
OBJ t = __INST(filePointer); |
71 | 4012 |
OBJ myDomain; |
819 | 4013 |
union sockaddr_u sa; |
28 | 4014 |
struct hostent *hp ; |
4015 |
int a, sock ; |
|
4016 |
long addr; |
|
4017 |
FILE *fp; |
|
649 | 4018 |
int ret, oldFlags; |
28 | 4019 |
int on = 1; |
4020 |
int ok; |
|
115 | 4021 |
int sockaddr_size; |
28 | 4022 |
|
217 | 4023 |
if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) { |
1009 | 4024 |
DBGPRINTF(("SOCKET: invalid domain arg\n")); |
4025 |
RETURN (false); |
|
28 | 4026 |
} |
4027 |
||
4028 |
ok = 0; |
|
217 | 4029 |
myDomain = __INST(domain); |
115 | 4030 |
bzero((char *) &sa, sizeof(sa)) ; |
508 | 4031 |
|
1009 | 4032 |
if (0) { |
4033 |
/* for ese below */ |
|
4034 |
} |
|
28 | 4035 |
#ifdef AF_INET |
1009 | 4036 |
else if (myDomain == @symbol(inet)) { |
4037 |
/* |
|
4038 |
* INET addressing: port must be a smallInteger; |
|
4039 |
* hostOrPathName the name of the host (dot notation allowed) |
|
4040 |
* or a byteArray containing the 4 address bytes. |
|
4041 |
*/ |
|
4042 |
if (! __isSmallInteger(portNrOrName)) { |
|
4043 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
4044 |
RETURN (false); |
|
4045 |
} |
|
4046 |
||
4047 |
sa.in.sin_family = AF_INET; |
|
4048 |
sa.in.sin_port = htons((u_short) __intVal(portNrOrName)) ; |
|
4049 |
||
4050 |
if (__isByteArray(hostOrPathName)) { |
|
4051 |
unsigned char *cp; |
|
4052 |
int n; |
|
4053 |
unsigned intAddr; |
|
4054 |
||
4055 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
4056 |
n = __byteArraySize(hostOrPathName); |
|
4057 |
if (n < 4) { |
|
4058 |
DBGPRINTF(("SOCKET: invalid ipAddr arg\n")); |
|
4059 |
RETURN (false); |
|
4060 |
} |
|
4061 |
intAddr = cp[0]; |
|
4062 |
intAddr = (intAddr << 8) | cp[1]; |
|
4063 |
intAddr = (intAddr << 8) | cp[2]; |
|
4064 |
intAddr = (intAddr << 8) | cp[3]; |
|
4065 |
sa.in.sin_addr.s_addr = htonl(intAddr); |
|
4066 |
/* bcopy(cp, &sa.in.sin_addr.s_addr, n); */ |
|
4067 |
} else { |
|
4068 |
if (! __isString(hostOrPathName)) { |
|
4069 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
4070 |
RETURN (false); |
|
4071 |
} |
|
4072 |
||
4073 |
if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) { |
|
4074 |
/* |
|
4075 |
* is Internet addr in octet notation |
|
4076 |
*/ |
|
4077 |
bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */ |
|
4078 |
} else { |
|
4079 |
/* |
|
4080 |
* do we know the host's address? |
|
4081 |
*/ |
|
4082 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
4083 |
if (hp == NULL) { |
|
4084 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
4085 |
RETURN (false); |
|
4086 |
} |
|
4087 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
|
4088 |
sa.in.sin_family = hp->h_addrtype; |
|
4089 |
} |
|
4090 |
} |
|
4091 |
||
4092 |
DBGPRINTF(("SOCKET: connect addr:%d.%d.%d.%d port: %d\n", |
|
4093 |
((unsigned char *)(&sa.in.sin_addr.s_addr))[0], |
|
4094 |
((unsigned char *)(&sa.in.sin_addr.s_addr))[1], |
|
4095 |
((unsigned char *)(&sa.in.sin_addr.s_addr))[2], |
|
4096 |
((unsigned char *)(&sa.in.sin_addr.s_addr))[3], |
|
962 | 4097 |
ntohs(sa.in.sin_port))); |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4098 |
|
1009 | 4099 |
sockaddr_size = sizeof(struct sockaddr_in); |
4100 |
ok = 1; |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4101 |
} |
525 | 4102 |
#endif /* AF_INET */ |
4103 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4104 |
#ifdef AF_INET6 |
1009 | 4105 |
else if (myDomain == @symbol(inet6)) { |
4106 |
/* |
|
4107 |
* INET6 addressing: port must be a smallInteger; |
|
4108 |
* hostOrPathName the name of the host |
|
4109 |
* or a byteArray containing the address bytes. |
|
4110 |
*/ |
|
4111 |
if (! __isSmallInteger(portNrOrName)) { |
|
4112 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
4113 |
RETURN (false); |
|
4114 |
} |
|
4115 |
||
4116 |
sa.in6.sin6_family = AF_INET6; |
|
4117 |
sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName)) ; |
|
4118 |
||
4119 |
if (__isByteArray(hostOrPathName)) { |
|
4120 |
unsigned char *cp; |
|
4121 |
int n; |
|
4122 |
||
4123 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
4124 |
n = __byteArraySize(hostOrPathName); |
|
4125 |
if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr); |
|
4126 |
bcopy(cp, sa.in6.sin6_addr.s6_addr, n); |
|
4127 |
} else { |
|
4128 |
if (! __isString(hostOrPathName)) { |
|
4129 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
4130 |
RETURN (false); |
|
4131 |
} |
|
4132 |
||
4133 |
/* |
|
4134 |
* do we know the host's address? |
|
4135 |
*/ |
|
4136 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
4137 |
if (hp == NULL) { |
|
4138 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
4139 |
RETURN (false); |
|
4140 |
} |
|
4141 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
|
4142 |
sa.in.sin_family = hp->h_addrtype; |
|
4143 |
} |
|
4144 |
||
4145 |
DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x... port: %d\n", |
|
4146 |
sa.in6.sin6_addr.s6_addr[0], |
|
4147 |
sa.in6.sin6_addr.s6_addr[1], |
|
4148 |
sa.in6.sin6_addr.s6_addr[2], |
|
4149 |
sa.in6.sin6_addr.s6_addr[3], |
|
4150 |
sa.in6.sin6_addr.s6_addr[4], |
|
4151 |
sa.in6.sin6_addr.s6_addr[5], |
|
4152 |
sa.in6.sin6_port)); |
|
4153 |
||
4154 |
sockaddr_size = sizeof(struct sockaddr_in6); |
|
4155 |
ok = 1; |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4156 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4157 |
#endif /* AF_INET6 */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4158 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4159 |
#ifdef AF_UNIX |
1009 | 4160 |
else if (myDomain == @symbol(unix)) { |
4161 |
char *pathName; |
|
4162 |
int l; |
|
4163 |
||
4164 |
/* |
|
4165 |
* UNIX domain: port is ignored; |
|
4166 |
* hostOrPathName is a pathName |
|
4167 |
*/ |
|
4168 |
if (! __isString(hostOrPathName)) { |
|
4169 |
DBGPRINTF(("SOCKET: invalid port (pathname) arg\n")); |
|
4170 |
RETURN (false); |
|
4171 |
} |
|
4172 |
pathName = (char *) __stringVal(hostOrPathName); |
|
4173 |
l = strlen(pathName); |
|
4174 |
if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) { |
|
4175 |
DBGPRINTF(("SOCKET: pathname too long\n")); |
|
4176 |
RETURN (false); |
|
4177 |
} |
|
4178 |
||
4179 |
strcpy(sa.un.sun_path, pathName); |
|
4180 |
sa.un.sun_family = AF_UNIX; |
|
4181 |
sockaddr_size = l + sizeof ( sa.un.sun_family ); |
|
4182 |
ok = 1; |
|
28 | 4183 |
} |
525 | 4184 |
#endif /* AF_UNIX */ |
4185 |
||
4186 |
#ifdef AF_APPLETALK |
|
1009 | 4187 |
else if (myDomain == @symbol(appletalk)) { |
4188 |
/* |
|
4189 |
* APPLETALK addressing: port must be a smallInteger; |
|
4190 |
* hostOrPathName the name of the host |
|
4191 |
* or a byteArray containing the 3 address bytes. |
|
4192 |
*/ |
|
4193 |
if (! __isSmallInteger(portNrOrName)) { |
|
4194 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
4195 |
RETURN (false); |
|
4196 |
} |
|
4197 |
||
4198 |
sa.at.sat_family = AF_APPLETALK; |
|
4199 |
sa.at.sat_port = __intVal(portNrOrName); |
|
4200 |
||
4201 |
if (__isByteArray(hostOrPathName)) { |
|
4202 |
unsigned char *cp; |
|
4203 |
int n; |
|
4204 |
||
4205 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
4206 |
n = __byteArraySize(hostOrPathName); |
|
4207 |
if (n > 3) n = 3; |
|
4208 |
bcopy(cp, &sa.at.sat_addr, n); |
|
4209 |
} else { |
|
4210 |
if (! __isString(hostOrPathName)) { |
|
4211 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
4212 |
RETURN (false); |
|
4213 |
} |
|
4214 |
||
4215 |
/* |
|
4216 |
* do we know the host's address? |
|
4217 |
*/ |
|
4218 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
4219 |
if (hp == NULL) { |
|
4220 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
4221 |
RETURN (false); |
|
4222 |
} |
|
4223 |
if (hp->h_addrtype != AF_APPLETALK) { |
|
4224 |
DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName))); |
|
4225 |
RETURN (false); |
|
4226 |
} |
|
4227 |
||
4228 |
bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ; |
|
4229 |
sa.at.sat_family = hp->h_addrtype; |
|
4230 |
} |
|
4231 |
||
4232 |
DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port)); |
|
4233 |
||
4234 |
sockaddr_size = sizeof(struct sockaddr_at); |
|
4235 |
ok = 1; |
|
525 | 4236 |
} |
4237 |
#endif /* APPLETALK */ |
|
4238 |
||
28 | 4239 |
/* |
4240 |
* XXXX add addressing stuff for other domains here ... |
|
4241 |
*/ |
|
4242 |
#ifdef AF_X25 |
|
1009 | 4243 |
else if (myDomain == @symbol(x25)) { |
28 | 4244 |
} |
4245 |
#endif |
|
819 | 4246 |
#ifdef AF_AX25 |
1009 | 4247 |
else if (myDomain == @symbol(ax25)) { |
819 | 4248 |
} |
4249 |
#endif |
|
28 | 4250 |
#ifdef AF_NS |
1009 | 4251 |
else if ((myDomain == @symbol(ns)) |
812 | 4252 |
|| (myDomain == @symbol(xns))) { |
28 | 4253 |
} |
4254 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4255 |
# ifdef AF_DECnet |
1009 | 4256 |
else if (myDomain == @symbol(decnet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4257 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4258 |
# endif |
93 | 4259 |
#ifdef AF_SNA |
1009 | 4260 |
else if (myDomain == @symbol(sna)) { |
93 | 4261 |
} |
4262 |
#endif |
|
4263 |
#ifdef AF_RAW |
|
1009 | 4264 |
else if (myDomain == @symbol(raw)) { |
93 | 4265 |
} |
4266 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4267 |
# ifdef AF_ISO |
1009 | 4268 |
else if (myDomain == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4269 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4270 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4271 |
# ifdef AF_NETBIOS |
1009 | 4272 |
else if (myDomain == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4273 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4274 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4275 |
# ifdef AF_IPX |
1009 | 4276 |
else if (myDomain == @symbol(ipx)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4277 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4278 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4279 |
# ifdef AF_BRIDGE |
1009 | 4280 |
else if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4281 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4282 |
# endif |
571 | 4283 |
# ifdef AF_BSC |
1009 | 4284 |
else if (myDomain == @symbol(bsc)) { |
571 | 4285 |
} |
4286 |
# endif |
|
812 | 4287 |
# ifdef AF_ROSE |
1009 | 4288 |
else if (myDomain == @symbol(rose)) { |
812 | 4289 |
} |
4290 |
# endif |
|
869 | 4291 |
# ifdef AF_IRDA |
1009 | 4292 |
else if (__INST(domain) == @symbol(irda)) { |
869 | 4293 |
} |
4294 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4295 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 4296 |
else if (myDomain == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4297 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4298 |
# endif |
28 | 4299 |
|
4300 |
if (! ok) { |
|
1009 | 4301 |
DBGPRINTF(("SOCKET: unsupported domain\n")); |
4302 |
RETURN (false); |
|
28 | 4303 |
} |
4304 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
4305 |
sock = fileno(__FILEVal(t)); |
28 | 4306 |
|
649 | 4307 |
#if defined(O_NONBLOCK) |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4308 |
/* |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4309 |
* set to non-blocking and wait later |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4310 |
*/ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4311 |
oldFlags = fcntl(sock, F_GETFL, 0); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4312 |
/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4313 |
fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK); |
649 | 4314 |
#endif |
4315 |
||
28 | 4316 |
/* |
4317 |
* connect |
|
4318 |
*/ |
|
81 | 4319 |
__BEGIN_INTERRUPTABLE__ |
28 | 4320 |
do { |
1009 | 4321 |
ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size); |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4322 |
} while ((ret < 0) |
1009 | 4323 |
&& ((errno == EINTR) |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4324 |
#ifdef EAGAIN |
1009 | 4325 |
|| (errno == EAGAIN) |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4326 |
#endif |
1009 | 4327 |
)); |
81 | 4328 |
__END_INTERRUPTABLE__ |
28 | 4329 |
|
4330 |
if (ret < 0) { |
|
649 | 4331 |
#if defined(EINPROGRESS) || defined(EALREADY) |
1009 | 4332 |
if (0 |
649 | 4333 |
# ifdef EINPROGRESS |
1009 | 4334 |
|| (errno == EINPROGRESS) |
649 | 4335 |
# endif |
4336 |
# ifdef EALREADY |
|
1009 | 4337 |
|| (errno == EALREADY) |
649 | 4338 |
# endif |
1009 | 4339 |
) { |
4340 |
/* |
|
4341 |
* This was a nonblocking operation that will take some time. |
|
4342 |
* Do a select on read to get informed when the operation is ready. |
|
4343 |
*/ |
|
4344 |
||
4345 |
isAsync = true; |
|
4346 |
} else |
|
649 | 4347 |
#endif /* EINPROGRESS or EALREADY */ |
1009 | 4348 |
{ |
4349 |
DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno)); |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
4350 |
#ifdef DUMP_ADDRESS |
1009 | 4351 |
{ |
4352 |
char *cp = (char *)(&sa); |
|
4353 |
int i; |
|
4354 |
||
4355 |
printf("address data:\n"); |
|
4356 |
for (i=0; i<sockaddr_size; i++) { |
|
4357 |
printf(" %02x\n", *cp++); |
|
4358 |
} |
|
4359 |
} |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
4360 |
#endif |
1009 | 4361 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
4362 |
RETURN (false); |
|
4363 |
} |
|
28 | 4364 |
} |
649 | 4365 |
|
4366 |
#if defined(O_NONBLOCK) |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4367 |
fcntl(sock, F_SETFL, oldFlags); |
649 | 4368 |
#endif |
4369 |
||
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4370 |
#else /* NO_SOCKET */ |
418 | 4371 |
RETURN (false); |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4372 |
#endif /* NO_SOCKET */ |
42 | 4373 |
%}. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4374 |
isAsync == true ifTrue:[ |
1009 | 4375 |
(self writeWaitWithTimeoutMs:timeout) ifTrue:[ |
4376 |
"/ a timeout occured |
|
4377 |
"/ should cancel the connect? |
|
4378 |
^ false. |
|
4379 |
]. |
|
4380 |
err := self getSocketError. |
|
4381 |
err ~~ 0 ifTrue:[ |
|
4382 |
lastErrorNumber := err. |
|
4383 |
^ false. |
|
4384 |
]. |
|
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4385 |
]. |
71 | 4386 |
port := portNrOrName. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4387 |
peerName := hostOrPathName. |
28 | 4388 |
^ true |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4389 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4390 |
" |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4391 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4392 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4393 |
sock connectTo:'localhost' port:21 withTimeout:1000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4394 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4395 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4396 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4397 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4398 |
sock connectTo:'localhost' port:9876 withTimeout:2000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4399 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4400 |
" |
25 | 4401 |
! ! |
4402 |
||
4403 |
!Socket methodsFor:'queries'! |
|
4404 |
||
126 | 4405 |
domain |
4406 |
"return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)" |
|
4407 |
||
4408 |
^ domain |
|
4409 |
! |
|
4410 |
||
4411 |
getName |
|
4412 |
"return the name; here, we return the ports name" |
|
4413 |
||
4414 |
^ port printString |
|
4415 |
! |
|
4416 |
||
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4417 |
getPeer |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4418 |
"ST-80 compatibility: return an IPSocketAddress instance representing |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4419 |
my hostname/port combination. |
155
fcf846c707b7
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
4420 |
If you are interested in the hostname, use getPeerName directly." |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4421 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4422 |
domain == #unix ifTrue:[ |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4423 |
^ UDSocketAddress name:peerName |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
4424 |
]. |
819 | 4425 |
domain == #inet ifTrue:[ |
4426 |
^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port |
|
4427 |
]. |
|
4428 |
domain == #inet6 ifTrue:[ |
|
4429 |
^ IPv6SocketAddress hostAddress:(self class ipV6AddressOfHost:peerName) port:port |
|
4430 |
]. |
|
4431 |
domain == #appletalk ifTrue:[ |
|
4432 |
^ AppletalkSocketAddress hostAddress:(self class appletalkAddressOfHost:peerName) port:port |
|
4433 |
]. |
|
4434 |
domain == #decnet ifTrue:[ |
|
4435 |
^ DecNetSocketAddress hostAddress:(self class decnetAddressOfHost:peerName) port:port |
|
4436 |
]. |
|
4437 |
self error:'unsupported domain'. |
|
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4438 |
|
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4439 |
"Created: 2.11.1995 / 11:22:39 / cg" |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4440 |
! |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4441 |
|
25 | 4442 |
getPeerName |
4443 |
"return the peer name; thats the hostname (or dotted name) of the |
|
4444 |
partners host after an accept." |
|
4445 |
||
4446 |
^ peerName |
|
28 | 4447 |
! |
4448 |
||
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4449 |
getSocketAdress |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4450 |
" |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4451 |
implemented for swazoo project primitive code cant load as extension |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4452 |
answer the my own address (I am bound to this address). |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4453 |
Note that this address may change after connect or accept. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4454 |
" |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4455 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4456 |
|socketAddress error| |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4457 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4458 |
filePointer isNil ifTrue:[ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4459 |
^ self errorNotOpen |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4460 |
]. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4461 |
socketAddress := ByteArray new:16. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4462 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4463 |
%{ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4464 |
#ifndef NO_SOCKET |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4465 |
OBJ t = __INST(filePointer); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4466 |
int sock; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4467 |
int sockaddr_size; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4468 |
int ret; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4469 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4470 |
if (!__isNonNilObject(socketAddress) || |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4471 |
(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) { |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4472 |
error = @symbol(badArgument1); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4473 |
goto err; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4474 |
} |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4475 |
sockaddr_size = __byteArraySize(socketAddress); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4476 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4477 |
sock = fileno(__FILEVal(t)); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4478 |
ret = getsockname(sock, (struct sockaddr *)__byteArrayVal(socketAddress), &sockaddr_size); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4479 |
if (ret < 0) { |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4480 |
DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno)); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4481 |
error = __MKSMALLINT(errno); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4482 |
} |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4483 |
err:; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4484 |
#else /* NO_SOCKET */ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4485 |
error = @symbol(notImplemented); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4486 |
#endif /* NO_SOCKET */ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4487 |
%}. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4488 |
error notNil ifTrue:[ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4489 |
^ self errorReporter reportOn:error |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4490 |
]. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4491 |
^ socketAddress copyFrom:5 to:8 |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4492 |
! |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4493 |
|
126 | 4494 |
isActive |
4495 |
"return true, if the receiver has a connection" |
|
81 | 4496 |
|
126 | 4497 |
^ filePointer notNil |
81 | 4498 |
! |
4499 |
||
71 | 4500 |
port |
4501 |
"return the port number (or name for unix-sockets) to which the socket is bound" |
|
28 | 4502 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4503 |
|p| |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4504 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4505 |
port == 0 ifTrue:[ |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4506 |
p := self getPort. |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4507 |
p notNil ifTrue:[ |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4508 |
port := p |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4509 |
] |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4510 |
]. |
71 | 4511 |
^ port |
28 | 4512 |
! |
4513 |
||
4514 |
type |
|
4515 |
"return the sockets connection type (i.e. #datagram, #stream etc)" |
|
4516 |
||
4517 |
^ socketType |
|
81 | 4518 |
! ! |
4519 |
||
126 | 4520 |
!Socket methodsFor:'socket setup'! |
4521 |
||
4522 |
domain:domainArg type:typeArg |
|
4523 |
"set up socket with domain and type. |
|
4524 |
This is a low level entry; no binding, listening or connect |
|
4525 |
is done. Both arguments must be symbols from one of |
|
4526 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
4527 |
||
649 | 4528 |
^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true |
126 | 4529 |
! |
4530 |
||
4531 |
domain:domainArg type:typeArg protocol:protocolNumber |
|
4532 |
"set up socket with domain, type and protocol number. |
|
4533 |
This is a low level entry; no binding, listening or connect |
|
4534 |
is done. Both arguments must be symbols from one of |
|
4535 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
4536 |
||
649 | 4537 |
^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true |
4538 |
||
4539 |
" |
|
4540 |
Socket new domain:#inet type:#stream |
|
4541 |
Socket new domain:#unix type:#stream |
|
4542 |
" |
|
4543 |
! |
|
4544 |
||
4545 |
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse |
|
4546 |
"set up socket with domain, type and protocol number. |
|
4547 |
This is a low level entry; no binding, listening or connect |
|
4548 |
is done. Both arguments must be symbols from one of |
|
4549 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp. |
|
4550 |
||
4551 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
4552 |
is to be set (to avoid the 'bind: address in use' error)." |
|
4553 |
||
126 | 4554 |
|errorNr| |
4555 |
||
4556 |
filePointer notNil ifTrue:[ |
|
789 | 4557 |
^ self errorAlreadyOpen |
126 | 4558 |
]. |
4559 |
%{ |
|
649 | 4560 |
|
418 | 4561 |
#ifndef NO_SOCKET |
126 | 4562 |
FILE *fp; |
4563 |
int dom, typ, pf, proto = 0, sock; |
|
649 | 4564 |
int on = 1; |
126 | 4565 |
|
4566 |
if (! __isSymbol(domainArg)) { |
|
789 | 4567 |
DBGPRINTF(("SOCKET: bad domain\n")); |
4568 |
RETURN ( nil ); |
|
126 | 4569 |
} |
4570 |
if (! __isSymbol(typeArg)) { |
|
789 | 4571 |
DBGPRINTF(("SOCKET: bad type\n")); |
4572 |
RETURN ( nil ); |
|
126 | 4573 |
} |
4574 |
if (protocolNumber != nil) { |
|
789 | 4575 |
if (!__isSmallInteger(protocolNumber)) { |
4576 |
DBGPRINTF(("SOCKET: bad protocol\n")); |
|
4577 |
RETURN ( nil ); |
|
4578 |
} |
|
4579 |
proto = __intVal(protocolNumber); |
|
126 | 4580 |
} |
4581 |
||
81 | 4582 |
|
126 | 4583 |
/* |
4584 |
* get address and protocol-family |
|
4585 |
*/ |
|
4586 |
#ifdef AF_UNIX |
|
4587 |
if (domainArg == @symbol(unix)) { |
|
789 | 4588 |
dom = AF_UNIX; |
126 | 4589 |
} else |
4590 |
#endif |
|
4591 |
#ifdef AF_INET |
|
4592 |
if (domainArg == @symbol(inet)) { |
|
789 | 4593 |
dom = AF_INET; |
126 | 4594 |
} else |
4595 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4596 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4597 |
if (domainArg == @symbol(inet6)) { |
789 | 4598 |
dom = AF_INET6; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4599 |
} else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4600 |
#endif |
126 | 4601 |
#ifdef AF_DECnet |
819 | 4602 |
if (domainArg == @symbol(decnet)) { |
789 | 4603 |
dom = AF_DECnet; |
126 | 4604 |
} else |
4605 |
#endif |
|
4606 |
#ifdef AF_APPLETALK |
|
4607 |
if (domainArg == @symbol(appletalk)) { |
|
789 | 4608 |
dom = AF_APPLETALK; |
126 | 4609 |
} else |
4610 |
#endif |
|
4611 |
#ifdef AF_X25 |
|
4612 |
if (domainArg == @symbol(x25)) { |
|
789 | 4613 |
dom = AF_X25; |
126 | 4614 |
} else |
4615 |
#endif |
|
819 | 4616 |
#ifdef AF_AX25 |
4617 |
if (domainArg == @symbol(ax25)) { |
|
4618 |
dom = AF_AX25; |
|
4619 |
} else |
|
4620 |
#endif |
|
126 | 4621 |
#ifdef AF_NS |
812 | 4622 |
if ((domainArg == @symbol(xns)) |
4623 |
|| (domainArg == @symbol(ns))) { |
|
789 | 4624 |
dom = AF_NS; |
126 | 4625 |
} else |
4626 |
#endif |
|
4627 |
#ifdef AF_SNA |
|
4628 |
if (domainArg == @symbol(sna)) { |
|
789 | 4629 |
dom = AF_SNA; |
126 | 4630 |
} else |
4631 |
#endif |
|
4632 |
#ifdef AF_RAW |
|
4633 |
if (domainArg == @symbol(raw)) { |
|
789 | 4634 |
dom = AF_RAW; |
126 | 4635 |
} else |
4636 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4637 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4638 |
if (domainArg == @symbol(iso)) { |
789 | 4639 |
dom = AF_ISO; |
874 | 4640 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4641 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4642 |
# ifdef AF_NETBIOS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4643 |
if (domainArg == @symbol(netbios)) { |
789 | 4644 |
dom = AF_NETBIOS; |
874 | 4645 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4646 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4647 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4648 |
if (domainArg == @symbol(ipx)) { |
789 | 4649 |
dom = AF_IPX; |
874 | 4650 |
} else |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4651 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4652 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4653 |
if (domainArg == @symbol(bridge)) { |
789 | 4654 |
dom = AF_BRIDGE; |
874 | 4655 |
} else |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4656 |
# endif |
571 | 4657 |
# ifdef AF_BSC |
4658 |
if (domainArg == @symbol(bsc)) { |
|
789 | 4659 |
dom = AF_BSC; |
874 | 4660 |
} else |
571 | 4661 |
# endif |
812 | 4662 |
# ifdef AF_ROSE |
4663 |
if (domainArg == @symbol(rose)) { |
|
4664 |
dom = AF_ROSE; |
|
874 | 4665 |
} else |
812 | 4666 |
# endif |
869 | 4667 |
# ifdef AF_IRDA |
4668 |
if (domainArg == @symbol(irda)) { |
|
4669 |
dom = AF_IRDA; |
|
874 | 4670 |
} else |
869 | 4671 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4672 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4673 |
if (domainArg == @symbol(ccitt)) { |
789 | 4674 |
dom = AF_CCITT; |
874 | 4675 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4676 |
# endif |
126 | 4677 |
{ |
789 | 4678 |
DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg))); |
4679 |
RETURN ( nil ); |
|
126 | 4680 |
} |
4681 |
||
4682 |
#ifdef SOCK_STREAM |
|
4683 |
if (typeArg == @symbol(stream)) { |
|
789 | 4684 |
typ = SOCK_STREAM; |
126 | 4685 |
} else |
4686 |
#endif |
|
4687 |
#ifdef SOCK_DGRAM |
|
4688 |
if (typeArg == @symbol(datagram)) { |
|
789 | 4689 |
typ = SOCK_DGRAM; |
126 | 4690 |
} else |
4691 |
#endif |
|
4692 |
#ifdef SOCK_RAW |
|
4693 |
if (typeArg == @symbol(raw)) |
|
789 | 4694 |
typ = SOCK_RAW; |
126 | 4695 |
else |
4696 |
#endif |
|
4697 |
#ifdef SOCK_SEQPACKET |
|
4698 |
if (typeArg == @symbol(seqPacket)) |
|
789 | 4699 |
typ = SOCK_SEQPACKET; |
126 | 4700 |
else |
4701 |
#endif |
|
4702 |
{ |
|
789 | 4703 |
DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg))); |
4704 |
RETURN ( nil ); |
|
126 | 4705 |
} |
4706 |
||
4707 |
__BEGIN_INTERRUPTABLE__ |
|
4708 |
do { |
|
789 | 4709 |
DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto)); |
4710 |
sock = socket(dom, typ, proto); |
|
126 | 4711 |
#if defined(EPROTONOSUPPORT) /* for SGI */ |
789 | 4712 |
if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) { |
4713 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
|
4714 |
proto = 0; |
|
4715 |
sock = socket(dom, typ, 0); |
|
4716 |
} |
|
126 | 4717 |
#endif |
4718 |
} while ((sock < 0) && (errno == EINTR)); |
|
4719 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4720 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4721 |
|
4722 |
if (sock < 0) { |
|
789 | 4723 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno)); |
4724 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4725 |
} else { |
649 | 4726 |
# ifdef SO_REUSEADDR |
789 | 4727 |
if (reuse == true) { |
4728 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n")); |
|
4729 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
4730 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
4731 |
} |
|
4732 |
} |
|
649 | 4733 |
# endif /* SO_REUSEADDR */ |
711 | 4734 |
|
789 | 4735 |
/* |
4736 |
* make it a FILE * |
|
4737 |
*/ |
|
4738 |
fp = fdopen(sock, "r+"); |
|
4739 |
if (! fp) { |
|
4740 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
4741 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4742 |
__BEGIN_INTERRUPTABLE__ |
|
4743 |
close(sock); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4744 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4745 |
__END_INTERRUPTABLE__ |
4746 |
} else { |
|
1035 | 4747 |
if (@global(FileOpenTrace) == true) { |
1009 | 4748 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
4749 |
} |
|
876 | 4750 |
|
789 | 4751 |
__INST(filePointer) = __MKOBJ(fp); |
4752 |
__STORESELF(filePointer); |
|
4753 |
} |
|
126 | 4754 |
} |
418 | 4755 |
#endif |
126 | 4756 |
%}. |
4757 |
||
4758 |
"all ok?" |
|
4759 |
filePointer notNil ifTrue:[ |
|
789 | 4760 |
domain := domainArg. |
4761 |
socketType := typeArg. |
|
4762 |
Lobby register:self. |
|
126 | 4763 |
] ifFalse:[ |
789 | 4764 |
^ nil |
126 | 4765 |
]. |
4766 |
||
4767 |
" |
|
4768 |
Socket new domain:#inet type:#stream |
|
4769 |
Socket new domain:#unix type:#stream |
|
4770 |
" |
|
81 | 4771 |
! |
4772 |
||
126 | 4773 |
for:hostName port:portNr |
4774 |
"setup for a TCP socket (i.e. inet domain, stream type) |
|
4775 |
If hostname is nil, a server port is opened, |
|
4776 |
otherwise a client port to the server on host. |
|
4777 |
||
4778 |
HISTORIC LEFTOVER: |
|
4779 |
This method will vanish, as soon as the low level |
|
4780 |
connect/bind works," |
|
4781 |
||
4782 |
self obsoleteMethodWarning. |
|
4783 |
||
4784 |
filePointer notNil ifTrue:[ |
|
789 | 4785 |
^ self errorAlreadyOpen |
126 | 4786 |
]. |
4787 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
789 | 4788 |
self error:'invalid portNr' |
126 | 4789 |
]. |
4790 |
%{ |
|
418 | 4791 |
#ifndef NO_SOCKET |
126 | 4792 |
struct sockaddr_in sa ; |
4793 |
struct hostent *hp ; |
|
4794 |
int a, sock ; |
|
4795 |
long addr; |
|
4796 |
FILE *fp; |
|
4797 |
int ret; |
|
4798 |
int on = 1; |
|
4799 |
||
4800 |
bzero((char *) &sa, sizeof(sa)) ; |
|
4801 |
sa.sin_family = AF_INET; |
|
4802 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
4803 |
||
4804 |
if ((hostName != nil) && __isString(hostName)){ |
|
789 | 4805 |
bzero(&sa, sizeof(sa)) ; |
4806 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
|
4807 |
/* |
|
4808 |
* is Internet addr in octet notation |
|
4809 |
*/ |
|
4810 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
4811 |
} else { |
|
4812 |
/* |
|
4813 |
* do we know the host's address? |
|
4814 |
*/ |
|
4815 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
|
4816 |
if (hp == NULL) { |
|
4817 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
|
4818 |
RETURN ( nil ); |
|
4819 |
} |
|
4820 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
4821 |
sa.sin_family = hp->h_addrtype; |
|
4822 |
} |
|
126 | 4823 |
} |
4824 |
||
4825 |
/* |
|
4826 |
* create the socket |
|
4827 |
*/ |
|
4828 |
__BEGIN_INTERRUPTABLE__ |
|
4829 |
do { |
|
789 | 4830 |
sock = socket(sa.sin_family, SOCK_STREAM, 0); |
126 | 4831 |
} while ((sock < 0) && (errno == EINTR)); |
4832 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4833 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4834 |
|
4835 |
if (sock < 0) { |
|
789 | 4836 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno)); |
4837 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4838 |
} else { |
789 | 4839 |
/* |
4840 |
* connect/bind |
|
4841 |
*/ |
|
1009 | 4842 |
sa.sin_port = htons((u_short) __intVal(portNr)) ; |
789 | 4843 |
|
4844 |
__BEGIN_INTERRUPTABLE__ |
|
4845 |
if (hostName != nil) { |
|
4846 |
do { |
|
4847 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4848 |
} while ((ret < 0) && (errno == EINTR)); |
|
4849 |
} else { |
|
126 | 4850 |
#ifdef SO_REUSEADDR |
789 | 4851 |
/* |
4852 |
* should I also do this for DGRAM sockets ? |
|
4853 |
*/ |
|
4854 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
4855 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
4856 |
} |
|
126 | 4857 |
#endif /* SO_REUSEADDR */ |
789 | 4858 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
4859 |
do { |
|
4860 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4861 |
} while ((ret < 0) && (errno == EINTR)); |
|
4862 |
} |
|
4863 |
__END_INTERRUPTABLE__ |
|
4864 |
||
4865 |
if (ret < 0) { |
|
4866 |
DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno)); |
|
4867 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4868 |
__BEGIN_INTERRUPTABLE__ |
|
4869 |
close(sock) ; |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4870 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4871 |
__END_INTERRUPTABLE__ |
4872 |
} else { |
|
4873 |
/* |
|
4874 |
* make it a FILE * |
|
4875 |
*/ |
|
4876 |
fp = fdopen(sock, "r+"); |
|
4877 |
if (! fp) { |
|
4878 |
DBGPRINTF(("SOCKET: fdopen failed\n")); |
|
4879 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4880 |
__BEGIN_INTERRUPTABLE__ |
|
4881 |
close(sock); |
|
822 | 4882 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4883 |
__END_INTERRUPTABLE__ |
4884 |
} else { |
|
1035 | 4885 |
if (@global(FileOpenTrace) == true) { |
1009 | 4886 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
4887 |
} |
|
876 | 4888 |
|
444 | 4889 |
#ifdef BUGGY_STDIO_LIB |
789 | 4890 |
setbuf(fp, NULL); |
4891 |
__INST(buffered) = false; |
|
126 | 4892 |
#endif |
789 | 4893 |
__INST(filePointer) = __MKOBJ(fp); |
4894 |
__STORESELF(filePointer); |
|
4895 |
} |
|
4896 |
} |
|
126 | 4897 |
} |
418 | 4898 |
#endif |
126 | 4899 |
%}. |
4900 |
filePointer isNil ifTrue:[ |
|
789 | 4901 |
^ nil |
126 | 4902 |
]. |
4903 |
mode := #readwrite. |
|
169 | 4904 |
Lobby register:self. |
126 | 4905 |
binary := false. |
4906 |
||
4907 |
domain := #inet. |
|
4908 |
socketType := #stream. |
|
4909 |
protocol := portNr. |
|
4910 |
peerName := hostName. |
|
81 | 4911 |
|
126 | 4912 |
" |
4913 |
Socket new for:'clam' port:(Socket portOfService:'echo') |
|
4914 |
||
4915 |
Socket new for:nil port:9999 |
|
4916 |
Socket new for:(OperatingSystem getHostName) port:9999 |
|
4917 |
" |
|
4918 |
! |
|
4919 |
||
4920 |
for:hostName udpPort:portNr |
|
4921 |
"setup for a UDP socket (i.e. inet domain, datagram type) |
|
4922 |
if hostname is nil, a server port is opened; |
|
4923 |
otherwise a client port to the server on host. |
|
4924 |
||
4925 |
HISTORIC LEFTOVER: |
|
4926 |
This method will vanish, as soon as the low level |
|
4927 |
connect/bind works," |
|
4928 |
||
4929 |
self obsoleteMethodWarning. |
|
4930 |
||
4931 |
filePointer notNil ifTrue:[ |
|
789 | 4932 |
^ self errorAlreadyOpen |
126 | 4933 |
]. |
4934 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
789 | 4935 |
self error:'invalid portNr' |
126 | 4936 |
]. |
4937 |
%{ |
|
418 | 4938 |
#ifndef NO_SOCKET |
126 | 4939 |
struct sockaddr_in sa ; |
4940 |
struct hostent *hp ; |
|
4941 |
int a, sock ; |
|
4942 |
long addr; |
|
4943 |
FILE *fp; |
|
4944 |
int ret; |
|
4945 |
||
4946 |
if (hostName != nil) { |
|
789 | 4947 |
bzero(&sa, sizeof(sa)) ; |
4948 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
|
4949 |
/* |
|
4950 |
* is Internet addr in octet notation |
|
4951 |
*/ |
|
4952 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
4953 |
sa.sin_family = AF_INET ; |
|
4954 |
} else { |
|
4955 |
/* |
|
4956 |
* is hostname - |
|
4957 |
* do we know the host's address? |
|
4958 |
*/ |
|
4959 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
|
4960 |
if (hp == NULL) { |
|
4961 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
|
4962 |
RETURN ( nil ); |
|
4963 |
} |
|
4964 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
4965 |
sa.sin_family = hp->h_addrtype ; |
|
4966 |
} |
|
526 | 4967 |
} else { |
789 | 4968 |
sa.sin_family = AF_INET; |
526 | 4969 |
} |
126 | 4970 |
|
4971 |
/* |
|
4972 |
* create the socket |
|
4973 |
*/ |
|
4974 |
__BEGIN_INTERRUPTABLE__ |
|
4975 |
do { |
|
789 | 4976 |
sock = socket(sa.sin_family, SOCK_DGRAM, 0); |
126 | 4977 |
} while ((sock < 0) && (errno == EINTR)); |
4978 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4979 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4980 |
|
4981 |
if (sock < 0) { |
|
789 | 4982 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno)); |
4983 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4984 |
} else { |
789 | 4985 |
/* |
4986 |
* ok, |
|
4987 |
* connect/bind |
|
4988 |
*/ |
|
4989 |
__BEGIN_INTERRUPTABLE__ |
|
4990 |
if (hostName == nil) { |
|
4991 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
4992 |
do { |
|
4993 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4994 |
} while ((ret < 0) && (errno == EINTR)); |
|
4995 |
} else { |
|
1009 | 4996 |
sa.sin_port = htons((u_short) __intVal(portNr)) ; |
789 | 4997 |
do { |
4998 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4999 |
} while ((ret < 0) && (errno == EINTR)); |
|
5000 |
} |
|
5001 |
__END_INTERRUPTABLE__ |
|
5002 |
||
5003 |
if (ret < 0) { |
|
5004 |
DBGPRINTF(("SOCKET: bind/connect call failed\n")); |
|
5005 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
5006 |
__BEGIN_INTERRUPTABLE__ |
|
5007 |
close(sock) ; |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
5008 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 5009 |
__END_INTERRUPTABLE__ |
5010 |
} else { |
|
5011 |
/* |
|
5012 |
* make it a FILE * |
|
5013 |
*/ |
|
5014 |
fp = fdopen(sock, "r+"); |
|
5015 |
if (! fp) { |
|
5016 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
5017 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
5018 |
__BEGIN_INTERRUPTABLE__ |
|
5019 |
close(sock); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
5020 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 5021 |
__END_INTERRUPTABLE__ |
5022 |
} else { |
|
1009 | 5023 |
if (@global(ExternalStream:FileOpenTrace) == true) { |
5024 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
|
5025 |
} |
|
876 | 5026 |
|
444 | 5027 |
#ifdef BUGGY_STDIO_LIB |
789 | 5028 |
setbuf(fp, NULL); |
5029 |
__INST(buffered) = false; |
|
126 | 5030 |
#endif |
789 | 5031 |
__INST(filePointer) = __MKOBJ(fp); |
5032 |
__STORESELF(filePointer); |
|
5033 |
} |
|
5034 |
} |
|
126 | 5035 |
} |
418 | 5036 |
#endif |
126 | 5037 |
%}. |
5038 |
filePointer isNil ifTrue:[ |
|
789 | 5039 |
^ nil |
126 | 5040 |
]. |
5041 |
||
5042 |
mode := #readwrite. |
|
169 | 5043 |
Lobby register:self. |
126 | 5044 |
binary := false. |
5045 |
||
5046 |
domain := #inet. |
|
5047 |
socketType := #datagram. |
|
5048 |
protocol := portNr. |
|
5049 |
peerName := hostName. |
|
5050 |
||
5051 |
" |
|
5052 |
Socket new for:'clam' udpPort:(Socket portOfService:'echo') |
|
5053 |
" |
|
28 | 5054 |
! ! |
5055 |
||
5056 |
!Socket methodsFor:'specials'! |
|
5057 |
||
5058 |
receiveTimeout:seconds |
|
71 | 5059 |
"set the receive timeout - for special applications only. |
5060 |
Not all operatingSystems offer this functionality |
|
5061 |
(returns false, if unsupported)" |
|
28 | 5062 |
|
5063 |
|millis| |
|
5064 |
||
5065 |
filePointer isNil ifTrue:[ |
|
789 | 5066 |
^ self errorNotOpen |
28 | 5067 |
]. |
5068 |
millis := (seconds * 1000) rounded. |
|
5069 |
%{ |
|
5070 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
58 | 5071 |
if (__isSmallInteger(millis)) { |
789 | 5072 |
OBJ fp = __INST(filePointer); |
5073 |
int sock; |
|
5074 |
int opt; |
|
5075 |
||
5076 |
sock = fileno(__FILEVal(fp)); |
|
1009 | 5077 |
opt = __intVal(millis) / (1000 / HZ); |
789 | 5078 |
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int)); |
5079 |
RETURN(true); |
|
28 | 5080 |
} |
5081 |
#endif |
|
71 | 5082 |
%}. |
28 | 5083 |
^ false |
81 | 5084 |
! |
5085 |
||
126 | 5086 |
sendTimeout:seconds |
5087 |
"set the send timeout - for special applications only. |
|
5088 |
Not all operatingSystems offer this functionality |
|
5089 |
(returns false, if unsupported)" |
|
81 | 5090 |
|
126 | 5091 |
|millis| |
25 | 5092 |
|
126 | 5093 |
filePointer isNil ifTrue:[ |
789 | 5094 |
^ self errorNotOpen |
126 | 5095 |
]. |
5096 |
millis := (seconds * 1000) rounded. |
|
5097 |
%{ |
|
5098 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
5099 |
if (__isSmallInteger(millis)) { |
|
789 | 5100 |
OBJ fp = __INST(filePointer); |
5101 |
int sock; |
|
5102 |
int opt; |
|
5103 |
||
5104 |
sock = fileno(__FILEVal(fp)); |
|
1009 | 5105 |
opt = __intVal(millis) / (1000 / HZ); |
789 | 5106 |
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int)); |
5107 |
RETURN(true); |
|
126 | 5108 |
} |
5109 |
#endif |
|
5110 |
%}. |
|
5111 |
^ false |
|
5112 |
! ! |
|
82 | 5113 |
|
464 | 5114 |
!Socket class methodsFor:'documentation'! |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
5115 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
5116 |
version |
1035 | 5117 |
^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.162 2002-04-09 14:58:01 stefan Exp $' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
5118 |
! ! |